cancel
Showing results for 
Search instead for 
Did you mean: 

USB Composite HID+CDC (VCP) with STM32F401

Ludovictor
Associate II

Hi,

I would like to create a gamepad that is recognized by the computer (windows), and have the Virtual Com Port (CDC) to send en receive data with the computer. For that, I want to create an USB Composite with HID+CDC.

 

I found an exemple on this website https://www.programmersought.com/article/18127793400/, I followed the guide, correct the warning and error and now my STM32 is recognized ! In device and printer I see the Jubeat Controller, and in device manager I see the serial USB (COMX).

 

To test both, I simulate button push every 1s for the HID and look the button state in device and printer, and for the VCP I open putty, configure the port com and make an echo of what I write on the keyboard.

 

My problem is that when I write something on putty, I have an hardfault. The problem was that the buffer receive in static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) was not the value in RxBuffer but a strange address. I try to correct it by replacing different thing about pdev->... but when I think the problem is gone, the gamepad no more change state in device and printer.

 

I don't understand how works the USB protocol and I feel I'm really close to resolve my issue.

 

I can share you my project if you want. In attach, you can find files that I think I must correct/change. I use a Nucleo board with a STM32F401RE. I added a quartz to use the USB.

 

Thank you for your help !

 

Edit : you can find my project here https://github.com/Ludovictor/STM32-USB-Composite-HID-CDC 

3 REPLIES 3
FBL
ST Employee

Hi @Ludovictor 

Regarding the hardfault, first, you need to dig intro processor registers to determine the exact instruction that causes the fault. Second, about your application composite CDC HID, you may check maximum packet size of HID and CDC OUT endpoint, the buffer could be overwritten. Also, make sure the HID and CDC endpoints do not have overlapping addresses. You can find endpoints addresses in usbd_conf.h. Check this example it would be helpful as well.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!
Ludovictor
Associate II

The instruction that causes the fault is a memcpy in the static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) function. Like I said, it's normal because the memcpy try to copy a wrong address and not the Rx receive. It looks like the function USBD_Composite_DataOut or USBD_CDC_DataOut don't copy/send the correct address.

Hi ! I edit my post with my project available on github. If someone can take a look or try it with a nucleo board, it will be perfect !