From 1a7af52edc2314b88005b4ae762ea801c9f0f29b Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sun, 21 Aug 2022 16:23:56 +0100 Subject: [PATCH] usb_serial: Fixed up the nomenclature for the USB serial interfaces --- src/include/general.h | 2 +- src/platforms/common/aux_serial.c | 4 +-- src/platforms/common/usb_serial.c | 50 ++++++++++++++-------------- src/platforms/common/usb_serial.h | 2 +- src/platforms/common/usbuart.h | 2 +- src/platforms/stm32/gdb_if.c | 6 ++-- src/platforms/stm32/rtt_if.c | 6 ++-- src/platforms/stm32/traceswodecode.c | 2 +- src/platforms/tm4c/gdb_if.c | 6 ++-- src/target/target.c | 2 +- 10 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/include/general.h b/src/include/general.h index 0e8fdca..a5d37d6 100644 --- a/src/include/general.h +++ b/src/include/general.h @@ -78,7 +78,7 @@ enum BMP_DEBUG { # define DEBUG_WIRE(...) do {} while(0) # define DEBUG_GDB_WIRE(...) do {} while(0) -void debug_uart_send_stdout(const uint8_t *data, size_t len); +void debug_serial_send_stdout(const uint8_t *data, size_t len); #else # include extern int cl_debuglevel; diff --git a/src/platforms/common/aux_serial.c b/src/platforms/common/aux_serial.c index ef679f1..4b38fde 100644 --- a/src/platforms/common/aux_serial.c +++ b/src/platforms/common/aux_serial.c @@ -335,7 +335,7 @@ static void aux_serial_receive_isr(const uint32_t usart, const uint8_t dma_irq) #ifdef USART_ICR USART_ICR(usart) = USART_ICR_IDLECF; #endif - debug_uart_run(); + debug_serial_run(); } nvic_enable_irq(dma_irq); @@ -370,7 +370,7 @@ static void aux_serial_dma_receive_isr(const uint8_t usart_irq, const uint8_t dm /* Clear flags and transmit a packet*/ dma_clear_interrupt_flags(USBUSART_DMA_BUS, dma_rx_channel, DMA_CGIF); - debug_uart_run(); + debug_serial_run(); nvic_enable_irq(usart_irq); } diff --git a/src/platforms/common/usb_serial.c b/src/platforms/common/usb_serial.c index 4f7d7ff..0c5e801 100644 --- a/src/platforms/common/usb_serial.c +++ b/src/platforms/common/usb_serial.c @@ -57,12 +57,12 @@ #include #endif -static bool gdb_uart_dtr = true; +static bool gdb_serial_dtr = true; static void usb_serial_set_state(usbd_device *dev, uint16_t iface, uint8_t ep); -static void debug_uart_send_callback(usbd_device *dev, uint8_t ep); -static void debug_uart_receive_callback(usbd_device *dev, uint8_t ep); +static void debug_serial_send_callback(usbd_device *dev, uint8_t ep); +static void debug_serial_receive_callback(usbd_device *dev, uint8_t ep); static bool debug_serial_send_complete = true; @@ -80,7 +80,7 @@ static uint8_t debug_serial_debug_write_index; static uint8_t debug_serial_debug_read_index; #endif -static enum usbd_request_return_codes gdb_uart_control_request(usbd_device *dev, struct usb_setup_data *req, +static enum usbd_request_return_codes gdb_serial_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *const len, void (**complete)(usbd_device *dev, struct usb_setup_data *req)) { (void)buf; @@ -92,7 +92,7 @@ static enum usbd_request_return_codes gdb_uart_control_request(usbd_device *dev, switch (req->bRequest) { case USB_CDC_REQ_SET_CONTROL_LINE_STATE: usb_serial_set_state(dev, req->wIndex, CDCACM_GDB_ENDPOINT); - gdb_uart_dtr = req->wValue & 1; + gdb_serial_dtr = req->wValue & 1; return USBD_REQ_HANDLED; case USB_CDC_REQ_SET_LINE_CODING: if (*len < sizeof(struct usb_cdc_line_coding)) @@ -102,7 +102,12 @@ static enum usbd_request_return_codes gdb_uart_control_request(usbd_device *dev, return USBD_REQ_NOTSUPP; } -static enum usbd_request_return_codes debug_uart_control_request(usbd_device *dev, struct usb_setup_data *req, +bool gdb_serial_get_dtr(void) +{ + return gdb_serial_dtr; +} + +static enum usbd_request_return_codes debug_serial_control_request(usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *const len, void (**complete)(usbd_device *dev, struct usb_setup_data *req)) { (void)complete; @@ -129,11 +134,6 @@ static enum usbd_request_return_codes debug_uart_control_request(usbd_device *de return USBD_REQ_NOTSUPP; } -bool gdb_uart_get_dtr(void) -{ - return gdb_uart_dtr; -} - void usb_serial_set_state(usbd_device *const dev, const uint16_t iface, const uint8_t ep) { uint8_t buf[10]; @@ -163,9 +163,9 @@ void usb_serial_set_config(usbd_device *dev, uint16_t value) usbd_ep_setup(dev, (CDCACM_GDB_ENDPOINT + 1) | USB_REQ_TYPE_IN, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); /* Serial interface */ - usbd_ep_setup(dev, CDCACM_UART_ENDPOINT, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE / 2, debug_uart_receive_callback); + usbd_ep_setup(dev, CDCACM_UART_ENDPOINT, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE / 2, debug_serial_receive_callback); usbd_ep_setup( - dev, CDCACM_UART_ENDPOINT | USB_REQ_TYPE_IN, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, debug_uart_send_callback); + dev, CDCACM_UART_ENDPOINT | USB_REQ_TYPE_IN, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, debug_serial_send_callback); usbd_ep_setup(dev, (CDCACM_UART_ENDPOINT + 1) | USB_REQ_TYPE_IN, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); #ifdef PLATFORM_HAS_TRACESWO @@ -174,9 +174,9 @@ void usb_serial_set_config(usbd_device *dev, uint16_t value) #endif usbd_register_control_callback(dev, USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, - USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, debug_uart_control_request); + USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, debug_serial_control_request); usbd_register_control_callback(dev, USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, - USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, gdb_uart_control_request); + USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, gdb_serial_control_request); /* Notify the host that DCD is asserted. * Allows the use of /dev/tty* devices on *BSD/MacOS @@ -189,7 +189,7 @@ void usb_serial_set_config(usbd_device *dev, uint16_t value) #endif } -void debug_uart_send_stdout(const uint8_t *const data, const size_t len) +void debug_serial_send_stdout(const uint8_t *const data, const size_t len) { for (size_t offset = 0; offset < len; offset += CDCACM_PACKET_SIZE) { const size_t count = MIN(len - offset, CDCACM_PACKET_SIZE); @@ -230,7 +230,7 @@ static bool debug_serial_fifo_buffer_empty(void) * Runs deferred processing for AUX serial RX, draining RX FIFO by sending * characters to host PC via the debug serial interface. */ -static void debug_uart_send_aux_serial_data(void) +static void debug_serial_send_data(void) { debug_serial_send_complete = false; aux_serial_update_receive_buffer_fullness(); @@ -255,7 +255,7 @@ static void debug_uart_send_aux_serial_data(void) } } -void debug_uart_run(void) +void debug_serial_run(void) { nvic_disable_irq(USB_IRQ); @@ -264,7 +264,7 @@ void debug_uart_run(void) /* Try to send a packet if usb is idle */ if (debug_serial_send_complete) - debug_uart_send_aux_serial_data(); + debug_serial_send_data(); nvic_enable_irq(USB_IRQ); } @@ -277,7 +277,7 @@ static void debug_serial_append_char(const char c) debug_serial_debug_write_index %= AUX_UART_BUFFER_SIZE; } -size_t debug_uart_write(const char *buf, const size_t len) +size_t debug_serial_debug_write(const char *buf, const size_t len) { if (nvic_get_active_irq(USB_IRQ) || nvic_get_active_irq(USBUSART_IRQ) || nvic_get_active_irq(USBUSART_DMA_RX_IRQ)) return 0; @@ -296,21 +296,21 @@ size_t debug_uart_write(const char *buf, const size_t len) debug_serial_append_char(buf[offset]); } - debug_uart_run(); + debug_serial_run(); return offset; } -static void debug_uart_send_callback(usbd_device *dev, uint8_t ep) +static void debug_serial_send_callback(usbd_device *dev, uint8_t ep) { (void) ep; (void) dev; #if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) - debug_uart_send_aux_serial_data(); + debug_serial_send_data(); #endif } #ifndef ENABLE_RTT -static void debug_uart_receive_callback(usbd_device *dev, uint8_t ep) +static void debug_serial_receive_callback(usbd_device *dev, uint8_t ep) { char *const transmit_buffer = aux_serial_current_transmit_buffer() + aux_serial_transmit_buffer_fullness(); const uint16_t len = usbd_ep_read_packet(dev, ep, transmit_buffer, CDCACM_PACKET_SIZE); @@ -347,7 +347,7 @@ int _write(const int file, const void *const ptr, const size_t len) (void)file; #ifdef PLATFORM_HAS_DEBUG if (debug_bmp) - return debug_uart_write(ptr, len); + return debug_serial_debug_write(ptr, len); #endif return len; } diff --git a/src/platforms/common/usb_serial.h b/src/platforms/common/usb_serial.h index ee49456..10113eb 100644 --- a/src/platforms/common/usb_serial.h +++ b/src/platforms/common/usb_serial.h @@ -34,6 +34,6 @@ void usb_serial_set_config(usbd_device *dev, uint16_t value); -bool gdb_uart_get_dtr(void); +bool gdb_serial_get_dtr(void); #endif /*USB_SERIAL_H*/ diff --git a/src/platforms/common/usbuart.h b/src/platforms/common/usbuart.h index 2885f6c..b1e438d 100644 --- a/src/platforms/common/usbuart.h +++ b/src/platforms/common/usbuart.h @@ -22,7 +22,7 @@ #include "general.h" -void debug_uart_run(void); +void debug_serial_run(void); uint32_t debug_serial_fifo_send(const char *const fifo, const uint32_t fifo_begin, const uint32_t fifo_end); #define TX_LED_ACT (1 << 0) diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index 1224111..5e680ed 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -45,7 +45,7 @@ void gdb_if_putchar(unsigned char c, int flush) if (flush || (count_in == CDCACM_PACKET_SIZE)) { /* Refuse to send if USB isn't configured, and * don't bother if nobody's listening */ - if (usb_get_config() != 1 || !gdb_uart_get_dtr()) { + if (usb_get_config() != 1 || !gdb_serial_get_dtr()) { count_in = 0; return; } @@ -107,7 +107,7 @@ unsigned char gdb_if_getchar(void) while (!(out_ptr < count_out)) { /* Detach if port closed */ - if (!gdb_uart_get_dtr()) { + if (!gdb_serial_get_dtr()) { __WFI(); return 0x04; } @@ -125,7 +125,7 @@ unsigned char gdb_if_getchar_to(int timeout) if (!(out_ptr < count_out)) do { /* Detach if port closed */ - if (!gdb_uart_get_dtr()) { + if (!gdb_serial_get_dtr()) { __WFI(); /* systick will wake up too!*/ return 0x04; } diff --git a/src/platforms/stm32/rtt_if.c b/src/platforms/stm32/rtt_if.c index 2306844..88ace03 100644 --- a/src/platforms/stm32/rtt_if.c +++ b/src/platforms/stm32/rtt_if.c @@ -59,10 +59,10 @@ inline static bool recv_set_nak() return recv_bytes_free() < 2 * CDCACM_PACKET_SIZE; } -/* debug_uart_receive_callback is called when usb uart has received new data for target. +/* debug_serial_receive_callback is called when usb uart has received new data for target. this routine has to be fast */ -void debug_uart_receive_callback(usbd_device *dev, uint8_t ep) +void debug_serial_receive_callback(usbd_device *dev, uint8_t ep) { (void)dev; (void)ep; @@ -121,7 +121,7 @@ bool rtt_nodata() /* rtt target to host: write string */ uint32_t rtt_write(const char *buf, uint32_t len) { - if (len != 0 && usbdev && usb_get_config() && gdb_uart_get_dtr()) { + if (len != 0 && usbdev && usb_get_config() && gdb_serial_get_dtr()) { for (uint32_t p = 0; p < len; p += CDCACM_PACKET_SIZE) { uint32_t plen = MIN(CDCACM_PACKET_SIZE, len - p); while(usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, buf + p, plen) <= 0); diff --git a/src/platforms/stm32/traceswodecode.c b/src/platforms/stm32/traceswodecode.c index 9224bf4..aeb48c9 100644 --- a/src/platforms/stm32/traceswodecode.c +++ b/src/platforms/stm32/traceswodecode.c @@ -47,7 +47,7 @@ uint16_t traceswo_decode(usbd_device *usbd_dev, uint8_t addr, if (swo_print) { swo_buf[swo_buf_len++]=ch; if (swo_buf_len == sizeof(swo_buf)) { - if (usb_get_config() && gdb_uart_get_dtr()) /* silently drop if usb not ready */ + if (usb_get_config() && gdb_serial_get_dtr()) /* silently drop if usb not ready */ usbd_ep_write_packet(usbd_dev, addr, swo_buf, swo_buf_len); swo_buf_len=0; } diff --git a/src/platforms/tm4c/gdb_if.c b/src/platforms/tm4c/gdb_if.c index 66ed595..37eeda6 100644 --- a/src/platforms/tm4c/gdb_if.c +++ b/src/platforms/tm4c/gdb_if.c @@ -40,7 +40,7 @@ void gdb_if_putchar(unsigned char c, int flush) if (flush || count_in == CDCACM_PACKET_SIZE) { /* Refuse to send if USB isn't configured, and * don't bother if nobody's listening */ - if (usb_get_config() != 1 || !gdb_uart_get_dtr()) { + if (usb_get_config() != 1 || !gdb_serial_get_dtr()) { count_in = 0; return; } @@ -68,7 +68,7 @@ unsigned char gdb_if_getchar(void) { while (tail_out == head_out) { /* Detach if port closed */ - if (!gdb_uart_get_dtr()) + if (!gdb_serial_get_dtr()) return 0x04; while (usb_get_config() != 1) @@ -86,7 +86,7 @@ unsigned char gdb_if_getchar_to(int timeout) if (head_out == tail_out) do { /* Detach if port closed */ - if (!gdb_uart_get_dtr()) + if (!gdb_serial_get_dtr()) return 0x04; while (usb_get_config() != 1) diff --git a/src/target/target.c b/src/target/target.c index e332e84..5a4ea35 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -702,7 +702,7 @@ int tc_write(target *t, int fd, target_addr buf, unsigned int count) if (cnt > count) cnt = count; target_mem_read(t, tmp, buf, cnt); - debug_uart_send_stdout(tmp, cnt); + debug_serial_send_stdout(tmp, cnt); count -= cnt; buf += cnt; }