aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/stm32
diff options
context:
space:
mode:
authorUwe Bonnes2013-01-20 21:47:03 +0100
committerUwe Bonnes2013-01-21 11:02:44 +0100
commit749fb318e78b89584af000f4e2b41dce013a6fc3 (patch)
treeee18cb0b46eca94c5aaf39cd365b1b8bf9abf453 /src/platforms/stm32
parent1fa961841dd9a6abd3ad50106f59b2e18eeccb77 (diff)
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
Diffstat (limited to 'src/platforms/stm32')
-rw-r--r--src/platforms/stm32/cdcacm.c3
-rw-r--r--src/platforms/stm32/gdb_if.c29
2 files changed, 25 insertions, 7 deletions
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 <stdlib.h>
#include "platform.h"
+#include "gdb_if.h"
#if defined(PLATFORM_HAS_TRACESWO)
#include <traceswo.h>
#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)