summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-14 01:46:25 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-14 01:46:25 +0100
commitcce7119a2b8f3cf61bd25105c8d8939a504dd5fa (patch)
tree654380cb0ffc0bde7f86413550a75672d4853c01
parent7e5be0b1b44f518fae56ef4ffd1dfe90ad134235 (diff)
downloadmicropython-cce7119a2b8f3cf61bd25105c8d8939a504dd5fa.tar.gz
micropython-cce7119a2b8f3cf61bd25105c8d8939a504dd5fa.zip
stmhal: Work around crazy bug in USB CDC.
Packets of 64 bytes length are not send to the host until the following packet is sent. Fixed by never sending packets of 64 bytes length.
-rw-r--r--stmhal/usbd_cdc_interface.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c
index 81f541df43..c6b6cf23f6 100644
--- a/stmhal/usbd_cdc_interface.c
+++ b/stmhal/usbd_cdc_interface.c
@@ -60,7 +60,7 @@ static uint16_t UserRxBufLen = 0; // counts number of valid characters in UserRx
static uint8_t UserTxBuffer[APP_TX_DATA_SIZE]; // data for USB IN endpoind is stored in this buffer
static uint16_t UserTxBufPtrIn = 0; // increment this pointer modulo APP_TX_DATA_SIZE when new data is available
-static uint16_t UserTxBufPtrOut = 0; // increment this pointer modulo APP_TX_DATA_SIZE when data is drained
+static __IO uint16_t UserTxBufPtrOut = 0; // increment this pointer modulo APP_TX_DATA_SIZE when data is drained
static int user_interrupt_char = VCP_CHAR_NONE;
static void *user_interrupt_data = NULL;
@@ -265,6 +265,14 @@ void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) {
}
buffptr = UserTxBufPtrOut;
+
+ // dpgeorge: For some reason that I don't understand, a packet size of 64 bytes
+ // (CDC_DATA_FS_MAX_PACKET_SIZE) does not get through to the USB host until the
+ // next packet is sent. To work around this, we just make sure that we never
+ // send a packet 64 bytes in length.
+ if (buffsize == CDC_DATA_FS_MAX_PACKET_SIZE) {
+ buffsize -= 1;
+ }
USBD_CDC_SetTxBuffer(&hUSBDDevice, (uint8_t*)&UserTxBuffer[buffptr], buffsize);