Question
USB HID device not listed in system devices
Posted on August 16, 2016 at 14:42
Hi,
I try to create a simple USB HID device with an STM32f429 board (the one with the LCD screen). I search for information for weeks, but I can't make it work. I read many times that there are “tons of examples�?, but I never managed to get one working. It is already difficult to find the actual library and documentation… And I don't want to use the Cube, it is too messy. I always use the Standard Peripheral Library, which works fine. The USB library is actually a mess as well. As far as I understood the programmer has to modify some of the lib files: usb_bsp, usb_conf, usbd_conf, usbd_usr, usb_desc. Things would be much easier if there was a clear separation between the library and the application code. That being said, I managed to get several examples compile and run. I plug the mini USB (ST-Link side) to one USB port, the micro one on another one, and I have a FTDI serial USB cable plugged on USART1 for additional printf debug (PA9, PA10). I checked that the micro USB uses the PB14 and PB15 pins. HSE value is8000000. My init code is like that:
pin_t usbdm = make_pin(GPIO_PORT_B, 14);
pin_t usbdp = make_pin(GPIO_PORT_B, 15);
pin_t usbvbus = make_pin(GPIO_PORT_B, 12);
pin_t usbid = make_pin(GPIO_PORT_B, 13);
gpio_config_alternate(usbdm, pin_dir_read, pull_down, 12);
gpio_config_alternate(usbdp, pin_dir_read, pull_down, 12);
gpio_config(usbvbus, pin_dir_read, pull_up);
gpio_config_alternate(usbid, pin_dir_read, pull_down, 12);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
The PIO init is wrapped in a specific file. The code goes like this:
void
gpio_config(pin_t pin, pin_dir_t dir, pull_t pull) {
RCC_AHB1PeriphClockCmd(1 << pin.port, ENABLE);
GPIO_InitTypeDef def;
def.GPIO_Pin = 1 << pin.pin;
def.GPIO_Mode = dir;
def.GPIO_Speed = GPIO_Speed_100MHz;
if
(dir)
def.GPIO_OType = GPIO_OType_PP;
//output : Push Pull
else
def.GPIO_OType = GPIO_OType_OD;
//input : Open Drain
def.GPIO_PuPd = pull;
GPIO_Init(stm32f4xx_gpio_ports[pin.port], &def);
}
void
gpio_config_alternate(pin_t pin, pin_dir_t dir, pull_t pull, uint8_t af) {
if
(af > 15)
return
;
RCC_AHB1PeriphClockCmd(1 << pin.port, ENABLE);
GPIO_InitTypeDef def;
def.GPIO_Pin = 1 << pin.pin;
def.GPIO_Mode = GPIO_Mode_AF;
def.GPIO_Speed = GPIO_Speed_100MHz;
if
(dir)
def.GPIO_OType = GPIO_OType_PP;
//output : Push Pull
else
def.GPIO_OType = GPIO_OType_OD;
//input : Open Drain
def.GPIO_PuPd = pull;
GPIO_Init(stm32f4xx_gpio_ports[pin.port], &def);
GPIO_PinAFConfig(stm32f4xx_gpio_ports[pin.port], pin.pin, af);
}
I added a couple of printf in all callbacks of usbd_usr to ease debugging but. I also use gdb (I use the arm-none-eabi gcc toolchain) with breakpoints. The only callback called is:
void USBD_USR_Init(void)
In particular, this one is never called:
void USBD_USR_DeviceConnected (void)
What do I need to get the device at least enumerated with lsusb or equivalent? (I use “
system_profiler SPUSBDataType�?
on Mac) Note: please ST, setup a GIT repo or something like that. It is complicated to browse hundred of pages, with zip containing different versions of the same libraries. It is difficult to figure out where is the last version of each library. #!usb-!hid #!stm32-!usb