From 749fb318e78b89584af000f4e2b41dce013a6fc3 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 20 Jan 2013 21:47:03 +0100 Subject: gdb_if: Use a doubled buffer scheme for reading data from USB Needed, as the OTG driver erases the data read after eventually calling the callback --- src/platforms/stm32/cdcacm.c | 3 ++- src/platforms/stm32/gdb_if.c | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src/platforms/stm32') diff --git a/src/platforms/stm32/cdcacm.c b/src/platforms/stm32/cdcacm.c index 00c5ed2..b6d2602 100644 --- a/src/platforms/stm32/cdcacm.c +++ b/src/platforms/stm32/cdcacm.c @@ -36,6 +36,7 @@ #include #include "platform.h" +#include "gdb_if.h" #if defined(PLATFORM_HAS_TRACESWO) #include #endif @@ -487,7 +488,7 @@ static void cdcacm_set_config(usbd_device *dev, u16 wValue) /* GDB interface */ usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, NULL); + CDCACM_PACKET_SIZE, gdb_usb_out_cb); usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL); usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index 0e702a2..030205a 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -28,9 +28,11 @@ #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]; void gdb_if_putchar(unsigned char c, int flush) @@ -49,17 +51,28 @@ void gdb_if_putchar(unsigned char c, int flush) } } +void gdb_usb_out_cb(usbd_device *dev, uint8_t ep) +{ + (void)ep; + count_new = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT, + double_buffer_out, CDCACM_PACKET_SIZE); +} + unsigned char gdb_if_getchar(void) { + while(!(out_ptr < count_out)) { /* Detach if port closed */ if(!cdcacm_get_dtr()) return 0x04; while(cdcacm_get_config() != 1); - count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT, - buffer_out, CDCACM_PACKET_SIZE); - out_ptr = 0; + if (count_new) { + memcpy(buffer_out, double_buffer_out,count_new); + count_out = count_new; + count_new = 0; + out_ptr = 0; + } } return buffer_out[out_ptr++]; @@ -74,9 +87,13 @@ unsigned char gdb_if_getchar_to(int timeout) if(!cdcacm_get_dtr()) return 0x04; - count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT, - buffer_out, CDCACM_PACKET_SIZE); - out_ptr = 0; + 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; + } } while(timeout_counter && !(out_ptr < count_out)); if(out_ptr < count_out) -- cgit v1.2.3