Skip to content

Commit 231665c

Browse files
committed
ports/stm32/factoryreset: Add TinyUSB-specific boot.py examples.
The default boot.py template now conditionally includes different USB configuration examples based on whether TinyUSB or the legacy USB stack is enabled at build time. For TinyUSB builds (MICROPY_HW_TINYUSB_STACK=1), the template shows the modern machine.USBDevice() API with examples for CDC, MSC, and NCM (network) drivers. For legacy USB builds, it continues to show the existing pyb.usb_mode() examples. This ensures users see the correct USB API for their board when formatting a new filesystem. Signed-off-by: Andrew Leech <[email protected]>
1 parent 53c80ee commit 231665c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ports/stm32/factoryreset.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ static const char fresh_boot_py[] =
4444
"import pyb\r\n"
4545
"#pyb.main('main.py') # main script to run after this one\r\n"
4646
#if MICROPY_HW_ENABLE_USB
47+
#if MICROPY_HW_TINYUSB_STACK
48+
"#usb = machine.USBDevice()\r\n"
49+
"#usb.builtin_driver = usb.BUILTIN_CDC | usb.BUILTIN_MSC # serial and storage\r\n"
50+
"#usb.active(True)\r\n"
51+
#if MICROPY_HW_NETWORK_USBNET
52+
"#usb.builtin_driver = usb.BUILTIN_CDC | usb.BUILTIN_NCM # serial and network\r\n"
53+
#endif
54+
#else
4755
"#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device\r\n"
4856
"#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse\r\n"
4957
#endif
58+
#endif
5059
#if MICROPY_PY_NETWORK
5160
"#import network\r\n"
5261
"#network.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU or XX for worldwide\r\n"

0 commit comments

Comments
 (0)