2016-03-18 06:42 AM
Hello,
i'm trying to make a USB cdc virtual port to transfer data to uart and back. I have successfully made the virtual port using CubeMX and transfer data to uart. But i have trouble to read data from uart and transfer it to virtual port (some characters get lost). Could someone help me with example or point me to an example using CubeMX HAL libraries?Thanks in advance for the answers. #usb #cdc2016-03-19 02:34 PM
2016-03-21 09:37 PM
> But i have trouble to read data from uart and transfer it to virtual port (some characters get lost).
It's because the difference of transfer interval timing between UART and USB bulk IN endpoint. While your CDC device connects to Windows, the bulk IN endpoint should wait for next 1ms SOF timing, before it could put another transfer to the bus (ie. USBD_CDC_TransmitPacket() call). On the other hand, UART RX interrupt could occur in shorter interval. And then, if your UART ISR would directly call USBD_CDC_TransmitPacket(), some characters would get lost. To escape from this timing difference, 1) In your UART ISR, received data is stored on a buffer, once. 2) In a timer interrupt of a couple of ms interval (or USB SOF ISR), the buffer is examined. If any data on the buffer, the data is sent using USBD_CDC_TransmitPacket(). You'll find this implementation using a timer in CDC_Standalone examples in cube ''projects'', for example, \Repository\STM32Cube_FW_F0_V1.5.0\Projects\STM32072B_EVAL\Applications\USB_Device\CDC_Standalone\Src\usbd_cdc_interface.c Find an example for your MCU, in the cube firmware library, in an EVAL board folder. Tsuneo