AnsweredAssumed Answered

STM32F4xx USB device CDC problem

Question asked by rubow.keith on Nov 6, 2014
I have implemented a USB virtual serial port (CDC) device using the USB HS interface on an STM32F429 processor on an STM32F429I-DISCO evaluation board. The virtual serial port acts as a communication link between my application running on the ARM, and Tera Term (or another terminal emulator) running on a PC. It does not act as a bridge to a UARD or other communications device.

The problem is that some characters that my application outputs end up missing, and do not appear on the Tera Term screen (I output only simple ASCII text). My output data is double buffered through a pair of 512 byte buffers. One buffer can be sent over the USB interface while the application can write data to the other buffer. Each time transmission of a buffer is complete, the buffers are switched (assuming there is data in the application's output buffer), and the new buffer is output to the USB while the application is given the (now empty) buffer that has been sent.

But some characters never appear on the Tera Term screen. This often happens at the end of a line when there is no more data to send. For example, I output "Command:" and see "Command" on the screen with the colon missing. It also happens sporadically in the middle of large quantities of data output by my application. It even happens when my application is sending only one character at a time, with long delays in between characters so that each packet sent has only one character. The characters just don't appear on the Tera Term screen.

I have put extensive debug code into my application to keep a history of characters my application sends, and a history of the size and contents of each packet sent over the USB. The history data indicates that all characters are sent, but some never show up on Tera Term. Because of my double buffering, each packet I send will be sent from a different buffer than the last packet. I call USBD_CDC_SetTxBuffer each time before I call USBD_CDC_TransmitPacket. I always wait for packet transmission to be complete before sending another packet.

What could be wrong? Is it something I am doing wrong, or could the problem be in the USB driver code? I could attach my complete source code (Atollif True Studio project) if anyone wants to look and my code or try running in on your own evaluation board.