aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/stm32/gdb_if.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platforms/stm32/gdb_if.c')
-rw-r--r--src/platforms/stm32/gdb_if.c79
1 files changed, 50 insertions, 29 deletions
diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c
index 3ea7d14..52922e7 100644
--- a/src/platforms/stm32/gdb_if.c
+++ b/src/platforms/stm32/gdb_if.c
@@ -22,18 +22,19 @@
* Serial Debugging protocol is implemented. This implementation for STM32
* uses the USB CDC-ACM device bulk endpoints to implement the channel.
*/
-#include "platform.h"
-#include <libopencm3/usb/usbd.h>
-
+#include "general.h"
+#include "cdcacm.h"
#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)
{
@@ -47,37 +48,64 @@ void gdb_if_putchar(unsigned char c, int flush)
}
while(usbd_ep_write_packet(usbdev, CDCACM_GDB_ENDPOINT,
buffer_in, count_in) <= 0);
+
+ if (flush && (count_in == CDCACM_PACKET_SIZE)) {
+ /* We need to send an empty packet for some hosts
+ * to accept this as a complete transfer. */
+ /* libopencm3 needs a change for us to confirm when
+ * that transfer is complete, so we just send a packet
+ * containing a null byte for now.
+ */
+ while (usbd_ep_write_packet(usbdev, CDCACM_GDB_ENDPOINT,
+ "\0", 1) <= 0);
+ }
+
count_in = 0;
}
}
+#ifdef STM32F4
void gdb_usb_out_cb(usbd_device *dev, uint8_t ep)
{
(void)ep;
usbd_ep_nak_set(dev, CDCACM_GDB_ENDPOINT, 1);
- count_new = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT,
- double_buffer_out, CDCACM_PACKET_SIZE);
+ count_new = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT,
+ double_buffer_out, CDCACM_PACKET_SIZE);
if(!count_new) {
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)
{
- while(!(out_ptr < count_out)) {
+ while (!(out_ptr < count_out)) {
/* Detach if port closed */
- if(!cdcacm_get_dtr())
+ 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++];
@@ -85,22 +113,15 @@ unsigned char gdb_if_getchar(void)
unsigned char gdb_if_getchar_to(int timeout)
{
- timeout_counter = timeout/100;
+ platform_timeout_set(timeout);
- if(!(out_ptr < count_out)) do {
+ if (!(out_ptr < count_out)) do {
/* Detach if port closed */
- if(!cdcacm_get_dtr())
+ 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);
- }
- } while(timeout_counter && !(out_ptr < count_out));
+ gdb_if_update_buf();
+ } while (!platform_timeout_is_expired() && !(out_ptr < count_out));
if(out_ptr < count_out)
return gdb_if_getchar();