I've made a simple custom PCB as a learning exercise. It has a single I2C sensor and a string of NeoPixels. I'd like to make it into an HID device, using data from the sensor. I have a working prototype (I2C sensor, NeoPixel string and functioning HID sketch) using an Arduino MKR Zero that functions as expected. I'm trying to replicate that functionality in a simple PCB.
Despite my custom PCB working an Arduino Zero derived bootloader, and basic Blink/NeoPixel example code (which required a custom board variant in Arduino IDE and a bit of remapping variant.cpp and variant.h), when I put some basic HID code onto it (that doesn't rely on the sensor, hardcoded inputs), it behaves differently to when running sketches without an HID library.
If I'm just running a Blink sketch, or a sketch with basic NeoPixel code, the device behaves as expected, and appears in Windows as an Arduino Zero (what I based my variant on), as in image below.

SerialUSB.println works as expected, so there is traffic between the PCB and PC.
If I upload any kind of HID code, including the example that I've got working on the MKR Zero, but also from three or four different HID example libraries, the sketch uploads and the device reboots, but Windows then picks up multiple USB devices, and the HID code doesn't work (e.g. it doesn't send characters if emulating a keyboard, or move the mouse if emulating a mouse, joystick, etc.). See image below.
No SerialUSB.println commands work when it's like this, and I need to reflash working code (like Blink) to get out of that state.
My suspicion is that I've setup my pinouts incorrectly, or that HID needs some kind of specific USB configuration that I don't understand yet. I'm finding that a real challenge to wrap my head around, and whilst there are multiple guides (including on this forum), most of them get to the actual part of doing the pinout mapping, and end up saying, "just do it". If it's USB configuration, I just don't have the terminology to Google yet, although I want to learn.
Could someone please help me? I've managed to wrangle my way through KiCAD, getting a PCB made, compiling a bootloader with a custom -DCRYSTALLESS flag, successfully flashing it, setting up board variant in Arduino IDE (probably unsuccessfully), but this and a 2 year old kid are frying my brain
.
My schematic is below, excluding the LED string coming off of PA16. Unfortunately I didn't follow the pinout mapping of the Arduino Zero (lesson learnt for next time).
PA08 and PA08 are my I2C SCL/SDA lines, and I've sent them up as the following in variant.cpp. I haven't actually been able to read from my I2C device yet on the custom PCB (verified it's getting power with a multimeter though).
{ PORTA, 9, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1] // Modified to be SCL
{ PORTA, 8, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // SDA: SERCOM3/PAD[0] // Modified to be SDA
The above pins are at index 4 and 3 respectively in the PinDescription g_APinDescription[] array, and so my variant.h points to 4 and 3 as needed - see below.
|#define PIN_WIRE_SDA (4u)|// Modified to point to PA08|
|---|---|
|#define PIN_WIRE_SCL (3u)|// Modified to point to PA09|
My LED dataline is as follows
{ PORTA, 16, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH6, TCC0_CH6, EXTERNAL_INT_4 }, // TCC0/WO[6] // Modified to match Pin 6 on an Arduino, and I know this works
My USB datalines are as follows, at index 28 and 29 in PinDescription g_APinDescription[]:
{ PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM
{ PORTA, 25, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DP
variant.h below
#define PIN_USB_DM (28ul)
#define PIN_USB_DP (29ul)
Do I need to do some configuring of the USB side of things to let the SAMD21 be an HID device? Assuming I've got the pinouts right (maybe haven't, since I2C isn't working), that's my next best guess, but a point in the direction would be really helpful.
