Harmony v3 configuration for USB HID Device
I am trying to create a Harmony v3 project to get the PIC32MZ2048EFM144 on the Curiosity 2.0 evaluation kit to enumerate as an HID USB device when I connect the "Target USB" connector to my computer.
Here's what I have tried so far...
I started with a copy of the demo app located here:
The demo app is for the PIC32MZ2048EFH
144, so I changed the configuration to target the device on the Curiosity 2.0 board, specifically the PIC32MZ2048EFM
Next, I opened MHC and made the following changes:
- Remove the PIC32MZ EF Starter Kit BSP, since this is not the kit I am using.
- Edit Pin Settings to remove the predefined LED (RH0) and SWITCH (RB12) because they do not line up with an LED or a switch on the Curiosity 2.0 board.
- Edit Pin Settings to define LED as RJ7. Configured as GPIO, Out, High, Open drain.
- Edit Pin Settings to define SWITCH as RJ4. Configured as GPIO, In, Change notification, Pullup.
I made no further changes in MHC at this point, leaving the USB HS driver, USB device layer, HUD function driver, Core timer, and Time modules as provided in the sample, saved the configuration, then generated the code.
So far so good. A clean-and-build produced errors because functions LED_Off() and LED_On() were not defined, and neither was the constant SWITCH_STATE_PRESSED. Not a problem. I just defined these as LED_Set(), LED_Clear(), and 0x00, respectively.
Now a clean-and-build produces no errors or warnings, so I loaded this code into the PIC32 on board using the "Make and Program" button.
I unplugged the USB cable from the "DEBUG USB" port on the Curiosity 2.0 board and plugged it into the "TARGET USB" port. Here's where I run into problems. On Windows 10, the device does not enumerate and in fact, the Device Manager doesn't show any changes when the board is plugged in or unplugged. However, while the board is plugged in, Windows repeatedly makes the sound it makes when a USB device is plugged in and a "USB Device not recognized" message occasionally pops up.
For diagnostic purposes, I also plugged the board into a Linux machine and it would not enumerate there either. I looked at the syslog and found these entries, which coincide with the Curiosity 2.0 board being plugged in:Apr 8 08:24:41 ted-Inspiron-620 kernel: [60730.268493] usb 2-1.3.1: new high-speed USB device number 42 using ehci-pci Apr 8 08:24:42 ted-Inspiron-620 kernel: [60730.440486] usb 2-1.3.1: new high-speed USB device number 43 using ehci-pci Apr 8 08:24:42 ted-Inspiron-620 kernel: [60730.532777] usb 2-1.3-port1: attempt power cycle Apr 8 08:24:42 ted-Inspiron-620 kernel: [60731.136530] usb 2-1.3.1: new full-speed USB device number 44 using ehci-pci Apr 8 08:24:43 ted-Inspiron-620 kernel: [60731.552516] usb 2-1.3.1: device not accepting address 44, error -32 Apr 8 08:24:43 ted-Inspiron-620 kernel: [60731.632502] usb 2-1.3.1: new high-speed USB device number 45 using ehci-pci Apr 8 08:24:43 ted-Inspiron-620 kernel: [60732.052513] usb 2-1.3.1: device not accepting address 45, error -71 Apr 8 08:24:43 ted-Inspiron-620 kernel: [60732.052914] usb 2-1.3-port1: unable to enumerate USB device
The LED on the Curiosity 2.0 board does not illuminate and the switch has no discernible effect.
It occurred to me that this might be a problem with power. I check the schematic and it shows the 5V from the TARGET USB connector feeding into the 3.3V regulator that powers the PIC32. That should be fine, but it's easy enough to provide another power source. The 5V from the DEBUG USB becomes PKOB_P5V0, which also feeds into the 3.3V regulator that powers the PIC32. I plugged in a separate USB cable to the DEBUG USB connector and connected it to a 2A, 5V charging block, which should provide all the power necessary for the PIC32. I then reconnected the TARGET USB to my computers and came up with the same result.
Bored yet? There's more...
I saw in the code that there are debug statements scattered throughout, so I configured the project to write the debug statements to UART6, which should write to the virtual com port created when DEBUG USB is connected to the computer. Here, exactly, are the steps I took to do that:
- Using MHC, add Harmony->System Services->Debug.
- On the Debug module, right-click the SYS_CONSOLE dependency and select Satisfiers->CONSOLE.
- On the Console module, right-click the UART dependency and select Satisfiers->UART6.
- Configure UART6 for 115200, 8N1.
- Edit Pin Table to select pin 79 for U6TX.
- Save configuration and generate code.
Now a clean-and-build generates a number of errors around implicit declarations and undeclared symbols from the debug library. These were all resolved by adding #include "system/debug/sys_debug.h"
to usb_device.c. Now a clean-and-build does not generate any errors or warnings.
I programmed the code into the PIC32 as usual.
I launched TeraTerm and configured it for the virtual com port (COM13 in my case), also set for 115200, 8N1 like the UART6 module in MHC.
Here I observed debug output, but it appeared to be the gobbledygook you typically get when the baud rate doesn't match between serial ports. I faffed about for a while troubleshooting this. I switched UART and serial port settings, and switched them back. I verified UART6 does indeed write to TeraTerm correctly on a clean project. I switched between blocking and non-blocking UART6 writes. I configured the unused UART6 receive pin, just in case. Etc., etc., ad nauseum. In the end, I could not get the debug output to write in clear text in this project.
Here I realized I am probably missing something more basic and I am getting further and further away from my goal of getting the HID USB demo project to work.
Has anyone had any luck getting the TARGET USB on the Curiosity 2.0 to enumerate as a HID device?
Or, can anyone offer troubleshooting suggestions or other advice for me to try?