Skip to content

Commit 6dc29dd

Browse files
committed
Add CDC command to trigger bootloader mode when enabled.
Add CDC RX callback that triggers bootloader when receiving "flash" command.
1 parent e317f16 commit 6dc29dd

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(VERSION_MINOR 73)
77

88
## Release Type Selection
99
option(DH_DEBUG "Build a debug version" OFF)
10+
option(DH_DEBUG_CDC_FLASH "Enable CDC command to trigger bootloader mode" OFF)
1011

1112
## Hardware Configuration
1213
set(DP_PIN_DEFAULT 14 CACHE STRING "Default USB D+ Pin Number")
@@ -120,6 +121,10 @@ target_compile_definitions(${binary}
120121
if (DH_DEBUG)
121122
add_definitions(-DDH_DEBUG)
122123
endif()
124+
125+
if (DH_DEBUG_CDC_FLASH)
126+
add_definitions(-DDH_DEBUG_CDC_FLASH)
127+
endif()
123128

124129
target_include_directories(${binary} PUBLIC ${COMMON_INCLUDES})
125130
target_link_libraries(${binary} PUBLIC ${COMMON_LINK_LIBRARIES})

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ _Note_ - This is not an actual generic USB drive, you can't use it to copy files
9898

9999
**Option 2** - Using the ROM bootloader - hold the on-board button while connecting each Pico and copy the uf2 to the flash drive that appears. Images later than 0.6 support holding the button without having to fiddle around the power supply, but the "hold button while plugging" should always work, regardless of device state.
100100

101+
**Option 3** - CDC Flash Command (Debug builds only) - If the firmware was built with `DH_DEBUG_CDC_FLASH=ON`, you can trigger bootloader mode via CDC serial command:
102+
```shell
103+
echo -n 'flash' > /dev/tty.usbmodem11104
104+
```
105+
This immediately resets the device into bootloader mode where it appears as "RPI-RP2" drive. This feature is intended for development workflows.
106+
101107
## Misc features
102108

103109
### Mouse slowdown

src/usb.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ void tud_umount_cb(void) {
9393
global_state.tud_connected = false;
9494
}
9595

96+
#ifdef DH_DEBUG_CDC_FLASH
97+
void tud_cdc_rx_cb(uint8_t itf) {
98+
char buf[64];
99+
uint32_t count = tud_cdc_n_available(itf);
100+
101+
if (count == 0)
102+
return;
103+
104+
if (count > sizeof(buf))
105+
count = sizeof(buf);
106+
107+
tud_cdc_n_read(itf, buf, count);
108+
109+
if (count >= 5 && memcmp(buf, "flash", 5) == 0) {
110+
reset_usb_boot(0, 0);
111+
}
112+
}
113+
#endif
114+
96115
/* ================================================== *
97116
* =============== USB HOST Section =============== *
98117
* ================================================== */

0 commit comments

Comments
 (0)