Skip to content

Commit 0c23f04

Browse files
committed
feat(dfu): improve config
1 parent d220256 commit 0c23f04

2 files changed

Lines changed: 43 additions & 22 deletions

File tree

docs/docs/main/docs/configuration/chip_config.mdx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ flash_size = 2097152
2020
# (Optional) Flash page size in bytes (4096 for RP2040).
2121
page_size = 4096
2222

23-
# (Optional) DFU activity LED pin, e.g. "PIN_25".
24-
led = "PIN_25"
23+
# (Optional) DFU activity LED pin, default "PIN_25".
24+
led = "PIN_25"
25+
led = "none" to omit DFU LED
2526

26-
# (Optional) Unlock keys for dfu_lock (physical matrix positions). Only works with dfu_lock feature.
27+
# (Optional) Unlock keys for dfu_lock (physical matrix positions). Only works with dfu_lock feature enabled.
2728
# Format: [[row, col], [row, col], ...]
2829
unlock_keys = [[0, 0], [1, 1]]
2930

@@ -39,6 +40,7 @@ unlock_keys = [[0, 0], [1, 1]]
3940

4041
```rust title="main.rs"
4142
// Partition layout (must match bootloader's memory.x)
43+
// only change FLASH_SIZE when using bootymcbootface, the rest ist automatically calculated.
4244
const FLASH_SIZE: u32 = 2 * 1024 * 1024;
4345
const PAGE_SIZE: u32 = 4096;
4446
const HALF_FLASH: u32 = FLASH_SIZE / 4;
@@ -50,9 +52,18 @@ const STORAGE_END: u32 = FLASH_SIZE - 32 * PAGE_SIZE;
5052

5153
// Initialize DFU flash + partitions (returns storage partition)
5254
let flash = async_flash_wrapper(rmk::dfu::init_flash(
53-
p.FLASH,
54-
0, // storage_start
55-
STORAGE_END, // storage_end
55+
p.FLASH,// Optional: DFU lock with physical key unlock. Requires the `dfu_lock` Cargo feature.
56+
let unlock_keys: &[(u8, u8)] = &[(0, 0), (1, 1)];
57+
let dfu_lock = ::rmk::dfu::DfuLock::new(&DFU_UNLOCK_KEYS);
58+
// Then run the dfu_lock in run_all!()
59+
// ...
60+
run_all!(
61+
// other processors
62+
dfu_lock,
63+
)
64+
65+
0, // storage_start, this is the address inside the storage partition of the flash, not the actual flash address
66+
STORAGE_END,
5667
STATE_OFFSET,
5768
STATE_SIZE,
5869
DFU_OFFSET,
@@ -66,8 +77,14 @@ rmk::dfu::set_led(Some(Output::new(p.PIN_25, Level::Low)));
6677
rmk::dfu::mark_booted();
6778

6879
// Optional: DFU lock with physical key unlock. Requires the `dfu_lock` Cargo feature.
69-
// Unlock is handled automatically by the #[rmk_keyboard] macro — no manual loop needed.
70-
// let unlock_keys: &[(u8, u8)] = &[(0, 0), (1, 1)];
80+
let unlock_keys: &[(u8, u8)] = &[(0, 0), (1, 1)];
81+
let mut dfu_lock = ::rmk::dfu::DfuLock::new(unlock_keys, &keymap);
82+
// Then add dfu_lock in run_all!()
83+
// ...
84+
run_all!(
85+
// other processors ...
86+
dfu_lock,
87+
)
7188
```
7289

7390
</Tab>
@@ -85,6 +102,8 @@ The bootloader divides flash into regions. The defaults follow the [bootymcbootf
85102
| DFU download | follows active | `flash_size / 4 + page_size` |
86103
| Storage | follows DFU | rest of flash |
87104

105+
The DFU partition size follows embassy-boot guidelines, the additional page is used for status information during flashing.
106+
88107
All `[dfu]` fields are optional. The partition values are auto-calculated from `flash_size` and `page_size` using the bootymcbootface formula. If you supply any of `state_offset`, `state_size`, `dfu_offset`, or `dfu_size` directly, auto-calculation is disabled and your values are used as-is.
89108

90109
Your `memory.x` must match this partition layout — see the [flashing guide](../user_guide/flash_firmware/use_embassy_boot.mdx) for details.

docs/docs/main/docs/user_guide/flash_firmware/use_embassy_boot.mdx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You need the [bootymcbootface](https://codeberg.org/Schievel/bootymcbootface/) b
2121
- `bootymcbootface_8MB.uf2` – for 8 MB flash
2222
- `bootymcbootface_16MB.uf2` – for 16 MB flash
2323

24-
The **2 MB version works with larger flash chips too** (e.g. 4 MB or 8 MB). It only uses the first 2 MB of flash, the rest remains unused. If you want to use the full flash, pick the matching variant.
24+
The **2 MB version works with larger flash chips too** (e.g. 4 MB or 8 MB). It only uses the first 2 MB of flash, the rest remains unused. Since RMK is not so big, a flash of 2MB is sufficient most of the times. (But keep in mind when using embassy-boot, the flash is partitioned into ACTIVE and DFU and the firmware has to fit into the ACTIVE partition. Which is only 512K on a 2MB RP2040 then.) If you want to use the full flash, pick the matching variant.
2525

2626
### Compile RMK with DFU support
2727

@@ -31,8 +31,8 @@ When using `rmkit init`, you will be asked whether you want to use embassy-boot
3131

3232
If configuring manually, ensure:
3333

34-
- `Cargo.toml` uses the `dfu_rp` feature instead of `rp2040`
35-
- `keyboard.toml` has `[storage]` and `[dfu]` sections
34+
- `Cargo.toml` uses the `dfu_rp` feature
35+
- `keyboard.toml` has `[dfu]` section
3636
- The flash partitioning in `memory.x` matches your bootloader and flash size (see `rmk/examples/use_rust/rp2040_embassy_boot/`)
3737

3838
**Important:** The bootymcbootface version and the RMK compilation must use the **same flash size**. Example: bootymcbootface 2 MB → RMK with 2 MB flash configuration.
@@ -43,6 +43,10 @@ You can still flash firmware via UF2 or probe-rs — as long as it was built wit
4343
If you flash a RMK firmware built with a **normal** `memory.x` (without embassy-boot), it will start at flash address `0x0` and **overwrite bootymcbootface**.
4444
:::
4545

46+
::: tip
47+
the embassy-boot bootloader and RMK will never overwrite the RP2040’s uf2 bootloader. It exists in ROM and can not be overwritten
48+
:::
49+
4650
## Step-by-step guide
4751

4852
### First-time flashing
@@ -57,13 +61,11 @@ The first time, you need to flash the bootloader first, then RMK.
5761
3. Copy the matching `bootymcbootface_<size>.uf2` to the drive
5862
4. The RP2040 reboots – the bootloader is now active
5963

60-
*(If an LED is configured, it will turn on during a DFU transfer and turn off when done.)*
61-
6264
**Method B – via debug probe (probe-rs):**
6365
```shell
64-
probe-rs run --chip RP2040 bootymcbootface_<size>.elf
66+
probe-rs run --chip RP2040 bootymcbootface_<size> (elf)
6567
# or
66-
cargo run --release
68+
cargo run --release // in the bootymcbootface project directory
6769
```
6870
(Make sure your project targets the bootloader binary)
6971

@@ -72,7 +74,7 @@ cargo run --release
7274
Now flash the actual RMK firmware. The bootloader stays in place.
7375

7476
**Method A – via UF2:**
75-
The embassy-boot bootloader also provides a UF2 mode. Put the board into bootloader mode (double-tap reset or BOOTSEL, depending on the board), then copy the RMK firmware `.uf2` file to the drive.
77+
Put the board into bootloader mode (hold BOOTSEL button, plug in USB, release), then copy the RMK firmware `.uf2` file to the appearing `RPI-RP2` drive.
7678

7779
**Method B – via debug probe (probe-rs):**
7880
```shell
@@ -96,7 +98,7 @@ rust-objcopy -O binary target/thumbv6m-none-eabi/release/your-firmware your-firm
9698
```shell
9799
cargo make bin --release
98100
```
99-
(Requires a `Makefile.toml` with a `bin` task — the generated template already includes one.)
101+
(Requires a `Makefile.toml` with a `bin` task — the generated template from `rmkit` already includes one.)
100102

101103
#### Flash via dfu-util
102104

@@ -116,28 +118,28 @@ Find your device's VID:PID via `lsusb` on Linux or Device Manager (under "Univer
116118
- macOS: `brew install dfu-util`
117119
- Windows: Download from [dfu-util.sourceforge.net](https://dfu-util.sourceforge.net/)
118120

119-
`dfu-util` will automatically detect the board — the RMK firmware exposes a DFU USB interface on every boot. No need to press BOOTSEL or trigger a special mode. (With the optional `dfu_lock` feature, DFU downloads start in a locked state and require a physical key press to unlock — see below.)
121+
`dfu-util` will automatically detect the board — the RMK firmware exposes a DFU USB interface at runtime. No need to press BOOTSEL or trigger a special mode. (With the optional `dfu_lock` feature, DFU downloads require a physical key press to unlock — see below.)
120122

121123
#### Unlocking DFU (optional, dfu_lock)
122124

123-
If your firmware was compiled with the `dfu_lock` feature, DFU starts in a **locked** state. To unlock:
125+
If your RMK was compiled with the `dfu_lock` feature, DFU starts in a **locked** state. To unlock:
124126

125127
1. Run `dfu-util -D your-firmware.bin` — the download will be rejected, but this signals the keyboard to open the unlock window
126128
2. The DFU LED turns **solid on** — you have **10 seconds** to press the `unlock_keys` combination configured in `keyboard.toml` (e.g. `[[0, 0], [1, 1]]`)
127129
3. Once the keys are pressed, the LED blinks **"D F U"** in Morse code (`-.. ..-. ..-`) — the DFU lock is released for another **10 seconds**
128-
4. Re-run `dfu-util -D your-firmware.bin` — this time the download proceeds, the LED stays on, and the firmware is updated
130+
4. Re-run `dfu-util -D your-firmware.bin` — this time the download proceeds, the LED flickers, and the firmware is updated
129131
5. After the update completes, the LED turns off and the board reboots
130132

131133
If you don't press the unlock keys within the first 10 seconds, the window closes and the LED turns off. If no DFU download starts within the unlocked 10 seconds, the lock re-engages automatically. In both cases just repeat from step 1.
132134

133135
#### LED behavior during DFU transfer (optional)
134136

135-
If an LED pin is configured in `keyboard.toml` (`[dfu] led = "PIN_25"`):
137+
If an LED pin is configured in `keyboard.toml` (default PIN_25, if not `[dfu] led = "none"`):
136138

137139
| State | LED behavior |
138140
|---|---|---|
139141
| Unlock window open (waiting for keys) | Solid on |
140142
| DFU unlocked (ready for dfu-util) | Blinks Morse "D F U" |
141143
| DFU download started | On |
142-
| Writing data blocks | Toggles on each block |
144+
| Writing data blocks | Toggles on each block (flickers) |
143145
| DFU finished / system reset | Off |

0 commit comments

Comments
 (0)