• AVR Freaks

Helpful ReplyHot!USB CDC Example MPLab Harmony

Author
speck
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2011/06/01 06:35:22
  • Location: 0
  • Status: offline
2016/01/29 09:58:34 (permalink)
0

USB CDC Example MPLab Harmony

Hi,
 
I currently have 2 development boards, one is from microchip and has the PIC32MZ2048ECH144 (PIC32MZ EC Starter Kit).  I need to bring up both Ethernet and USB Device on the PIC32.  I wanted to start with USB as i've done it in the past.  First I tried loading the USB CDC single/dual examples that are provided with harmony (using v1.06.02), but based on the LED's it immediately goes into "suspended" state and never exits.
 
I shifted gears as I always have a PIC32-HMZ144 from olimex that I ordered and wanted to bring up the USB Device on there.  I created a brand new Harmony project and configured everything using the MPLAB Harmony Configurator, muxed a clock out to make sure my PLL is correctly configured.  After these baby steps I enabled the USB driver and added in a USB State Machine that I could call and generally copied quite a bit from the CDC Single Example.  After messing around I figured out the PIC32 immediately goes to the USBDEV_ERROR state due to the USB_DEV_CDC_Read call failing, after shifting from USB_SPEED_HIGH to USB_SPEED_FULL this issue resolved itself (this is less than ideal, but baby steps)...
 
Now I am able to see COM7 appearing in my device manager, the proper "name" is displayed and I'm progressing through the states correctly: USBDEV_SCHEDULE_READ --> USBDEV_WAIT_FOR_READ_COMPLETE --> USBDEV_SCHEDULE_WRITE --> USBDEV_WAIT_FOR_WRITE_COMPLETE --> back to USBDEV_SCHEDULE_READ.  However when I look at the read buffer it's always full of NULL's, I can however manually write to it and see the correct values appear.  For the write side I tried manually setting the first four bytes to 'a', 'b', 'c', 'd', but even these don't appear correctly in my putty session.
 
I know there has to be something silly i'm doing in my code to break this entire project, but for the life of me I cannot find it.  I've used both the TCP/IP stack and the USB stack from MLA but this is my first harmony project.  It all looked easy with the configurator but now i'm not so sure...  I included the code here, probably a bit of a mess...
 
Any help would be greatly appreciated, have deadlines for both of these boards that are rapidly approaching...
 
Thank you in advance,
 
 
-sp
 
Here are a few code snippets from my project:

USB_DEVICE_CDC_RESULT readRequestResult = USB_DEVICE_CDC_Read (USB_DEVICE_CDC_INDEX_0,
&usbData.readTransferHandle, usbData.rdData,
USBDEV_BUF_SIZE);

if(usbData.readTransferHandle == USB_DEVICE_CDC_TRANSFER_HANDLE_INVALID || readRequestResult != USB_DEVICE_CDC_RESULT_OK)
{
usbData.state = USBDEV_ERROR;
break;
}

 

/* Echo the received character + 1*/
usbData.wrData[0] = 'a';
usbData.wrData[1] = 'b';
usbData.wrData[2] = 'c';
usbData.wrData[3] = 'd';
//usbData.wrData[0] = 'a';
USB_DEVICE_CDC_RESULT wrResult = USB_DEVICE_CDC_Write(USB_DEVICE_CDC_INDEX_0,
&usbData.writeTransferHandle,
usbData.wrData, 1,
USB_DEVICE_CDC_TRANSFER_FLAGS_DATA_COMPLETE);

if(usbData.writeTransferHandle == USB_DEVICE_CDC_TRANSFER_HANDLE_INVALID
|| wrResult != USB_DEVICE_CDC_RESULT_OK)
{
usbData.state = USBDEV_ERROR;
break;
}

#1
speck
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2011/06/01 06:35:22
  • Location: 0
  • Status: offline
Re: USB CDC Example MPLab Harmony 2016/01/29 13:27:02 (permalink) ☄ Helpfulby DominusT 2019/04/05 12:43:10
5 (1)
Hi,
 
I was able to figure out what the issue is.  In case anyone has this same issue I had to do the following to fix it:
1) In the USB_DATA structure switch the wrData and rdData to be uint8_t pointers
2) create two global arrays for wrData and rdData to point at.  
   a) global array pointer types were: uint8_t __attribute__((coherent)) __attribute__((aligned(4)))
3) when the init function 'USBDEVSM_init' was called, set the wrData dn rdData pointers to the global arrays
 
I still don't know why the PIC32MZ Embedded Connectivity (EC) Starter Kit doesn't work, but that's an issue for another day.  I've attached the new project in case it helps anyone in the future.
 
Thanks,
 
 
 
-SP
#2
RISC
Super Member
  • Total Posts : 5376
  • Reward points : 0
  • Status: offline
Re: USB CDC Example MPLab Harmony 2016/02/01 00:22:39 (permalink)
0
Hi,
I have used the PIC32MZ EC starter kit with CDC demos without any issue. I took the out of the box demos from the Harmony app\USB folder
Can you confirm if your board is at leat enumerated using untouched demos. You can see this with USBdeview freeware. Click on the connected column and look which USB devices are connected. you can recognize Microchip devices with the VID 04D8.
If so, use Teraterm or any other terminal sw.
I also used the USB console service but it is important to note that you must push the ENTER key to start the console (this is mentioned in the Harmony apps manual).
Regards
post edited by RISC - 2016/02/06 06:27:53
#3
JNR
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2014/07/24 21:41:00
  • Location: Bangalore
  • Status: offline
Re: USB CDC Example MPLab Harmony 2016/02/03 20:46:08 (permalink)
0
Hello,
 
Please try the following.
 
1. To the read and write buffer definitions add the following attributes and check if you are getting valid read data.
__attribute__((coherent)) __attribute__((aligned(16)))
 
2. The project is configured for working in FS mode only. You can change this to HS and FS in the Harmony
    configurator using the following options:
    In USB Library -> Use USB Stack -> USB Device Instance 0 -> Function 1 -> Speed, select    
   USB_HIGH_SPEED|USB_FULL_SPEED option.
 
I will try to debug the attached project in the mean time.
 
Regards,
JNR
#4
DominusT
Super Member
  • Total Posts : 1322
  • Reward points : 0
  • Joined: 2005/07/22 08:31:18
  • Status: offline
Re: USB CDC Example MPLab Harmony 2019/04/05 13:08:07 (permalink)
0
speck
Hi,
 I was able to figure out what the issue is.  In case anyone has this same issue I had to do the following to fix it:
1) In the USB_DATA structure switch the wrData and rdData to be uint8_t pointers
2) create two global arrays for wrData and rdData to point at.  
   a) global array pointer types were: uint8_t __attribute__((coherent)) __attribute__((aligned(4)))
3) when the init function 'USBDEVSM_init' was called, set the wrData dn rdData pointers to the global arrays
 
I still don't know why the PIC32MZ Embedded Connectivity (EC) Starter Kit doesn't work, but that's an issue for another day.  I've attached the new project in case it helps anyone in the future.
 
Thanks,
  
-SP


Thank you. I had a similar problem:

https://www.microchip.com..ums/tt.aspx?forumid=203



#5
Jump to:
© 2019 APG vNext Commercial Version 4.5