AnsweredAssumed Answered

USB HID device not listed in system devices

Question asked by Tom on Aug 16, 2016
Latest reply on Nov 8, 2016 by FTITI.Walid

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 is 8000000.

My init code is like that:

01.pin_t usbdm = make_pin(GPIO_PORT_B, 14);
02.pin_t usbdp = make_pin(GPIO_PORT_B, 15);
03.pin_t usbvbus = make_pin(GPIO_PORT_B, 12);
04.pin_t usbid = make_pin(GPIO_PORT_B, 13);
06.gpio_config_alternate(usbdm, pin_dir_read, pull_down, 12);
07.gpio_config_alternate(usbdp, pin_dir_read, pull_down, 12);
08.gpio_config(usbvbus, pin_dir_read, pull_up);
09.gpio_config_alternate(usbid, pin_dir_read, pull_down, 12);
11.RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS, ENABLE);
12.RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE);
14.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:

01.void gpio_config(pin_t pin, pin_dir_t dir, pull_t pull) {
02.    RCC_AHB1PeriphClockCmd(1 << pin.port, ENABLE);
04.    GPIO_InitTypeDef def;
05.    def.GPIO_Pin = 1 <<;
06.    def.GPIO_Mode = dir;
07.    def.GPIO_Speed = GPIO_Speed_100MHz;
08.    if (dir)
09.        def.GPIO_OType = GPIO_OType_PP; //output : Push Pull
10.    else
11.        def.GPIO_OType = GPIO_OType_OD; //input : Open Drain
12.    def.GPIO_PuPd = pull;
14.    GPIO_Init(stm32f4xx_gpio_ports[pin.port], &def);
17.void gpio_config_alternate(pin_t pin, pin_dir_t dir, pull_t pull, uint8_t af) {
18.    if (af > 15)
19.        return;
20.    RCC_AHB1PeriphClockCmd(1 << pin.port, ENABLE);
22.    GPIO_InitTypeDef def;
23.    def.GPIO_Pin = 1 <<;
24.    def.GPIO_Mode = GPIO_Mode_AF;
25.    def.GPIO_Speed = GPIO_Speed_100MHz;
26.    if (dir)
27.        def.GPIO_OType = GPIO_OType_PP; //output : Push Pull
28.    else
29.        def.GPIO_OType = GPIO_OType_OD; //input : Open Drain
30.    def.GPIO_PuPd = pull;
32.    GPIO_Init(stm32f4xx_gpio_ports[pin.port], &def);
33.    GPIO_PinAFConfig(stm32f4xx_gpio_ports[pin.port],, 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.