Configure CDC ACM packet size in a #define for easy access.

This doesn't work for >64 bytes.  Suspect bug in libopencm3.
This commit is contained in:
Gareth McMullin 2012-01-09 23:15:10 +13:00
parent 7e0de5b86b
commit 53ebc6770e
3 changed files with 16 additions and 17 deletions

View File

@ -83,14 +83,14 @@ static const struct usb_endpoint_descriptor gdb_data_endp[] = {{
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x01, .bEndpointAddress = 0x01,
.bmAttributes = USB_ENDPOINT_ATTR_BULK, .bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64, .wMaxPacketSize = CDCACM_PACKET_SIZE,
.bInterval = 1, .bInterval = 1,
}, { }, {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x81, .bEndpointAddress = 0x81,
.bmAttributes = USB_ENDPOINT_ATTR_BULK, .bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64, .wMaxPacketSize = CDCACM_PACKET_SIZE,
.bInterval = 1, .bInterval = 1,
}}; }};
@ -187,14 +187,14 @@ static const struct usb_endpoint_descriptor uart_data_endp[] = {{
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x03, .bEndpointAddress = 0x03,
.bmAttributes = USB_ENDPOINT_ATTR_BULK, .bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64, .wMaxPacketSize = CDCACM_PACKET_SIZE,
.bInterval = 1, .bInterval = 1,
}, { }, {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = 0x83, .bEndpointAddress = 0x83,
.bmAttributes = USB_ENDPOINT_ATTR_BULK, .bmAttributes = USB_ENDPOINT_ATTR_BULK,
.wMaxPacketSize = 64, .wMaxPacketSize = CDCACM_PACKET_SIZE,
.bInterval = 1, .bInterval = 1,
}}; }};
@ -459,8 +459,8 @@ static void cdcacm_data_rx_cb(u8 ep)
{ {
(void)ep; (void)ep;
char buf[64]; char buf[CDCACM_PACKET_SIZE];
int len = usbd_ep_read_packet(0x03, buf, 64); int len = usbd_ep_read_packet(0x03, buf, CDCACM_PACKET_SIZE);
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
usart_send_blocking(USART1, buf[i]); usart_send_blocking(USART1, buf[i]);
} }
@ -471,14 +471,14 @@ static void cdcacm_set_config(u16 wValue)
configured = wValue; configured = wValue;
/* GDB interface */ /* GDB interface */
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, NULL); usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL);
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_BULK, 64, NULL); usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL);
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
#ifdef INCLUDE_UART_INTERFACE #ifdef INCLUDE_UART_INTERFACE
/* Serial interface */ /* Serial interface */
usbd_ep_setup(0x03, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb); usbd_ep_setup(0x03, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, cdcacm_data_rx_cb);
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_BULK, 64, NULL); usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL);
usbd_ep_setup(0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); usbd_ep_setup(0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
#endif #endif

View File

@ -27,18 +27,16 @@
#include "gdb_if.h" #include "gdb_if.h"
#define VIRTUAL_COM_PORT_DATA_SIZE 64
static uint32_t count_out; static uint32_t count_out;
static uint32_t count_in; static uint32_t count_in;
static uint32_t out_ptr; static uint32_t out_ptr;
static uint8_t buffer_out[VIRTUAL_COM_PORT_DATA_SIZE]; static uint8_t buffer_out[CDCACM_PACKET_SIZE];
static uint8_t buffer_in[VIRTUAL_COM_PORT_DATA_SIZE]; static uint8_t buffer_in[CDCACM_PACKET_SIZE];
void gdb_if_putchar(unsigned char c, int flush) void gdb_if_putchar(unsigned char c, int flush)
{ {
buffer_in[count_in++] = c; buffer_in[count_in++] = c;
if(flush || (count_in == VIRTUAL_COM_PORT_DATA_SIZE)) { if(flush || (count_in == CDCACM_PACKET_SIZE)) {
/* Refuse to send if USB isn't configured, and /* Refuse to send if USB isn't configured, and
* don't bother if nobody's listening */ * don't bother if nobody's listening */
if((cdcacm_get_config() != 1) || !cdcacm_get_dtr()) { if((cdcacm_get_config() != 1) || !cdcacm_get_dtr()) {
@ -59,7 +57,7 @@ unsigned char gdb_if_getchar(void)
while(cdcacm_get_config() != 1); while(cdcacm_get_config() != 1);
count_out = usbd_ep_read_packet(1, buffer_out, count_out = usbd_ep_read_packet(1, buffer_out,
VIRTUAL_COM_PORT_DATA_SIZE); CDCACM_PACKET_SIZE);
out_ptr = 0; out_ptr = 0;
} }
@ -76,7 +74,7 @@ unsigned char gdb_if_getchar_to(int timeout)
return 0x04; return 0x04;
count_out = usbd_ep_read_packet(1, buffer_out, count_out = usbd_ep_read_packet(1, buffer_out,
VIRTUAL_COM_PORT_DATA_SIZE); CDCACM_PACKET_SIZE);
out_ptr = 0; out_ptr = 0;
} while(timeout_counter && !(out_ptr < count_out)); } while(timeout_counter && !(out_ptr < count_out));

View File

@ -33,6 +33,7 @@
#define INCLUDE_UART_INTERFACE #define INCLUDE_UART_INTERFACE
#define INLINE_GPIO #define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
/* Important pin mappings for STM32 implementation: /* Important pin mappings for STM32 implementation:
* *