cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID device not listed in system devices

thomaspietrzak9
Associate II
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
4 REPLIES 4
thomaspietrzak9
Associate II
Posted on November 03, 2016 at 19:44

In case others have a problem with the official demos and the STM32f4 discovery board (407 based) you need to compile with -DPLL_M=8, and change system_stm32f4xx.c like this:

#
if
defined(STM32F40_41xxx)
#define PLL_N 336
/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P 2
#elif defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx)
#define PLL_N 360
...

The default clock configuration is wrong with the original spl files.

dixon
Associate II
Posted on November 04, 2016 at 15:04

Just increase the heap size to double. It might work

thomaspietrzak9
Associate II
Posted on November 08, 2016 at 11:14

> Just increase the heap size to double. It might work

I don't understand how it relates to USB.

By the way, since I changed these clocks, UART is not working properly anymore. When I send data, the receiver see odd data, as if the baudrate was wrong. Does anybody have ideas on that?

Walid FTITI_O
Senior II
Posted on November 08, 2016 at 11:28

Hi Tom, 

I recommend that you check the ready-to-use example ''HID_Standalone'' inside the STM32CubeF4 library package at this path: STM32Cube_FW_F4_V1.13.0\Projects\STM324x9I_EVAL\Applications\USB_Host\HID_Standalone

You may also refere to the user manual

http://www.st.com/content/ccc/resource/technical/document/user_manual/cf/38/e5/b5/dd/1d/4c/09/DM00108129.pdf/files/DM00108129.pdf/jcr:content/translations/en.DM00108129.pdf

-Hannibal-