ports: On cold boot, enable USB after boot.py completes.

For mimxrt, nrf, renesas-ra, rp2 and samd ports, this commit implements
similar behaviour to the stm32 port, where USB is only brought up after
boot.py completes execution.

Currently this doesn't add any useful functionality (and may break
workflows that depend on USB-CDC being live in boot.py), however it's a
precondition for more usable workflows with USB devices defined in
Python (allows setting up USB interfaces in boot.py before the device
enumerates for the first time).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
Angus Gratton
2024-01-18 08:52:16 +11:00
committed by Damien George
parent 5d83bbca60
commit 00ba6aaae4
8 changed files with 38 additions and 21 deletions

View File

@@ -36,6 +36,7 @@
#include "shared/readline/readline.h"
#include "shared/runtime/pyexec.h"
#include "shared/runtime/softtimer.h"
#include "shared/tinyusb/mp_usbd.h"
#include "lib/oofatfs/ff.h"
#include "lib/littlefs/lfs1.h"
#include "lib/littlefs/lfs1_util.h"
@@ -63,7 +64,6 @@
#include "usrsw.h"
#include "rtc.h"
#include "storage.h"
#include "tusb.h"
#if MICROPY_PY_LWIP
#include "lwip/init.h"
#include "lwip/apps/mdns.h"
@@ -270,10 +270,6 @@ int main(void) {
state.reset_mode = 1;
state.log_soft_reset = false;
#if MICROPY_HW_ENABLE_USBDEV
tusb_init();
#endif
#if MICROPY_PY_BLUETOOTH
mp_bluetooth_hci_init();
#endif
@@ -366,14 +362,20 @@ soft_reset:
#endif
// Run boot.py (or whatever else a board configures at this stage).
if (MICROPY_BOARD_RUN_BOOT_PY(&state) == BOARDCTRL_GOTO_SOFT_RESET_EXIT) {
goto soft_reset_exit;
}
int boot_res = MICROPY_BOARD_RUN_BOOT_PY(&state);
// Now we initialise sub-systems that need configuration from boot.py,
// or whose initialisation can be safely deferred until after running
// boot.py.
#if MICROPY_HW_ENABLE_USBDEV
mp_usbd_init();
#endif
if (boot_res == BOARDCTRL_GOTO_SOFT_RESET_EXIT) {
goto soft_reset_exit;
}
// At this point everything is fully configured and initialised.
// Run main.py (or whatever else a board configures at this stage).