diff options
| author | Gerzain Mata <[email protected]> | 2025-07-29 01:19:22 -0700 |
|---|---|---|
| committer | Gerzain Mata <[email protected]> | 2025-07-29 08:11:49 -0700 |
| commit | 1b4ea556c0e99622a18c48126cfc6899ffa102b1 (patch) | |
| tree | 158edb71711a270b00e634bbab55194cf35c4935 /examples/boot/bootloader/stm32wba-dfu/README.md | |
| parent | 7cf7f8b0ef344cdbef76703d4d700fbfddda23c9 (diff) | |
STM32WBA usb-dfu example
- Added sample application
- Added sample bootloader
Removed trace import
Diffstat (limited to 'examples/boot/bootloader/stm32wba-dfu/README.md')
| -rw-r--r-- | examples/boot/bootloader/stm32wba-dfu/README.md | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/boot/bootloader/stm32wba-dfu/README.md b/examples/boot/bootloader/stm32wba-dfu/README.md new file mode 100644 index 000000000..d50164255 --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/README.md | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | # Bootloader for STM32 | ||
| 2 | |||
| 3 | This bootloader implementation uses `embassy-boot` and `embassy-usb-dfu` to manage firmware updates and interact with the flash memory on STM32WB55 devices. | ||
| 4 | |||
| 5 | ## Prerequisites | ||
| 6 | |||
| 7 | - Rust toolchain with `cargo` installed | ||
| 8 | - `cargo-flash` for flashing the bootloader | ||
| 9 | - `dfu-util` for firmware updates | ||
| 10 | - `cargo-binutils` for binary generation | ||
| 11 | |||
| 12 | ## Usage | ||
| 13 | |||
| 14 | ### 1. Flash the Bootloader | ||
| 15 | |||
| 16 | First, flash the bootloader to your device: | ||
| 17 | |||
| 18 | ``` | ||
| 19 | cargo flash --features embassy-stm32/stm32wba65ri --release --chip STM32WBA65RI | ||
| 20 | ``` | ||
| 21 | |||
| 22 | ### 2. Build and Flash Application | ||
| 23 | |||
| 24 | Generate your application binary and flash it using DFU: | ||
| 25 | |||
| 26 | ``` | ||
| 27 | cargo objcopy --release -- -O binary fw.bin | ||
| 28 | dfu-util -d c0de:cafe -w -D fw.bin | ||
| 29 | ``` | ||
| 30 | |||
| 31 | ### 3. Sign Updates Before Flashing (Optional) | ||
| 32 | |||
| 33 | Currently, embassy-usb-dfu only supports a limited implementation of the generic support for ed25519-based update verfication in embassy-boot. This implementation assumes that a signature is simply concatenated to the end of an update binary. For more details, please see https://embassy.dev/book/#_verification and/or refer to the documentation for embassy-boot-dfu. | ||
| 34 | |||
| 35 | To sign (and then verify) application updates, you will first need to generate a key pair: | ||
| 36 | |||
| 37 | ``` | ||
| 38 | signify-openbsd -G -n -p secrets/key.pub -s secrets/key.sec | ||
| 39 | tail -n1 secrets/key.pub | base64 -d -i - | dd ibs=10 skip=1 > secrets/key.pub.short | ||
| 40 | ``` | ||
| 41 | |||
| 42 | Then you will need to sign all you binaries with the private key: | ||
| 43 | |||
| 44 | ``` | ||
| 45 | cargo objcopy --release -- -O binary fw.bin | ||
| 46 | shasum -a 512 -b fw.bin | head -c128 | xxd -p -r > target/fw-hash.txt | ||
| 47 | signify-openbsd -S -s secrets/key.sec -m target/fw-hash.txt -x target/fw-hash.sig | ||
| 48 | cp fw.bin fw-signed.bin | ||
| 49 | tail -n1 target/fw-hash.sig | base64 -d -i - | dd ibs=10 skip=1 >> fw-signed.bin | ||
| 50 | dfu-util -d c0de:cafe -w -D fw-signed.bin | ||
| 51 | ``` | ||
| 52 | |||
| 53 | Finally, as shown in this example with the `verify` feature flag enabled, you then need to embed the public key into your bootloader so that it can verify update signatures. | ||
| 54 | |||
| 55 | N.B. Please note that the exact steps above are NOT a good example of how to manage your keys securely. In a production environment, you should take great care to ensure that (at least the private key) is protected and not leaked into your version control system. | ||
| 56 | |||
| 57 | ## Troubleshooting | ||
| 58 | |||
| 59 | - Make sure your device is in DFU mode before flashing | ||
| 60 | - Verify the USB VID:PID matches your device (c0de:cafe) | ||
| 61 | - Check USB connections if the device is not detected | ||
| 62 | - Make sure the transfer size option of `dfu-util` matches the bootloader configuration. By default, `dfu-util` will use the transfer size reported by the device, but you can override it with the `-t` option if needed. | ||
| 63 | - Make sure `control_buf` size is larger than or equal to the `usb_dfu` `BLOCK_SIZE` parameter (in this example, both are set to 4096 bytes). | ||
