From 7f5d8c4605e9305b7d1dbb100d6704618f8f3b4b Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 23 Nov 2023 09:53:16 +1100 Subject: [PATCH] samd: Enable support for Python USB devices. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/samd/Makefile | 1 + ports/samd/main.c | 3 +++ ports/samd/mpconfigport.h | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 5a7cb9916a..b678cd9828 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -136,6 +136,7 @@ SHARED_SRC_C += \ shared/tinyusb/mp_cdc_common.c \ shared/tinyusb/mp_usbd.c \ shared/tinyusb/mp_usbd_descriptor.c \ + shared/tinyusb/mp_usbd_runtime.c \ ASF4_SRC_C += $(addprefix lib/asf4/$(MCU_SERIES_LOWER)/,\ hal/src/hal_atomic.c \ diff --git a/ports/samd/main.c b/ports/samd/main.c index f051e961ff..9f213f27d4 100644 --- a/ports/samd/main.c +++ b/ports/samd/main.c @@ -93,6 +93,9 @@ void samd_main(void) { pwm_deinit_all(); #endif soft_timer_deinit(); + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + mp_usbd_deinit(); + #endif gc_sweep_all(); #if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART sercom_deinit_all(); diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 28a99333d3..0b47500bf7 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -63,8 +63,13 @@ #ifndef MICROPY_HW_USB_DESC_STR_MAX #define MICROPY_HW_USB_DESC_STR_MAX (32) #endif +// Support machine.USBDevice +#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE +#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) #endif +#endif // MICROPY_HW_ENABLE_USBDEV + #define MICROPY_PY_SYS_PLATFORM "samd" // Extended modules