mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
stm32: Fix init sequence of USB hardware and TinyUSB stack.
This commit fixes the initialization sequence for TinyUSB when enabled on the stm32 port: - Following other ports, `mp_usbd_init()` should be called just after running `boot.py`, to give the user a chance to configure USB. - Hardware initialization (via `pyb_usbd_init()`) should only occur once, the first time TinyUSB is started up. This is achieved by adding a hook to the shared TinyUSB bindings to call `pyb_usbd_init()`, and only do the hardware init if TinyUSB was not already initialized. Also, `pyb_usbd_init()` is renamed `mp_usbd_ll_init()` to make it match with the rest of the stared TinyUSB binding code. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -611,14 +611,9 @@ soft_reset:
|
|||||||
pyb_can_init0();
|
pyb_can_init0();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MICROPY_HW_ENABLE_USB
|
#if MICROPY_HW_STM_USB_STACK && MICROPY_HW_ENABLE_USB
|
||||||
#if MICROPY_HW_TINYUSB_STACK
|
|
||||||
pyb_usbd_init();
|
|
||||||
mp_usbd_init();
|
|
||||||
#else
|
|
||||||
pyb_usb_init0();
|
pyb_usb_init0();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MICROPY_PY_MACHINE_I2S
|
#if MICROPY_PY_MACHINE_I2S
|
||||||
machine_i2s_init0();
|
machine_i2s_init0();
|
||||||
@@ -690,6 +685,10 @@ soft_reset:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_TINYUSB_STACK && MICROPY_HW_ENABLE_USBDEV
|
||||||
|
mp_usbd_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MICROPY_HW_HAS_MMA7660
|
#if MICROPY_HW_HAS_MMA7660
|
||||||
// MMA accel: init and reset
|
// MMA accel: init and reset
|
||||||
accel_init();
|
accel_init();
|
||||||
|
|||||||
@@ -261,6 +261,7 @@
|
|||||||
#if MICROPY_HW_TINYUSB_STACK
|
#if MICROPY_HW_TINYUSB_STACK
|
||||||
#ifndef MICROPY_HW_ENABLE_USBDEV
|
#ifndef MICROPY_HW_ENABLE_USBDEV
|
||||||
#define MICROPY_HW_ENABLE_USBDEV (1)
|
#define MICROPY_HW_ENABLE_USBDEV (1)
|
||||||
|
#define MICROPY_HW_TINYUSB_LL_INIT mp_usbd_ll_init
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MICROPY_HW_USB_CDC
|
#ifndef MICROPY_HW_USB_CDC
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// We use the ST Cube HAL library for most hardware peripherals
|
// We use the ST Cube HAL library for most hardware peripherals
|
||||||
#include STM32_HAL_H
|
#include STM32_HAL_H
|
||||||
#include "pin.h"
|
#include "pin.h"
|
||||||
|
#include "usbd_conf.h"
|
||||||
#include "py/ringbuf.h"
|
#include "py/ringbuf.h"
|
||||||
#include "shared/runtime/interrupt_char.h"
|
#include "shared/runtime/interrupt_char.h"
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
|
#include "shared/tinyusb/mp_usbd.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
@@ -334,7 +335,12 @@ static void mp_usbd_ll_init_hs(void) {
|
|||||||
|
|
||||||
#if MICROPY_HW_TINYUSB_STACK
|
#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
|
#if MICROPY_HW_USB_FS
|
||||||
mp_usbd_ll_init_fs();
|
mp_usbd_ll_init_fs();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
#define USBD_HS_NUM_FIFO (1 + USBD_HS_NUM_TX_FIFO)
|
#define USBD_HS_NUM_FIFO (1 + USBD_HS_NUM_TX_FIFO)
|
||||||
|
|
||||||
#if MICROPY_HW_TINYUSB_STACK
|
#if MICROPY_HW_TINYUSB_STACK
|
||||||
void pyb_usbd_init(void);
|
void mp_usbd_ll_init(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_STM32_USBD_CONF_H
|
#endif // MICROPY_INCLUDED_STM32_USBD_CONF_H
|
||||||
|
|||||||
Reference in New Issue
Block a user