cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 libusb-win32 with FREERTOS problem

ahmed_drioueche
Associate

Hello, 

I'm using STM32F407VGT board to send and receive data to/from a Nodejs application via libusb. This works correctly when not using freeRTOS, but as soon as i create a freeRTOS task or use any CMSIS function such as  osDelay() the board's usb device is no longer recognized by my windows 10, and my Nodejs app prints this to the console: 

libusb: error [init_device] device 'USB\VID_0000&PID_0002\5&15165C90&0&2' has invalid descriptor!
libusb: warning [winusb_get_device_list] failed to initialize device 'USB\VID_0000&PID_0002\5&15165C90&0&2'

I have modified some usbd_desc.c and usbd_cdc.c files to make it compatibe with libusb (without freeRTOS) as shown in this video from STMicroelectronics: (starting from minute 6) https://www.youtube.com/watch?v=ft8LXVcYFRg

The changes are as folllows:

in usbd_desc.c changed the bDeviceClass and bDeviceSubClass to 0, 

in usbd_cdc.c removed the interrupt endpoint

In usbd_cdc.h changed USB_CDC_CONFIG_DESC_SIZ to 32 instead of 67

installed WinUSB driver for the device

 

Removing these modifications freeRTOS no longer causes the mentioned issue but the USB no longer works

If anyone has a clue please help

 

3 REPLIES 3
Bob S
Principal

The issue is probably FreeRTOS related since the USB code works without FreeRTOS (presuming you did not change the USB code when you added FreeRTOS).  Check the stack sizes for all of your tasks.  In fact make sure you have the FreeRTOS stack checking features enabled.

Calling osDelay() from ANY task causes USB to fail?????

Hello, Thanks for your reply

The difference between the USB functioning properly and getting completly corrupted is removing or including this line that creates a freeRTOS task :  osThreadDef(Task2, (os_pthread)usbHandler, osPriorityLow, 0, 32);

          This one -> USBTaskHandle = osThreadCreate(osThread(Task2), NULL);

(usbHandler is an empty function)

The initiation of freeRTOS is always present in both cases: 

MX_FREERTOS_Init();

osKernelStart();

I experimented with different priorities and stack sizes but the result is the same. 

Calling osDelay anywhere makes the USB permenently stop sending and receiving (I suspect USB descriptor corruptiion)

That usage of osThreadDef() [with 5 params] does not match any definition I've seen.  But it looks like your stack size is 32, which I think means 32 BYTES.  That is waaaaaaaaaaaay too small for ANY task stack. Even if it was 32 WORDS it would be way too small.  Any interrupt will overflow that stack and trash things.  Try at least 128 (for an empty task) or larger.