AnsweredAssumed Answered

STM32F1 USB VCP Problems

Question asked by Gordon Williams on Dec 29, 2013
Latest reply on Jan 7, 2014 by Gordon Williams
Hi. I'm developing an Open Source project (a JavaScript interpreter) for STM32 microcontrollers ( One part of this is a bootloader that mimic's ST's serial port bootloader, but over USB VCP - however the whole project depends on USB VCP.

It's based on ST's USB VCP example code (I recently updated from V3.4.0 to V4.0.0) and running on an STM32F103, but I'm having some big problems with it.

  • On all platforms, characters sent from the PC are occasionally lost.
  • On Windows a significant amount of PCs seem to just stop sending/receiving data after a while and the device and program using it have to be restarted before they'll work again. It seems like USB2 ports specifically have problems, and USB3 seem more reliable.

A few things that could be related:
  • When IMR_MSK contains all flags (they weren't all set for V3.4.0 of the libs), the USB device doesn't enumerate.
  • After testing it seems as if characters at the end of a USB packet are lost if it is full (>64 chars). So lowering VIRTUAL_COM_PORT_DATA_SIZE makes it even more likely that data gets lost.
  • Even though VIRTUAL_COM_PORT_DATA_SIZE is 64, occasionally USB_SIL_Read returns 65!!
  • I'm doing flow control using:  SetEPRxStatus(ENDP3, is_rx_buffer_not_full ? EP_RX_VALID : EP_RX_NAK); - however the RX buffer does not overflow.

The relevant code for the endpoint is here:

And all the code for the bootloader is in:

Please help! This is turning into a huge problem - while I can work around the lost characters by throttling the data sent over USB, I can't get around the complete loss of data when running under Windows.

If it helps, there are versions of the software available for a few of the 'HY' STM32F103 boards available on eBay, and it exhibits the same problems on all of those too. If someone can help fix this I'm more than happy to send them one of the Espruino board kits that I've made by way of a thankyou!