aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-08-04 00:33:32 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2012-08-04 00:33:32 -0400
commitb642f7b095b2c9324281f2a7f929314ddbafe17c (patch)
tree9397c300956a4f7945822241a4d70577c1837b9a
parent6788dff2e0ba8a548b0a91b78c04031a4fc5df54 (diff)
usb_cdcacm: Set endpoint to NAK before checking byte count.
Fixes an (admittedly very unlikely) race condition. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
-rw-r--r--libmaple/usb/stm32f1/usb_cdcacm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/libmaple/usb/stm32f1/usb_cdcacm.c b/libmaple/usb/stm32f1/usb_cdcacm.c
index 07cf9c4..2a942e5 100644
--- a/libmaple/usb/stm32f1/usb_cdcacm.c
+++ b/libmaple/usb/stm32f1/usb_cdcacm.c
@@ -540,11 +540,11 @@ static void vcomDataTxCb(void) {
}
static void vcomDataRxCb(void) {
- /* This following is safe since we set the RX endpoint to NAK
- * after each data packet received, and only set it to VALID when
- * all bytes have been read. */
- n_unread_bytes = usb_get_ep_rx_count(USB_CDCACM_RX_ENDP);
usb_set_ep_rx_stat(USB_CDCACM_RX_ENDP, USB_EP_STAT_RX_NAK);
+ n_unread_bytes = usb_get_ep_rx_count(USB_CDCACM_RX_ENDP);
+ /* This copy won't overwrite unread bytes, since we've set the RX
+ * endpoint to NAK, and will only set it to VALID when all bytes
+ * have been read. */
usb_copy_from_pma((uint8*)vcomBufferRx, n_unread_bytes,
USB_CDCACM_RX_ADDR);