diff --git a/ports/mimxrt/mphalport.c b/ports/mimxrt/mphalport.c index 33693732f225..be4b1d8b5c81 100644 --- a/ports/mimxrt/mphalport.c +++ b/ports/mimxrt/mphalport.c @@ -34,7 +34,6 @@ #include "ticks.h" #include "tusb.h" #include "fsl_snvs_lp.h" -#include "tinyusb_debug.h" #ifndef MICROPY_HW_STDIN_BUFFER_LEN #define MICROPY_HW_STDIN_BUFFER_LEN 512 @@ -48,8 +47,6 @@ ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, uint8_t cdc_itf_pending; // keep track of cdc interfaces which need attention to poll void poll_cdc_interfaces(void) { - tud_task(); - // any CDC interfaces left to poll? if (cdc_itf_pending && ringbuf_free(&stdin_ringbuf)) { for (uint8_t itf = 0; itf < 8; ++itf) { @@ -63,12 +60,12 @@ void poll_cdc_interfaces(void) { } } + void tud_cdc_rx_cb(uint8_t itf) { // consume pending USB data immediately to free usb buffer and keep the endpoint from stalling. // in case the ringbuffer is full, mark the CDC interface that need attention later on for polling cdc_itf_pending &= ~(1 << itf); - for (uint32_t bytes_avail = tud_cdc_n_available(itf); - !tinyusb_debug_enabled() && bytes_avail > 0; --bytes_avail) { + for (uint32_t bytes_avail = tud_cdc_n_available(itf); bytes_avail > 0; --bytes_avail) { if (ringbuf_free(&stdin_ringbuf)) { int data_char = tud_cdc_read_char(); if (data_char == mp_interrupt_char) { @@ -118,12 +115,6 @@ int mp_hal_stdin_rx_chr(void) { mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { mp_uint_t ret = len; bool did_write = false; - - if (tinyusb_debug_enabled()) { - tinyusb_debug_tx_strn(str, len); - return len; - } - if (tud_cdc_connected()) { size_t i = 0; while (i < len) { diff --git a/ports/nrf/drivers/usb/usb_cdc.c b/ports/nrf/drivers/usb/usb_cdc.c index 2d9e28e5dfdc..3ded9fef62b2 100644 --- a/ports/nrf/drivers/usb/usb_cdc.c +++ b/ports/nrf/drivers/usb/usb_cdc.c @@ -43,8 +43,8 @@ #include "nrf_soc.h" #include "ble_drv.h" #endif -#include "tinyusb_debug.h" +#include "tinyusb_debug.h" extern void tusb_hal_nrf_power_event(uint32_t event); static void cdc_task(bool tx); @@ -155,10 +155,16 @@ static void cdc_task(bool tx) } static void usb_cdc_loop(void) { - if (!tinyusb_debug_enabled()) { - tud_task(); - cdc_task(true); + if (tinyusb_debug_enabled()) { + return ; } + + tud_task(); + cdc_task(true); +} + +void tud_cdc_rx_cb(uint8_t itf) { + cdc_task(false); } int usb_cdc_init(void) @@ -231,15 +237,15 @@ int mp_hal_stdin_rx_chr(void) { } mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { - if (tinyusb_debug_enabled()){ - tinyusb_debug_tx_strn(str, len); - return len; - } - for (const char *top = str + len; str < top; str++) { ringbuf_put((ringbuf_t*)&tx_ringbuf, *str); usb_cdc_loop(); } return len; } + +MP_WEAK void USBD_IRQHandler(void) { + tud_int_handler(0); +} + #endif // MICROPY_HW_USB_CDC diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index 9190f4084d5e..c5ae221e984b 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -37,7 +37,6 @@ #include "uart.h" #include "hardware/rtc.h" #include "pico/unique_id.h" -#include "tinyusb_debug.h" #if MICROPY_PY_NETWORK_CYW43 #include "lib/cyw43-driver/src/cyw43.h" @@ -88,8 +87,7 @@ void tud_cdc_rx_cb(uint8_t itf) { // consume pending USB data immediately to free usb buffer and keep the endpoint from stalling. // in case the ringbuffer is full, mark the CDC interface that need attention later on for polling cdc_itf_pending &= ~(1 << itf); - for (uint32_t bytes_avail = tud_cdc_n_available(itf); - !tinyusb_debug_enabled() && bytes_avail > 0; --bytes_avail) { + for (uint32_t bytes_avail = tud_cdc_n_available(itf); bytes_avail > 0; --bytes_avail) { if (ringbuf_free(&stdin_ringbuf)) { int data_char = tud_cdc_read_char(); if (data_char == mp_interrupt_char) { @@ -156,12 +154,6 @@ int mp_hal_stdin_rx_chr(void) { mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { mp_uint_t ret = len; bool did_write = false; - - if (tinyusb_debug_enabled()) { - tinyusb_debug_tx_strn(str, len); - return len; - } - #if MICROPY_HW_ENABLE_UART_REPL mp_uart_write_strn(str, len); did_write = true;