|
| 1 | +# Uploading firmware through Daisy Bootloader |
| 2 | + |
| 3 | +The chip on board has quite limited flash capacity of 128 kB. To fit larger |
| 4 | +firmware on Daisy, [the Daisy Bootloader exists](https://electro-smith.github.io/libDaisy/md_doc_2md_2__a7___getting-_started-_daisy-_bootloader.html). |
| 5 | +Check the documentation to learn about the different bootloader modes and the |
| 6 | +methods for uploading firmware through it. |
| 7 | + |
| 8 | +In this directory, you'll find an example project that uses the bootloader. |
| 9 | +The program is copied via DFU to the onboard 8 MB flash storage. When the board |
| 10 | +starts, the bootloader will then copy the program to SDRAM for faster execution. |
| 11 | + |
| 12 | +This example is made for Daisy Patch SM and assumes you're already familiar with |
| 13 | +this crate. If you want to flash a different board, update the `Cargo.toml` |
| 14 | +accordingly. |
| 15 | + |
| 16 | +## Flashing the example |
| 17 | + |
| 18 | +First, install the bootloader on the board. You can use <https://flash.daisy.audio/>, |
| 19 | +go to the "Bootloader" tab, select version "v6.2", and flash it. |
| 20 | +Alternatively, you can use the libDaisy project and its Makefile. |
| 21 | + |
| 22 | +First, install the bootloader on the board. You can use <https://flash.daisy.audio/>, |
| 23 | +go to the "Bootloader" tab, select version "v6.2", and flash it. Alternatively |
| 24 | +you can use the [libDaisy](https://github.com/electro-smith/libDaisy/tree/master) |
| 25 | +project and its `Makefile`. |
| 26 | + |
| 27 | +Once the bootloader is installed, restart the module and press the BOOT button |
| 28 | +within the first 2 seconds after startup. The onboard LED should start pulsing, |
| 29 | +indicating the bootloader is active and waiting. |
| 30 | + |
| 31 | +Now build the example firmware: |
| 32 | + |
| 33 | +```sh |
| 34 | +cargo objcopy --release -- -O binary target/program.bin |
| 35 | +``` |
| 36 | + |
| 37 | +After building, use `dfu-util` to upload the program. Note the `-s` parameter, |
| 38 | +which now points to the beginning of the writable onboard flash, not the |
| 39 | +internal flash: |
| 40 | + |
| 41 | +After that, it is just a matter of using `dfu-util` to upload the program. |
| 42 | +Note the `-s` parameter which now points at the beginning of writeable |
| 43 | +on-board flash, instead of the internal flash: |
| 44 | + |
| 45 | +```sh |
| 46 | +dfu-util -a 0 -s 0x90040000:leave -D target/program.bin -d ,0483:df11 |
| 47 | +``` |
| 48 | + |
| 49 | +The program should now be uploaded, and the onboard LED should be blinking. |
| 50 | + |
| 51 | +## Attaching to logs |
| 52 | + |
| 53 | +The bootloader doesn't allow flashing the program using |
| 54 | +[`probe-rs`](https://probe.rs/), but you can still attach to logs using |
| 55 | +[cargo-embed](https://probe.rs/docs/tools/cargo-embed/). |
| 56 | + |
| 57 | +Build the program including INFO-level logs, flash it, and attach to |
| 58 | +it using an ST-Link programmer: |
| 59 | + |
| 60 | +```sh |
| 61 | +DEFMT_LOG=info cargo objcopy --release -- -O binary target/program.bin |
| 62 | +dfu-util -a 0 -s 0x90040000:leave -D target/program.bin -d ,0483:df11 |
| 63 | +DEFMT_LOG=info cargo-embed --release |
| 64 | +``` |
| 65 | + |
| 66 | +You should now see the log output. |
| 67 | + |
| 68 | +## What makes this work |
| 69 | + |
| 70 | +### `Cargo.toml` |
| 71 | + |
| 72 | +The `Cargo.toml` config is standard, except for the `set-vtor` feature flag |
| 73 | +that must be enabled on `cortex-m-rt`. |
| 74 | + |
| 75 | +### `memory.x` |
| 76 | + |
| 77 | +This file is different from the standard `memory.x`. The main difference is the |
| 78 | +region alias replacing `FLASH` of the default link file with `SRAM`. |
| 79 | +The rest of the layout is also slightly adjusted to meet the bootloader’s |
| 80 | +requirements. |
| 81 | + |
| 82 | +### `Embed.toml` |
| 83 | + |
| 84 | +This file is optional. It makes `cargo-embed` only read logs without trying to |
| 85 | +flash the firmware. |
| 86 | + |
| 87 | +## Caveats |
| 88 | + |
| 89 | +### SRAM |
| 90 | + |
| 91 | +Since the program is uploaded to SRAM and runs from there, your program can't |
| 92 | +use that memory. Other memory regions are still available, but keep in mind |
| 93 | +they are either smaller or slower. |
| 94 | + |
| 95 | +### Reserved flash |
| 96 | + |
| 97 | +Part of the onboard flash is used to store the firmware. It’s still possible |
| 98 | +for the firmware to use this flash, but care must be taken when writing to it. |
| 99 | +The first four 64 kB blocks are reserved, followed by the firmware itself. |
| 100 | +When using the bootloader in SRAM mode (as in this example), the firmware can |
| 101 | +take up to 480 kB, so the first 736 kB, or 184 sectors, are occupied and should |
| 102 | +not be written to. |
| 103 | + |
| 104 | +## Credits |
| 105 | + |
| 106 | +Kudos to `eulerdisk` for [explaining](https://github.com/rust-embedded/cortex-m/issues/599#issuecomment-2956003568) |
| 107 | +how to adjust the linker to work with the bootloader. Thanks to `Corvus Prudens` |
| 108 | +and `mito3705` from [Daisy Discord](https://discord.com/channels/1037767234803740694/1039305128886403072) |
| 109 | +who shared valuable input on using the Daisy Bootloader with Rust. |
0 commit comments