From fd9eef821e7451fcb1d7839f9d1d21c098787327 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Thu, 16 Oct 2014 13:48:28 -0700 Subject: Revert USB double buffered OUT handling on STM32F1. This introduced a bug where the endpoint can get stuck, forever sending NAK. --- src/platforms/stm32/cdcacm.c | 13 +++++++++---- src/platforms/stm32/gdb_if.c | 46 +++++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 22 deletions(-) (limited to 'src/platforms/stm32') diff --git a/src/platforms/stm32/cdcacm.c b/src/platforms/stm32/cdcacm.c index ef7ff3b..9694cf0 100644 --- a/src/platforms/stm32/cdcacm.c +++ b/src/platforms/stm32/cdcacm.c @@ -485,17 +485,22 @@ static void cdcacm_set_config(usbd_device *dev, uint16_t wValue) configured = wValue; /* GDB interface */ +#ifdef STM32F4 usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, gdb_usb_out_cb); + CDCACM_PACKET_SIZE, gdb_usb_out_cb); +#else + usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, NULL); +#endif usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, NULL); + CDCACM_PACKET_SIZE, NULL); usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); /* Serial interface */ usbd_ep_setup(dev, 0x03, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, usbuart_usb_out_cb); + CDCACM_PACKET_SIZE, usbuart_usb_out_cb); usbd_ep_setup(dev, 0x83, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, usbuart_usb_in_cb); + CDCACM_PACKET_SIZE, usbuart_usb_in_cb); usbd_ep_setup(dev, 0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); #if defined(PLATFORM_HAS_TRACESWO) diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index 482effe..c8208b3 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -28,12 +28,14 @@ #include "gdb_if.h" static uint32_t count_out; -static uint32_t count_new; static uint32_t count_in; static uint32_t out_ptr; static uint8_t buffer_out[CDCACM_PACKET_SIZE]; -static uint8_t double_buffer_out[CDCACM_PACKET_SIZE]; static uint8_t buffer_in[CDCACM_PACKET_SIZE]; +#ifdef STM32F4 +static volatile uint32_t count_new; +static uint8_t double_buffer_out[CDCACM_PACKET_SIZE]; +#endif void gdb_if_putchar(unsigned char c, int flush) { @@ -63,6 +65,7 @@ void gdb_if_putchar(unsigned char c, int flush) } } +#ifdef STM32F4 void gdb_usb_out_cb(usbd_device *dev, uint8_t ep) { (void)ep; @@ -73,6 +76,27 @@ void gdb_usb_out_cb(usbd_device *dev, uint8_t ep) usbd_ep_nak_set(dev, CDCACM_GDB_ENDPOINT, 0); } } +#endif + +static void gdb_if_update_buf(void) +{ + while (cdcacm_get_config() != 1); +#ifdef STM32F4 + asm volatile ("cpsid i; isb"); + if (count_new) { + memcpy(buffer_out, double_buffer_out, count_new); + count_out = count_new; + count_new = 0; + out_ptr = 0; + usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); + } + asm volatile ("cpsie i; isb"); +#else + count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT, + buffer_out, CDCACM_PACKET_SIZE); + out_ptr = 0; +#endif +} unsigned char gdb_if_getchar(void) { @@ -82,14 +106,7 @@ unsigned char gdb_if_getchar(void) if (!cdcacm_get_dtr()) return 0x04; - while (cdcacm_get_config() != 1); - if (count_new) { - memcpy(buffer_out, double_buffer_out,count_new); - count_out = count_new; - count_new = 0; - out_ptr = 0; - usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); - } + gdb_if_update_buf(); } return buffer_out[out_ptr++]; @@ -104,14 +121,7 @@ unsigned char gdb_if_getchar_to(int timeout) if (!cdcacm_get_dtr()) return 0x04; - while (cdcacm_get_config() != 1); - if (count_new) { - memcpy(buffer_out, double_buffer_out,count_new); - count_out = count_new; - count_new = 0; - out_ptr = 0; - usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); - } + gdb_if_update_buf(); } while(timeout_counter && !(out_ptr < count_out)); if(out_ptr < count_out) -- cgit v1.2.3