• AVR Freaks

Hot!HOW TO: PIC32MZ USB without Harmony

Page: < 1234 > Showing page 3 of 4
Author
nigelwright7557
Super Member
  • Total Posts : 308
  • Reward points : 0
  • Joined: 2006/11/06 08:15:51
  • Location: 0
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/02/08 20:24:35 (permalink)
0
I was going to upload my harmony USB for pic32mz but its so full of swear words for bits I had problems with !
I got my code mostly from the harmony libraries for HID_DEMO_BASIC
I used the app.h and app.c as the basis for my program.
My program reads data from a2d to the pc.
PIC32MZ a2d is a beast to get to grips with after using smaller pics !
There are dozens of 32 bit registers to get to grips with.
On previous projects there have been about 3 registers to set up to deal with !
 
I had a big problem with my usb interface.
It kept sending back the transmit buffer data from the previous exchange !
I had to add some code which accessed my a2d buffer before it would behave.
#41
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/02/08 23:23:11 (permalink)
0
AGL59
Thank you !
I will try it for HID device on PIC32MM, even if I have already boards working well for some applications.
I'm a hardware guy, so this is software as I like. Harmony drives me crazzy. I wrote many applications with TCP/IP, web server, digital filtering... without Harmony, which is painfull for me.
Now, the dream would be same code but for host HID on PIC32MZ2048EFM144, as I'm unable to do same thing with Harmony. It was working with a PIC32MX570 and old stack... I will think about it, now I've seen it was possible to use USB without thousands of lines.




You're welcome!
I'm just happy people are finding it useful.
I get frustrated with Harmony too and figured there had to be a way... I worked on it, off and on, for about a year. I had to do a lot of digging and reading, but finally it worked!

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#42
Timmons
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2018/02/07 01:09:23
  • Location: 0
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/02/09 09:02:29 (permalink)
0
Dear MisterHemi
 
i Tested the input endpoint and works Ok!
 
But I cannot transmit packet from EP2. did you testes the transmission?
I try to put the transmission function on "if" below and I try to enable bit 
 
USBCSR0bits.EP2TXIF
 
in the main, but it happen that i have a "reset" when i try to transmit
and windows notifie me "Unknow Device"
 
can you post a transmission example code?
 
Thanks
 
 /* Endpoint 2 TX Interrupt Handler */
   if(USBCSR0bits.EP2TXIF){ // Endpoint 2 Transmit A Packet.
        // To send packets via EP2 call function txUSB_ep2()
        // see how packets are sent in function controlTrans() as an example
        // otherwise this interrupt handler may have limited use depending
        // upon your implementation.
 
    USBCSR0bits.EP2TXIF = 0; // Supposedly Cleared By Hardware (Clear Just In Case).

 
post edited by Timmons - 2019/02/09 09:04:45
#43
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/02/09 14:28:41 (permalink)
0
Timmons
Dear MisterHemi
 
i Tested the input endpoint and works Ok!
 
But I cannot transmit packet from EP2. did you testes the transmission?
I try to put the transmission function on "if" below and I try to enable bit 
 
USBCSR0bits.EP2TXIF
 
in the main, but it happen that i have a "reset" when i try to transmit
and windows notifie me "Unknow Device"
 
can you post a transmission example code?
 
Thanks
 
 /* Endpoint 2 TX Interrupt Handler */
   if(USBCSR0bits.EP2TXIF){ // Endpoint 2 Transmit A Packet.
        // To send packets via EP2 call function txUSB_ep2()
        // see how packets are sent in function controlTrans() as an example
        // otherwise this interrupt handler may have limited use depending
        // upon your implementation.
 
    USBCSR0bits.EP2TXIF = 0; // Supposedly Cleared By Hardware (Clear Just In Case).

 




I haven't tested the TX endpoint (ep2 if I remember off the top of my head) but it should function similar to the way ep0 functions when sending data, except it has it's own interrupt and handler.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#44
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/02/09 15:00:21 (permalink)
0
Timmons
Dear MisterHemi
 
i Tested the input endpoint and works Ok!
 
But I cannot transmit packet from EP2. did you testes the transmission?
I try to put the transmission function on "if" below and I try to enable bit 
 
USBCSR0bits.EP2TXIF
 
in the main, but it happen that i have a "reset" when i try to transmit
and windows notifie me "Unknow Device"
 
can you post a transmission example code?
 
Thanks
 
 /* Endpoint 2 TX Interrupt Handler */
   if(USBCSR0bits.EP2TXIF){ // Endpoint 2 Transmit A Packet.
        // To send packets via EP2 call function txUSB_ep2()
        // see how packets are sent in function controlTrans() as an example
        // otherwise this interrupt handler may have limited use depending
        // upon your implementation.
 
    USBCSR0bits.EP2TXIF = 0; // Supposedly Cleared By Hardware (Clear Just In Case).

 




In this function:

void txUSB_ep2(uint32_t ep2TXLen){
volatile uint8_t *ep2fifo = NULL;
ep2fifo = (uint8_t *)&USBFIFO2;

for(ep2ArrPos = 0; ep2ArrPos < ep2TXLen; ep2ArrPos++){
*ep2fifo = ep2usbData[ep2ArrPos];
}

USBE2CSR0bits.TXPKTRDY = 1;
}

you should be able to send data, similar to the way ep0 does, using this function:

ep2usbData = your_data;
txUSB_ep2(sizeof(your_data));

the array your_data is where you'd store the data you want to be transmitted, also be sure the length of your_data isn't more than the ep2 TX buffer size. 
Also maybe clear the array after the data has been transmitted, maybe using something such as
memset
.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#45
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/03/20 16:52:37 (permalink)
5 (1)
I just added an update and a USB MIDI example. See the updates in the first post.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#46
signed *someone
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2010/06/19 02:20:14
  • Location: 0
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/20 10:49:47 (permalink)
0
Timmons
I wanted to write to you after finally resolving the problem..............
 
Francesco

 
Would you be able to share your code that achieves that solution, Francesco? I am facing exactly the same problem and don't know how to solve it. My device enumerates in Windows 10 with an exclamation mark. I have not changed anything in MisterHemi's demo code, except the VID/PID pair. Gave it the Microchip's standard 0x04d8 / 0x000a and that made it enumerate itself as a COM port.
The message that Windows gives is:
 
This device cannot start. (Code 10)
An invalid parameter was passed to a service or function.
 
---
 
And special thanks to MisterHemi for this amazing piece of code!!
 
Note to Microchip: it's time to abandon this monstrosity called Harmony!
 
#47
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/20 19:47:10 (permalink)
0
kiiid
 
And special thanks to MisterHemi for this amazing piece of code!!
 
Note to Microchip: it's time to abandon this monstrosity called Harmony!
 




You're VERY welcome!
I was hoping it would be useful.
 
I also posted another thread regarding the TX interrupts here:
https://www.microchip.com/forums/m1097829.aspx#1097829
 
The code I posted in that thread works when the endpoint 3 interrupt directly/immediately calls the function to transmit the data back to the host. However above that ISR if you uncomment the TX ISRs (and comment out the code which calls txByte_ep2 and ep2_BlockData in the endpoint 3 ISR) the endpoint 1 and 2 TX interrupts don't work.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#48
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/20 19:51:25 (permalink)
0
Regarding my previous post I forgot to mention that code in the other post I mentioned is for a CDC ACM example. It works but not exactly as I believe it's supposed to work.
 
I still don't know why but would like to find the answer.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#49
signed *someone
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2010/06/19 02:20:14
  • Location: 0
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 02:29:40 (permalink)
0
Thank you MisterHemi !!
I had a look at your other post (strangely, there have not been any responses there??) and downloaded the demo zip for ACM, but it is exactly the same as your initial demo posted here. Is this how it is supposed to be?
I think there should be a bit more code in the interrupt handler to deal with the host but I have absolutely no knowledge of USB and not sure what needs to be done in order to end up with a functional minimum that emulates a COM port
#50
DominusT
Super Member
  • Total Posts : 1332
  • Reward points : 0
  • Joined: 2005/07/22 08:31:18
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 06:12:58 (permalink)
0
kiiid
Thank you MisterHemi !!
I had a look at your other post (strangely, there have not been any responses there??) and downloaded the demo zip for ACM, but it is exactly the same as your initial demo posted here. Is this how it is supposed to be?
I think there should be a bit more code in the interrupt handler to deal with the host but I have absolutely no knowledge of USB and not sure what needs to be done in order to end up with a functional minimum that emulates a COM port


Is it really that bad to use Harmony? I also needed to emulate a COM port via USB, I thought about writing my own code but decided to give Harmony a chance and it seems to work without problems, apart from accelerating the development of my project.
#51
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 07:29:39 (permalink)
0
kiiid
Thank you MisterHemi !!
I had a look at your other post (strangely, there have not been any responses there??) and downloaded the demo zip for ACM, but it is exactly the same as your initial demo posted here. Is this how it is supposed to be?
I think there should be a bit more code in the interrupt handler to deal with the host but I have absolutely no knowledge of USB and not sure what needs to be done in order to end up with a functional minimum that emulates a COM port




From my understanding there should be an INTERRUPT endpoint (in the example it's endpoint 1) which would report the status of the Com port (CTS, DSR, etc). However it seems the TX interrupt is never triggered, which is very odd to me. I believe the host should send a request which would cause that interrupt to be triggered, since the host is what controls all of the transactions. These no real interrupt (in conventional terms) as we know it, it's just a notification for the host so it knows there's data present or a request to be serviced.
 
I was also surprised no one else replied on the other thread.
 
Regarding using Harmony.... it just seems bloated and unnecessarily complicated. It has a steep leaning curve in my opinion. I wanted something more efficient and easier to understand, I believe Harmony's code it many times the size of the code I posted. It's nice to have more room for other things.
 
I have several projects some being simple MIDI music devices to a very complex synthesizer... for the simpler devices (such as a MIDI sequencer) I thought the PIC32 would be adequate and wanted to have USB MIDI,  DIN MIDI, and a display. I figured if the processor is fast enough and the code small enough/efficient I could possibly integrate quite a few features. It seemed to be too much, in my opinion, to try to implement what I want and learn Harmony and worry about the size of the code... I wanted, if possible, to keep it as compact as possible.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#52
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 07:41:18 (permalink)
0
DominusT
kiiid
Thank you MisterHemi !!
I had a look at your other post (strangely, there have not been any responses there??) and downloaded the demo zip for ACM, but it is exactly the same as your initial demo posted here. Is this how it is supposed to be?
I think there should be a bit more code in the interrupt handler to deal with the host but I have absolutely no knowledge of USB and not sure what needs to be done in order to end up with a functional minimum that emulates a COM port


Is it really that bad to use Harmony? I also needed to emulate a COM port via USB, I thought about writing my own code but decided to give Harmony a chance and it seems to work without problems, apart from accelerating the development of my project.




See my above post.... but I also wanted to add this....
 
Harmony may be useable but it has a steep learning curve. To do the things I wanted required that I learn about USB, descriptors, etc and that just led me in the direction of developing my own USB stack. It seemed to be just as steep of a learning curve as trying to learn Harmony and I have a much better understanding now of how USB descriptors work and how to configure them for many types of USB devices - CDC ACM, MIDI, Audio, etc.
 
One of my concerns though was the size of the Harmony code too and all of the layers and wrappers, etc. There weren't any clear tutorials and when trying to dig through the Harmony code I was constantly flipping back and forth from one page to another trying to understand how it worked... many I was asking too many questions and should've just taken it as it is... but I wanted to have a deeper understanding of what I was doing, I tend to do that and maybe not always to my advantage LoL: LoL
 
For example I want to do bare metal programming on the Atmel SAMAD5A36 and NXP LS1012A but feel a bit frustrated by the lack of tools (for the Macintosh anyway), the hurdles (such as figuring out how to configure GCC and/or Eclipse) or the cost of some development IDEs.
 
If Microchip ever includes the SAMA5Dxx series in MPLAB X i'd be a very happy person Smile: Smile  

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#53
friesen
Super Member
  • Total Posts : 2082
  • Reward points : 0
  • Joined: 2008/05/08 05:23:35
  • Location: Indiana, USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 07:50:45 (permalink)
0
@MisterHemi, why would you want the SAMA5Dxx series in MPLAB X?
 
I think PIC32 silicon is great, but after two projects using the MZ DA, I am to the point where I can't hardly deal with the dev tools for it.  Once your project uses about half the flash, debugger and ide delays are somewhere well over a minute from debug click to actual debugging on a modern PC with 32gb ram, etc etc etc..  So, I have indeed been testing the waters of the SAMA5D22C and jlink.  I can actually see external memory!  Program times are short!  Oh, if only the DA + MPLABX could do this eh?  At this point, I am using eclipse, although it did take some work to get the deubgger stuff working correctly.

Erik Friesen
#54
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 08:01:01 (permalink)
0
friesen
@MisterHemi, why would you want the SAMA5Dxx series in MPLAB X?
 
I think PIC32 silicon is great, but after two projects using the MZ DA, I am to the point where I can't hardly deal with the dev tools for it.  Once your project uses about half the flash, debugger and ide delays are somewhere well over a minute from debug click to actual debugging on a modern PC with 32gb ram, etc etc etc..  So, I have indeed been testing the waters of the SAMA5D22C and jlink.  I can actually see external memory!  Program times are short!  Oh, if only the DA + MPLABX could do this eh?  At this point, I am using eclipse, although it did take some work to get the deubgger stuff working correctly.




I figured it would be good since i'm already familiar with MPLAB X, however if there's something else that's better i'd be willing to try that too. I'll have to look into jlink as i'm not familiar with it. Thanks!
 
Also I did install Atmel Studio (running Windows 10 via VMWare) on my MacBook Pro but it doesn't seem support the SAMA5D36.
post edited by MisterHemi - 2019/05/22 08:03:16

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#55
DominusT
Super Member
  • Total Posts : 1332
  • Reward points : 0
  • Joined: 2005/07/22 08:31:18
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 08:08:42 (permalink)
5 (1)
MisterHemi
DominusT
kiiid
Thank you MisterHemi !!
I had a look at your other post (strangely, there have not been any responses there??) and downloaded the demo zip for ACM, but it is exactly the same as your initial demo posted here. Is this how it is supposed to be?
I think there should be a bit more code in the interrupt handler to deal with the host but I have absolutely no knowledge of USB and not sure what needs to be done in order to end up with a functional minimum that emulates a COM port


Is it really that bad to use Harmony? I also needed to emulate a COM port via USB, I thought about writing my own code but decided to give Harmony a chance and it seems to work without problems, apart from accelerating the development of my project.




See my above post.... but I also wanted to add this....
 
Harmony may be useable but it has a steep learning curve. To do the things I wanted required that I learn about USB, descriptors, etc and that just led me in the direction of developing my own USB stack. It seemed to be just as steep of a learning curve as trying to learn Harmony and I have a much better understanding now of how USB descriptors work and how to configure them for many types of USB devices - CDC ACM, MIDI, Audio, etc.
 
One of my concerns though was the size of the Harmony code too and all of the layers and wrappers, etc. There weren't any clear tutorials and when trying to dig through the Harmony code I was constantly flipping back and forth from one page to another trying to understand how it worked... many I was asking too many questions and should've just taken it as it is... but I wanted to have a deeper understanding of what I was doing, I tend to do that and maybe not always to my advantage LoL: LoL
 
For example I want to do bare metal programming on the Atmel SAMAD5A36 and NXP LS1012A but feel a bit frustrated by the lack of tools (for the Macintosh anyway), the hurdles (such as figuring out how to configure GCC and/or Eclipse) or the cost of some development IDEs.
 
If Microchip ever includes the SAMA5Dxx series in MPLAB X i'd be a very happy person Smile: Smile  


I understand your frustration, I have worked with MCHP devices for many years, and for a long time I was reluctant to use Harmony, but little by little I have managed to understand what it is all about, even though there is still a lot of 'hermeticism'.
In the forums I read that it should be used more for complex peripherals (Ethernet, USB, WiFi, etc.) but for others it is preferable to write your own code, it is something that I do and to generate delays I avoid using the system timer.
I think that for newcomers, especially those who don't write code as tasks with states, it is a little more complicated to understand and use.
And soon Harmony 3 will arrive that seems to be completely new. I plan to stay with version 2.xx for the moment you have understood and understand this new version that is aimed at Atmel devices.
#56
signed *someone
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2010/06/19 02:20:14
  • Location: 0
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 08:29:56 (permalink)
0
DominusT
Is it really that bad to use Harmony? I also needed to emulate a COM port via USB, I thought about writing my own code but decided to give Harmony a chance and it seems to work without problems, apart from accelerating the development of my project.



Well, I can only speak from personal point of view, but I gave it a shot. Several times. No more Harmony for me. Ever.
I would much rather see Microchip recognising that it is a massive overkill in all aspects and return back to the simple and much more efficient Plib. As to USB - it is a big fat joke by itself, but people have to live with it somehow. In 90% of the cases a developer actually needs nothing but a serial interface emulation, and to add 20-something extra K to the code by including the full USB stack is crazy
#57
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/22 08:32:54 (permalink)
0
kiiid
DominusT
Is it really that bad to use Harmony? I also needed to emulate a COM port via USB, I thought about writing my own code but decided to give Harmony a chance and it seems to work without problems, apart from accelerating the development of my project.



Well, I can only speak from personal point of view, but I gave it a shot. Several times. No more Harmony for me. Ever.
I would much rather see Microchip recognising that it is a massive overkill in all aspects and return back to the simple and much more efficient Plib. As to USB - it is a big fat joke by itself, but people have to live with it somehow. In 90% of the cases a developer actually needs nothing but a serial interface emulation, and to add 20-something extra K to the code by including the full USB stack is crazy




Exactly and MIDI is essentially a serial interface too, so it's overkill and not efficient.

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#58
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/05/23 13:14:24 (permalink)
0
kiiid
Thank you MisterHemi !!
I had a look at your other post (strangely, there have not been any responses there??) and downloaded the demo zip for ACM, but it is exactly the same as your initial demo posted here. Is this how it is supposed to be?
I think there should be a bit more code in the interrupt handler to deal with the host but I have absolutely no knowledge of USB and not sure what needs to be done in order to end up with a functional minimum that emulates a COM port




Someone finally replied to the other post. They stated that the endpoint TX interrupt happens after transmission is complete. However in my code when I enabled/uncommented the part of the ISR that handles the TX interrupts it should have turned on an LED but that never happens.
 
As for dealing with the host I don't think there's much more to be added but I do know there should be some code to indicate UART states such as CTS, DSR, etc. I believe that should have been handled by endpoint 1 in my example in the other post (https://www.microchip.com/forums/m1097829.aspx#1097829). That example does echo back a character to the host. You could modify that to have the PIC send back a character at a time to the host by calling the function that transmits a byte via endpoint 2  for example:

ep2BlockData = yourData;
txByte_ep2(0);

 
 

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#59
MisterHemi
Senior Member
  • Total Posts : 171
  • Reward points : 0
  • Joined: 2017/11/02 12:24:21
  • Location: Commerce, CA USA
  • Status: offline
Re: HOW TO: PIC32MZ USB without Harmony 2019/06/22 21:09:52 (permalink)
0
I attempted to edit the first post and add this to it but the forum won't allow it.... annoying!
It often says "you don't have permission".
I wish they would FIX it!
 
UPDATE - 22 June 2019:
I'm attaching an updated CDC ACM example. I've tried to clean it up a little and remove some unnecessary things.
You will still need to add some required functions to make it compliant with the USB specifications for a CDC ACM device.
 
In this section (beginning on line 661) titled CDC ACM Class Request some request are stalled and need to edited to comply

 
 
 
/*********************************************************************
CDC ACM Class Request
*********************************************************************/
case 0x2100: // SEND_ENCAPSULATED_COMMAND (Required for CDC ACM) - INTERFACE
USBE0CSR0bits.STALL = 1;
break;

case 0x2101: // GET_ENCAPSULATED_RESPONSE (Required for CDC ACM) - INTERFACE
USBE0CSR0bits.STALL = 1;
break;

case 0x2120: // SET_LINE_CODING - INTERFACE
rxUSB_ep0(wLength);
serialState = ep0usbTemp;
dwDTERate = ((serialState[3] << 24) | (serialState[2] << 16) | (serialState[1] << 8) | serialState[0]); // BAUD
bCharFormat = serialState[4] & 0x03; // Stop Bits - 7, 8, etc
bParityType = serialState[5] & 0x07; // Parity
bDataBits = serialState[6] & 0x1F; // Data bits
break;

case 0x2121: // GET_LINE_CODING - INTERFACE
// Requests current DTE rate, stop-bits, parity, and number-of-character bits.
USBE0CSR0bits.STALL = 1;
break;

case 0x2122: // SET_CONTROL_LINE_STATE - INTERFACE (called when host/terminal disconnects)
// RS232 signal used to tell the DCE device the DTE device is now present.
// NOTE: This is briefly (quickly) called when the device goes on/offline 
controlState = wValue;
/* Send initial message to the terminal/console */
if(controlState != 0){
// NOTE: When controlState is zero (0) the CDC device is offline (when the terminal is disconnected).
// This message is sent each time the device goes online (when the terminal connects to it).
char message[] = "PIC32MZ connected. Welcome!\n";
ep2BlockData = message;
sendMessage_ep2();
}
break;

case 0xA101: // RESPONSE_AVAILABLE (required for CDC ACM)
USBE0CSR0bits.STALL = 1;
break;

case 0xA120: // SERIAL STATE
USBE0CSR0bits.STALL = 1;
break;

case 0xA121: // GET_LINE_CODING - INTERFACE
USBE0CSR0bits.STALL = 1;
break;

default:
USBE0CSR0bits.STALL = 1;
break;
 
 
 

 
CHANGES:
1) When case 0x2122 is called, when going online/offline, it sends a welcome message upon going online.
 
2) Function rxUSB_ep0 has been corrected to receive data correctly after the request (bm/b) packet has been received and there's data following it.
 
3) When you change the baud rate, stop bits, parity, etc in your terminal program/app case 0x2120 will be called and the new baud rate, etc will be saved. This wasn't in the previous version. You can use this if you have a UART or other device which needs this. It's shown here:

 
 
 
case 0x2120: // SET_LINE_CODING - INTERFACE
rxUSB_ep0(wLength);
serialState = ep0usbTemp;
dwDTERate = ((serialState[3] << 24) | (serialState[2] << 16) | (serialState[1] << 8) | serialState[0]); // BAUD
bCharFormat = serialState[4] & 0x03; // Stop Bits - 7, 8, etc
bParityType = serialState[5] & 0x07; // Parity
bDataBits = serialState[6] & 0x1F; // Data bits
break;
 
 
 

 
Oddities:
This function works correctly but it's odd that the size has to multiplied by 8. Also it will send an extra 4 characters which is why 4 has been subtracted from the length. I have some general ideas as to why this is... perhaps because of the width of the FIFO, etc.

 
 
 
void sendMessage_ep2(){
/* Send a message to the USB terminal console */
uint32_t txSize = (sizeof(ep2BlockData) * 8) - 4;
txBlock_ep2(txSize);
}
 
 
 

 
Hopefully this will also be helpful and easier to read/understand.
(I wish they would FIX THE FORUM so it stops saying "you don't have permission to post" and you have to attempt multiple times to post something!)
 
See the first post for updated code. I posted version 2 of the USB CDC ACM example there.
post edited by MisterHemi - 2019/06/25 09:17:06

My configuration:
MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
 
Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
#60
Page: < 1234 > Showing page 3 of 4
Jump to:
© 2019 APG vNext Commercial Version 4.5