Skip to content

Commit

Permalink
ports/all: Revert changes to mphalport/tinyusb for CDC debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
iabdalkader committed Jan 19, 2024
1 parent 6e252c7 commit 9fceba6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
13 changes: 2 additions & 11 deletions ports/mimxrt/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 15 additions & 9 deletions ports/nrf/drivers/usb/usb_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
10 changes: 1 addition & 9 deletions ports/rp2/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9fceba6

Please sign in to comment.