From 4e20db54c8134c5f967f5ca4d9efe0577b920041 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Sat, 4 Aug 2012 00:33:32 -0400 Subject: usb_cdcacm: Set endpoint to NAK before checking byte count. Fixes an (admittedly very unlikely) race condition. Signed-off-by: Marti Bolivar --- libmaple/usb/stm32f1/usb_cdcacm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libmaple/usb/stm32f1') 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); -- cgit v1.2.3