Loading...
 

System Workbench for STM32


STM32H7 USB HS CDC Device Issues

I am trying to set up my STM32H753 to use the USB HS CDC controller. Its a custom board using the USB3300 as the external PHY.

My intended use case is to be able to transfer bulk data between my PC and the MCU. I am not trying to implement a virtual com port, the UART/USART devices that are being used are being used for a separate purpose and are not being used as part of the USB interface. Currently, I have one USART port active that I am using as a debug port so I print some useful state and event messages.

I ticked all the necessary boxes in CubeMX to generate code for a USB HS device using an external PHY using the CDC middleware. I have also implemented all the functions (CDC_Init_HS, CDC_DeInit_HS, CDC_Control_HS, CDC_Receive_HS, and CDC_Transmist_HS) in usb_cdc_if.c. All of these, apart from CDC_Receive_HS have been left at their defaults (not really sure what to do with them to be honest). In CDC_Receive_HS I copy the received data into a more accessible buffer, but otherwise the function is the same as its default. I have also added some print statements (using the USART) in some useful places so I can I keep track of what the MCU is doing.

The MCU is set up so that once every millisecond it will write data to the USB port, and every time it receives data on the USB port it will write a message to the USART saying that it received data.

I have also set up a small program on the PC using libusb to perform bulk transfer. Its a simple write some data, read some data in an infinite loop with some print statements to track progress.

What I am finding is that I can use libusb to connect to the USB HS CDC device reliably and usually the initial write command from the PC says it is successful, but this is the extent of my success. I get no print statements on the USART saying that the device received any data. Sometimes the PC will receive some data, but the next write command from the PC will always hang.

I suspect that I am not setting up something correctly, but I am struggling to find any useful documentation that will actually tell me how to use the HAL functions from the CubeMX generated code and what I actually need to do to set up the CDC interface properly.

Has anyone had any success using this device and this middleware?

Thanks in advance,
Bidski