diff --git a/src/platforms/common/aux_serial.c b/src/platforms/common/aux_serial.c index 8eaa3bd..2cd79bd 100644 --- a/src/platforms/common/aux_serial.c +++ b/src/platforms/common/aux_serial.c @@ -306,18 +306,11 @@ void aux_serial_update_receive_buffer_fullness(void) bool aux_serial_receive_has_data(void) { - return -#ifdef ENABLE_DEBUG - usb_dbg_in != usb_dbg_out || -#endif - aux_serial_receive_write_index != aux_serial_receive_read_index; + return aux_serial_receive_write_index != aux_serial_receive_read_index; } void aux_serial_drain_receive_buffer(void) { -#ifdef ENABLE_DEBUG - usb_dbg_out = usb_dbg_in; -#endif aux_serial_receive_read_index = aux_serial_receive_write_index; /* Turn off LED */ usbuart_set_led_state(RX_LED_ACT, false); diff --git a/src/platforms/common/usb_serial.c b/src/platforms/common/usb_serial.c index 429c4a1..53c7c07 100644 --- a/src/platforms/common/usb_serial.c +++ b/src/platforms/common/usb_serial.c @@ -74,6 +74,13 @@ static bool aux_serial_receive_complete = true; * https://github.com/mirror/newlib-cygwin/blob/master/newlib/libc/sys/arm/syscalls.c#L115 */ void initialise_monitor_handles(void); + +/* Debug Fifo buffer with space for copy fn overrun */ +char usb_dbg_buf[AUX_UART_BUFFER_SIZE]; +/* Debug Fifo in pointer */ +uint8_t usb_dbg_in; +/* Debug Fifo out pointer */ +uint8_t usb_dbg_out; #endif static enum usbd_request_return_codes gdb_uart_control_request(usbd_device *dev, struct usb_setup_data *req, @@ -215,6 +222,13 @@ uint32_t debug_serial_fifo_send(const char *const fifo, const uint32_t fifo_begi return fifo_begin; } +#ifdef ENABLE_DEBUG +static bool debug_serial_fifo_has_data(void) +{ + return usb_dbg_in != usb_dbg_out; +} +#endif + /* * Runs deferred processing for AUX serial RX, draining RX FIFO by sending * characters to host PC via the debug serial interface. @@ -226,7 +240,14 @@ static void debug_uart_send_aux_serial_data(void) /* Forcibly empty fifo if no USB endpoint. * If fifo empty, nothing further to do. */ - if (usb_get_config() != 1 || !aux_serial_receive_has_data()) { + if (usb_get_config() != 1 || (!aux_serial_receive_has_data() +#ifdef ENABLE_DEBUG + && !debug_serial_fifo_has_data()) +#endif + ) { +#ifdef ENABLE_DEBUG + usb_dbg_out = usb_dbg_in; +#endif aux_serial_drain_receive_buffer(); aux_serial_receive_complete = true; } else { diff --git a/src/platforms/common/usbuart.h b/src/platforms/common/usbuart.h index 9c1d6a6..2885f6c 100644 --- a/src/platforms/common/usbuart.h +++ b/src/platforms/common/usbuart.h @@ -39,15 +39,6 @@ uint32_t debug_serial_fifo_send(const char *const fifo, const uint32_t fifo_begi #define USART_DMA_BUF_SIZE (1U << USART_DMA_BUF_SHIFT) #define AUX_UART_BUFFER_SIZE (USART_DMA_BUF_SIZE) - -#ifdef ENABLE_DEBUG -/* Debug Fifo buffer with space for copy fn overrun */ -extern char usb_dbg_buf[AUX_UART_BUFFER_SIZE]; -/* Debug Fifo in pointer */ -extern uint8_t usb_dbg_in; -/* Debug Fifo out pointer */ -extern uint8_t usb_dbg_out; -#endif #elif defined(LM4F) #define AUX_UART_BUFFER_SIZE 128 #endif diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index d559f5a..7560ca7 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -31,12 +31,3 @@ #include "usbuart.h" #include "usb.h" #include "aux_serial.h" - -#ifdef ENABLE_DEBUG -/* Debug Fifo buffer with space for copy fn overrun */ -char usb_dbg_buf[AUX_UART_BUFFER_SIZE]; -/* Debug Fifo in pointer */ -uint8_t usb_dbg_in; -/* Debug Fifo out pointer */ -uint8_t usb_dbg_out; -#endif