diff --git a/src/platforms/common/usb_serial.c b/src/platforms/common/usb_serial.c index 024678e..e33e290 100644 --- a/src/platforms/common/usb_serial.c +++ b/src/platforms/common/usb_serial.c @@ -48,6 +48,7 @@ #endif #include "usbuart.h" +#include #include #include @@ -184,3 +185,31 @@ void debug_uart_send_stdout(const uint8_t *const data, const size_t len) nvic_enable_irq(USB_IRQ); } } + +#ifdef ENABLE_DEBUG +size_t usbuart_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; + + CM_ATOMIC_CONTEXT(); + + for (size_t i = 0; i < len && (usb_dbg_in + 1) % RX_FIFO_SIZE != usb_dbg_out; ++i) + { + if (buf[i] == '\n') + { + usb_dbg_buf[usb_dbg_in++] = '\r'; + usb_dbg_in %= RX_FIFO_SIZE; + + if ((usb_dbg_in + 1) % RX_FIFO_SIZE == usb_dbg_out) + break; + } + usb_dbg_buf[usb_dbg_in++] = buf[i]; + usb_dbg_in %= RX_FIFO_SIZE; + } + + usbuart_run(); + + return len; +} +#endif diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index 1c32fd4..668cce5 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -260,34 +260,6 @@ void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep) } #endif -#ifdef USBUART_DEBUG -size_t usbuart_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; - - CM_ATOMIC_CONTEXT(); - - for (size_t i = 0; i < len && (usb_dbg_in + 1) % RX_FIFO_SIZE != usb_dbg_out; i++) - { - if (buf[i] == '\n') - { - usb_dbg_buf[usb_dbg_in++] = '\r'; - usb_dbg_in %= RX_FIFO_SIZE; - - if ((usb_dbg_in + 1) % RX_FIFO_SIZE == usb_dbg_out) - break; - } - usb_dbg_buf[usb_dbg_in++] = buf[i]; - usb_dbg_in %= RX_FIFO_SIZE; - } - - usbuart_run(); - - return len; -} -#endif - /* * Runs deferred processing for USBUSART RX, draining RX FIFO by sending * characters to host PC via CDCACM. Allowed to write to FIFO OUT pointer.