diff options
| -rw-r--r-- | ports/stm32/main.c | 11 | ||||
| -rw-r--r-- | ports/stm32/mpconfigboard_common.h | 1 | ||||
| -rw-r--r-- | ports/stm32/mphalport.h | 1 | ||||
| -rw-r--r-- | ports/stm32/usbd_conf.c | 8 | ||||
| -rw-r--r-- | ports/stm32/usbd_conf.h | 2 |
5 files changed, 15 insertions, 8 deletions
diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 6f7413694..8085a5e25 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -611,14 +611,9 @@ soft_reset: pyb_can_init0(); #endif - #if MICROPY_HW_ENABLE_USB - #if MICROPY_HW_TINYUSB_STACK - pyb_usbd_init(); - mp_usbd_init(); - #else + #if MICROPY_HW_STM_USB_STACK && MICROPY_HW_ENABLE_USB pyb_usb_init0(); #endif - #endif #if MICROPY_PY_MACHINE_I2S machine_i2s_init0(); @@ -690,6 +685,10 @@ soft_reset: } #endif + #if MICROPY_HW_TINYUSB_STACK && MICROPY_HW_ENABLE_USBDEV + mp_usbd_init(); + #endif + #if MICROPY_HW_HAS_MMA7660 // MMA accel: init and reset accel_init(); diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h index 1ce42055d..e21f474d7 100644 --- a/ports/stm32/mpconfigboard_common.h +++ b/ports/stm32/mpconfigboard_common.h @@ -261,6 +261,7 @@ #if MICROPY_HW_TINYUSB_STACK #ifndef MICROPY_HW_ENABLE_USBDEV #define MICROPY_HW_ENABLE_USBDEV (1) +#define MICROPY_HW_TINYUSB_LL_INIT mp_usbd_ll_init #endif #ifndef MICROPY_HW_USB_CDC diff --git a/ports/stm32/mphalport.h b/ports/stm32/mphalport.h index 098a848fb..50aa45697 100644 --- a/ports/stm32/mphalport.h +++ b/ports/stm32/mphalport.h @@ -1,6 +1,7 @@ // We use the ST Cube HAL library for most hardware peripherals #include STM32_HAL_H #include "pin.h" +#include "usbd_conf.h" #include "py/ringbuf.h" #include "shared/runtime/interrupt_char.h" diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index be56b2202..e5ac9311d 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -32,6 +32,7 @@ #include "usbd_core.h" #include "py/obj.h" #include "py/mphal.h" +#include "shared/tinyusb/mp_usbd.h" #include "irq.h" #include "usb.h" @@ -334,7 +335,12 @@ static void mp_usbd_ll_init_hs(void) { #if MICROPY_HW_TINYUSB_STACK -void pyb_usbd_init(void) { +void mp_usbd_ll_init(void) { + // Only initialize the USB hardware once. + if (tusb_inited()) { + return; + } + #if MICROPY_HW_USB_FS mp_usbd_ll_init_fs(); #endif diff --git a/ports/stm32/usbd_conf.h b/ports/stm32/usbd_conf.h index cb0457982..5829d6870 100644 --- a/ports/stm32/usbd_conf.h +++ b/ports/stm32/usbd_conf.h @@ -65,7 +65,7 @@ #define USBD_HS_NUM_FIFO (1 + USBD_HS_NUM_TX_FIFO) #if MICROPY_HW_TINYUSB_STACK -void pyb_usbd_init(void); +void mp_usbd_ll_init(void); #endif #endif // MICROPY_INCLUDED_STM32_USBD_CONF_H |
