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

@@ -29,7 +29,6 @@
#if MICROPY_HW_USB_CDC
#include "tusb.h"
#include "nrfx.h"
#include "nrfx_power.h"
#include "nrfx_uart.h"
@@ -37,6 +36,7 @@
#include "py/stream.h"
#include "py/runtime.h"
#include "shared/runtime/interrupt_char.h"
#include "shared/tinyusb/mp_usbd.h"
#ifdef BLUETOOTH_SD
#include "nrf_sdm.h"
@@ -186,7 +186,7 @@ int usb_cdc_init(void)
tx_ringbuf.iget = 0;
tx_ringbuf.iput = 0;
tusb_init();
mp_usbd_init();
return 0;
}

View File

@@ -261,13 +261,15 @@ soft_reset:
led_state(1, 0);
#if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN
ret = pyexec_file_if_exists("boot.py");
#endif
#if MICROPY_HW_USB_CDC
usb_cdc_init();
#endif
#if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN
// run boot.py and main.py if they exist.
ret = pyexec_file_if_exists("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) {
pyexec_file_if_exists("main.py");
}