Revert USB double buffered OUT handling on STM32F1.

This introduced a bug where the endpoint can get stuck, forever sending NAK.
This commit is contained in:
Gareth McMullin 2014-10-16 13:48:28 -07:00
parent f85a8c4ebb
commit fd9eef821e
2 changed files with 37 additions and 22 deletions

View File

@ -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)

View File

@ -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)