From ef21e98520fb9cdac0ccc340f8be349af8abec29 Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Fri, 25 Jul 2025 12:42:09 +0200 Subject: [PATCH] samd/mphalport: Fix building with USB CDC disabled. This commit fixes the build issues in the SAMD port that arise when explicitly disabling USB CDC support. The console code assumed CDC support is always enabled even if it was disabled in mpconfigport.h. These changes make accessing CDC conditional to that support configuration being enabled. Signed-off-by: Alessandro Gatti --- ports/samd/mphalport.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/samd/mphalport.c b/ports/samd/mphalport.c index 84d05b9185..327ab436a7 100644 --- a/ports/samd/mphalport.c +++ b/ports/samd/mphalport.c @@ -120,7 +120,9 @@ uint64_t mp_hal_ticks_us_64(void) { uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { uintptr_t ret = 0; + #if MICROPY_HW_USB_CDC ret |= mp_usbd_cdc_poll_interfaces(poll_flags); + #endif #if MICROPY_PY_OS_DUPTERM ret |= mp_os_dupterm_poll(poll_flags); #endif @@ -129,8 +131,9 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) { int mp_hal_stdin_rx_chr(void) { for (;;) { - + #if MICROPY_HW_USB_CDC mp_usbd_cdc_poll_interfaces(0); + #endif int c = ringbuf_get(&stdin_ringbuf); if (c != -1) { return c; @@ -149,11 +152,13 @@ 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 MICROPY_HW_USB_CDC mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len); if (cdc_res > 0) { did_write = true; ret = MIN(cdc_res, ret); } + #endif #if MICROPY_PY_OS_DUPTERM int dupterm_res = mp_os_dupterm_tx_strn(str, len); if (dupterm_res >= 0) {