AnsweredAssumed Answered

Questions about the STM32 usbd_cdc_core usb OTG driver

Question asked by morgan.christopher on Apr 29, 2014
Latest reply on Sep 14, 2015 by kern.chris
Hello.

Using stm32f107 here.

I've been using the v2.1.0 stm32 usb host device library to build a cdc device. I used the vcp example and modified it, but I'm seeing cases where a 64 packet is being lost.

I think I may have determined the cause of the issue. I modified usbd_cdc_core.c to add some accessors to let me write into the APP_Rx_Buffer with memcpy. I'm performing these writes into the buffer from task level (running embos here), by disabling interrupts and then calling the routines.

I suspect the issue may be due to the way DCD_EP_Tx() works. It looks like Handle_USBAsynchXfer() is assuming that the APP_Rx_ptr_out can be advanced, because the routine is running at isr time and because DCD_EP_Tx() is processing the payload. But it looks like DCD_EP_Tx() is simply setting the transaction up. I suspect my issue is that at task time I'm out running the transfer.

The transfer is setup by DCD_EP_Tx(), APP_Rx_ptr_out is advanced and then task execution resumes, but the data hasn't been sent yet. At this time the task writes some number of bytes into the APP_Rx_Buffer, overwriting the data that is still pending to be sent.

Am I misunderstanding how this is working? How can I ensure that I can write into the APP_Rx_buffer outside of a usb isr without overwriting data pending to be sent?

Outcomes