Hello all,
I am following the Virtual COM example to communicate with the PC by using the USB port and process the data like a serial port. Until there everything works fine, I can send data and receive with no problems. After that I used a software that sends a data frame every second, it works for a while but after some time, sometimes as soon as 15 seconds sometimes takes 10 minutes, stop working. I have been debugging the code and what I found is USBD_CDC_ACM_DataAvailable always return 0 when it does not work properly, but I could not go beyond that. Has anyone experienced anything similar? Any advice on what to check or possible solutions?
Thanks,
As discussed on this topic, http://www.keil.com/forum/57272/ USBD_CDC_ACM (MiddleWare common across MCUs) seems to have a bug, which appears when the Receive buffer is (nearly) full by the last packet. Once the last packet is deferred (CDC_DepOutPending), odd behavior occurs around this buffer, like GetChar/DataAvailable
As I don’t have the source code of current USBD_CDC_ACM, I can’t dig this trouble any more. Contact to Keil Support on this issue.
For temporal workaround, you may double the size of the Receive buffer (USBD_CDC_ACM_RECEIVEBUF_SIZE macro in usb_config.c), so that packet pending doesn’t occur. USBD_CDC_ACM_RECEIVEBUF_SIZE should be a number of power of 2 (2^N).
Tsuneo
Dear Tsuneo,
Thanks for your answer. I have changed the Receive Buffer size as you adviced me, seems to take more time to hang although eventually it does. The data frames I am sending are fairly small, just 8 bytes. Since the buffer seems to be the problem, is there any way to empty it at some point?
Thanks