cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 USB DEVICE CDC PROBLEM

PanosGial
Associate II

I am trying to use STM32H747IGT6 as a USB device. I want to sent data using CDC. Below you can find my configuration and code. The MX_USB_DEVICE_Init() is successful. Although when I call the CDC_Transmit_FS, it never returns USB_OK and I wasn't able to find the USB device through my laptop. 
The only thing I found is that after the initialization done by the ST Generated code, the struct with the device configuration is still NULL and it seems that nothing is actually initialised and I assume that this is a problem. Although the initialization function returns USB_OK. 
Does anyone have any ideas about this problem?
If you need further information about the project please let me know.
Screenshot 2024-01-09 at 8.22.23 PM.pngScreenshot 2024-01-09 at 8.23.09 PM.pngScreenshot 2024-01-09 at 8.24.47 PM.pngScreenshot 2024-01-09 at 8.25.29 PM.pngScreenshot 2024-01-09 at 8.26.02 PM.png

10 REPLIES 10
STea
ST Employee

Hello @PanosGial ,

can you please send the generated MX_USB_DEVICE_Init() function and give more details about the CubeMX version you are using to further investigate your issue ?

BR

In order 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 am using the version 1.14.0 of STM32CubeIDE
Here is the MX_USB_DEVICE_init()
I  tried moving HAL_PWREx_EnableUSBVoltageDetector() above the other functions(inside USER CODE BEGIN USB_DEVICE_INIT_PreTreatment) but nothing changes.

Thank you in advance
Screenshot 2024-01-10 at 3.20.44 PM.png

Sebastiaan
Senior

Are you using a nucleo board or your own design?

If the device is not even recognized by your PC, that could indicate pinout issues. The device should put a high signal on D+ so that the laptop can detect a new USB device.

If that's not happening, maybe an external pull-up is required on D+ (could be that your STM32 does not automatically control D+, that info is in the datasheet).

Sebastiaan
Senior

Your code uses "HAL_PWREx_EnableUSBVoltageDetector()" but VBUS sensing is disabled in your cubemx configuration? At least, I suppose that's what "HAL_PWREx_EnableUSBVoltageDetector" is for but I'm not sure. It's worth to verify that too.. The easiest (if you don't need it) is to keep vbus sensing disabled.

This is a custom design. The pinout is ok and the external pull up is applied but I cannot detect the USB device from my laptop

Use a decent Linux machine; enable kernel trace (dmesg). Observe the dmesg after plug in the device (compare with a good CDC device like a USB to serial adapter). If still there's absolutely nothing in dmesg, there is one of problems mentioned by @Sebastiaan. Dual-core STM32H7 are complicated, you may want to start from a simpler single-core MCU.

 

Sebastiaan
Senior

Actually, in the reference manual (rm0399), it's mentioned that DP (and DM) have integrated pull-ups and pull-downs. So in that case, you don't need, and don't even want external pull-ups.

We had the same issue on an STM32F4, where pull-ups were integrated, but also added externally. As a consequence, your laptop immediately detects the pull-up and tries to communicate, but the USB peripheral is not yet started, and hence the initialization (negotiation) procedure fails, and on windows this pops up as an error like "could not read device descriptor".

In windows device manager, you can disable and re-enable the device to launch a new negotiation when the USB stack is running. On linux, similar information can indeed be retrieved via dmesg log, as @Pavel A. points out, and there certainly must be a way to re-trigger the USB detection too.

unicyclebloke
Associate III

Did you get to the bottom of this? I seem to have the same issue (for a STM32H747BIT6). No errors are reported anywhere within MX_USB_DEVICE_Init(), but the data structure hUsbDeviceFS does not appear to be properly initialised. There is an array (of void*) called pClassDataCmsit which should hold a pointer to the CDC API (a USBD_CDC_HandleTypeDef*). The array length is only one and the value is NULL. 

My project is a vanilla project created with STM32CubeIDE. All I added was a bit of code to do a periodic write over the USB. This fails because of the NULL pointer. I have previously used STM32CubeIDE to create a USB project for STM32G4. It worked immediately. 

Thanks.

array (of void*) called pClassDataCmsit

This has something to to with the Composite device library. Before exposing the device to host, the device level descriptor must be ready, with all the functions (interfaces) registered. If the device is not composite, this pointer (or array) likely is unused, so not a problem.