cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F745 USB communication fails

MDJ
Associate II

The project consists of STM32F745 MCU and a desktop application. The desktop application sends the data over USB CDC and receives the response back. The problem happens if large data chunks are being sent. What happens is that if several packets of lets say 220 bytes for example are sent a few of them are received without any problems (sometimes 3-4, sometimes 20-30 packets go through, no rules whatsoever). When the communication fails the F745 doesn't receive the whole 220 bytes packet. Sometimes it receives 128 bytes, sometimes 192 bytes, a few time 64 bytes are received and the communication fails. The USB FS is used with max packet size of 64 bytes. The endpoints are bulk endpoints. Library version for F745 is 1.16.2. Any insights would be appreciated as there are no evident errors.

6 REPLIES 6
MAnde.8
Associate

The 64/128/192 bytes you do receive indicate some pointer/buffer problem since the USB FIFO buffers are 64 bytes. Try identifying any pointer/buffer handling and make sure that the interrupt service routine doesn't interfere with the buffer pointers in your application. Make sure to check and handle any USB errors.

I used the CDC library in 2014 and have a vague memory that the application example had a bug where buffer wrapping didn't work correctly.

gbm
Lead III

Standard USB device problem remark #1: Make sure you call CDC_Transmit from the ISR of the same priority as the USB interrupt. Do not try to call it from any other piece of code, like main() function loop.

Pavel A.
Evangelist III

> Do not try to call it from any other piece of code, like main() function loop

why not, with USBD interrupt disabled?

MDJ
Associate II

Already tried, nothing changes.

The only thing I do is to take the data from the Rx callback and later I process it from the main loop. No modifications to the generated HAL CDC library for USB except for Rx callback implementation and added functionality to echo back line coding for windows devices. It is hard to pinpoint where it actually fails as it is almost pure generated library code but thanks for the insights. I will try to look into the things you suggested.

EDIT: I failed to mention that HAL library was modified to also include dual CDC support. One interface is to send data to and receive data from F745 and other is to gather logs from F745, (just for receiving data from F745, nothing is being sent to the MCU).

> Make sure you call CDC_Transmit from the ISR of the same priority as the USB interrupt.

> with USBD interrupt disabled

What a "nice" USB stack... Guys, seriously - TinyUSB is not a broken bloatware, has a sane design, is actively developed and is easy to use.