From 3d018f5abbafad9a059aaa92fef518567b9e83ea Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Fri, 18 Jul 2025 16:36:07 +0200 Subject: [PATCH 1/5] shared/tinyusb: Fix build errors with CDC support disabled. This commit makes possible building MicroPython with USB CDC support disabled. The original code does support such a configuration but missed a few spots where build errors would arise. These changes fix the remaining issues, fixing also warnings caused by the changes needed to make the build succeed. Signed-off-by: Alessandro Gatti --- shared/tinyusb/mp_usbd.h | 3 +++ shared/tinyusb/mp_usbd_runtime.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/shared/tinyusb/mp_usbd.h b/shared/tinyusb/mp_usbd.h index 5c8f2a6095f30..866ef8503a580 100644 --- a/shared/tinyusb/mp_usbd.h +++ b/shared/tinyusb/mp_usbd.h @@ -38,13 +38,16 @@ #ifndef NO_QSTR #include "tusb.h" #include "device/dcd.h" +#include "class/cdc/cdc_device.h" #endif // Initialise TinyUSB device. static inline void mp_usbd_init_tud(void) { tusb_init(); + #if MICROPY_HW_USB_CDC tud_cdc_configure_fifo_t cfg = { .rx_persistent = 0, .tx_persistent = 1 }; tud_cdc_configure_fifo(&cfg); + #endif } // Run the TinyUSB device task diff --git a/shared/tinyusb/mp_usbd_runtime.c b/shared/tinyusb/mp_usbd_runtime.c index a1eebeebd2fcd..72e011732d400 100644 --- a/shared/tinyusb/mp_usbd_runtime.c +++ b/shared/tinyusb/mp_usbd_runtime.c @@ -267,9 +267,11 @@ static uint16_t runtime_dev_open(uint8_t rhport, tusb_desc_interface_t const *it } // If TinyUSB built-in drivers are enabled, don't claim any interface in the built-in range + #if USBD_ITF_BUILTIN_MAX > 0 if (mp_usb_device_builtin_enabled(usbd) && itf_desc->bInterfaceNumber < USBD_ITF_BUILTIN_MAX) { return 0; } + #endif // Determine the total descriptor length of the interface(s) we are going to claim uint8_t assoc_itf_count = _runtime_dev_count_itfs(itf_desc); From f6769dec8369155bd60f3ea8573cd0b4dbf4be1d Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Fri, 25 Jul 2025 11:49:23 +0200 Subject: [PATCH 2/5] rp2/mphalport: Fix building with USB CDC disabled. This commit fixes the linking issues in the RP2 port that arise when explicitly disabling USB CDC support. The console input ringbuffer needs to be made available if dupterm support is enabled, and the console character input function would always attempt to read from the input ringbuffer even if CDC support is disabled and the console isn't bound to any UART. Signed-off-by: Alessandro Gatti --- ports/rp2/mphalport.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index b581b3b59f95d..afafa9d6935af 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -50,7 +50,7 @@ static uint64_t time_us_64_offset_from_epoch; #endif -#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC +#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC || MICROPY_PY_OS_DUPTERM_NOTIFY #ifndef MICROPY_HW_STDIN_BUFFER_LEN #define MICROPY_HW_STDIN_BUFFER_LEN 512 @@ -83,11 +83,12 @@ int mp_hal_stdin_rx_chr(void) { #if MICROPY_HW_USB_CDC mp_usbd_cdc_poll_interfaces(0); #endif - + #if MICROPY_HW_ENABLE_UART_REPL || MICROPY_PY_OS_DUPTERM_NOTIFY int c = ringbuf_get(&stdin_ringbuf); if (c != -1) { return c; } + #endif #if MICROPY_PY_OS_DUPTERM int dupterm_c = mp_os_dupterm_rx_chr(); if (dupterm_c >= 0) { From 9e23e77287454a830605c5b46597074923b02949 Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Fri, 25 Jul 2025 12:15:01 +0200 Subject: [PATCH 3/5] mimxrt/mphalport: Fix building with USB CDC disabled. This commit fixes the build issues in the MIMXRT 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/mimxrt/mphalport.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ports/mimxrt/mphalport.c b/ports/mimxrt/mphalport.c index be5abd95bec54..c3802be30f5d7 100644 --- a/ports/mimxrt/mphalport.c +++ b/ports/mimxrt/mphalport.c @@ -47,7 +47,9 @@ ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0, 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 @@ -56,7 +58,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; @@ -74,11 +78,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) { From b136a721a908bf49f41b8b79ef58329d7a0a949a Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Fri, 25 Jul 2025 12:42:09 +0200 Subject: [PATCH 4/5] 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 84d05b9185afe..327ab436a7126 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) { From 40306666da4768f52aedb10718f4cd72bbd538bb Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Fri, 25 Jul 2025 13:54:41 +0200 Subject: [PATCH 5/5] esp32/usb: Fix building with USB CDC disabled. This commit fixes the build issues in the ESP32 port that arise when explicitly disabling USB CDC support. The USB support code gated the USB serial number retrieval behind the USB CDC support definition, even though all USB devices must be able to be queried for their serial number. Signed-off-by: Alessandro Gatti --- ports/esp32/usb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c index 3ce3d045810af..0d4c68ad31002 100644 --- a/ports/esp32/usb.c +++ b/ports/esp32/usb.c @@ -28,13 +28,16 @@ #include "py/mphal.h" #include "usb.h" -#if MICROPY_HW_USB_CDC -#include "esp_rom_gpio.h" +#if MICROPY_HW_ENABLE_USBDEV + #include "esp_mac.h" -#include "esp_private/usb_phy.h" #include "shared/tinyusb/mp_usbd.h" +#if MICROPY_HW_USB_CDC +#include "esp_rom_gpio.h" +#include "esp_private/usb_phy.h" + static usb_phy_handle_t phy_hdl; @@ -69,6 +72,8 @@ void usb_usj_mode(void) { } #endif +#endif // MICROPY_HW_USB_CDC + void mp_usbd_port_get_serial_number(char *serial_buf) { // use factory default MAC as serial ID uint8_t mac[8]; @@ -77,4 +82,4 @@ void mp_usbd_port_get_serial_number(char *serial_buf) { mp_usbd_hex_str(serial_buf, mac, sizeof(mac)); } -#endif // MICROPY_HW_USB_CDC +#endif // MICROPY_HW_ENABLE_USBDEV pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy