From 776be79f7bb10b09e795e2ea93bb795a653c9b4c Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 24 Jun 2022 19:56:15 +0200 Subject: Move bootloader main to examples This should remove some confusion around embassy-boot-* being a library vs. a binary. The binary is now an example bootloader instead. --- examples/boot/application/nrf/.cargo/config.toml | 9 ++++ examples/boot/application/nrf/Cargo.toml | 18 +++++++ examples/boot/application/nrf/README.md | 34 +++++++++++++ examples/boot/application/nrf/build.rs | 34 +++++++++++++ examples/boot/application/nrf/memory-bl.x | 18 +++++++ examples/boot/application/nrf/memory.x | 15 ++++++ examples/boot/application/nrf/src/bin/a.rs | 43 ++++++++++++++++ examples/boot/application/nrf/src/bin/b.rs | 23 +++++++++ .../boot/application/stm32f3/.cargo/config.toml | 9 ++++ examples/boot/application/stm32f3/Cargo.toml | 25 ++++++++++ examples/boot/application/stm32f3/README.md | 29 +++++++++++ examples/boot/application/stm32f3/build.rs | 37 ++++++++++++++ examples/boot/application/stm32f3/memory.x | 15 ++++++ examples/boot/application/stm32f3/src/bin/a.rs | 40 +++++++++++++++ examples/boot/application/stm32f3/src/bin/b.rs | 24 +++++++++ .../boot/application/stm32f7/.cargo/config.toml | 9 ++++ examples/boot/application/stm32f7/Cargo.toml | 25 ++++++++++ examples/boot/application/stm32f7/README.md | 29 +++++++++++ examples/boot/application/stm32f7/build.rs | 37 ++++++++++++++ examples/boot/application/stm32f7/flash-boot.sh | 8 +++ examples/boot/application/stm32f7/memory-bl.x | 18 +++++++ examples/boot/application/stm32f7/memory.x | 15 ++++++ examples/boot/application/stm32f7/src/bin/a.rs | 40 +++++++++++++++ examples/boot/application/stm32f7/src/bin/b.rs | 26 ++++++++++ .../boot/application/stm32h7/.cargo/config.toml | 9 ++++ examples/boot/application/stm32h7/Cargo.toml | 25 ++++++++++ examples/boot/application/stm32h7/README.md | 29 +++++++++++ examples/boot/application/stm32h7/build.rs | 37 ++++++++++++++ examples/boot/application/stm32h7/flash-boot.sh | 8 +++ examples/boot/application/stm32h7/memory-bl.x | 18 +++++++ examples/boot/application/stm32h7/memory.x | 15 ++++++ examples/boot/application/stm32h7/src/bin/a.rs | 40 +++++++++++++++ examples/boot/application/stm32h7/src/bin/b.rs | 26 ++++++++++ .../boot/application/stm32l0/.cargo/config.toml | 9 ++++ examples/boot/application/stm32l0/Cargo.toml | 25 ++++++++++ examples/boot/application/stm32l0/README.md | 29 +++++++++++ examples/boot/application/stm32l0/build.rs | 37 ++++++++++++++ examples/boot/application/stm32l0/memory.x | 15 ++++++ examples/boot/application/stm32l0/src/bin/a.rs | 44 ++++++++++++++++ examples/boot/application/stm32l0/src/bin/b.rs | 24 +++++++++ .../boot/application/stm32l1/.cargo/config.toml | 9 ++++ examples/boot/application/stm32l1/Cargo.toml | 25 ++++++++++ examples/boot/application/stm32l1/README.md | 29 +++++++++++ examples/boot/application/stm32l1/build.rs | 37 ++++++++++++++ examples/boot/application/stm32l1/memory.x | 15 ++++++ examples/boot/application/stm32l1/src/bin/a.rs | 44 ++++++++++++++++ examples/boot/application/stm32l1/src/bin/b.rs | 24 +++++++++ .../boot/application/stm32l4/.cargo/config.toml | 9 ++++ examples/boot/application/stm32l4/Cargo.toml | 25 ++++++++++ examples/boot/application/stm32l4/README.md | 29 +++++++++++ examples/boot/application/stm32l4/build.rs | 37 ++++++++++++++ examples/boot/application/stm32l4/memory.x | 15 ++++++ examples/boot/application/stm32l4/src/bin/a.rs | 40 +++++++++++++++ examples/boot/application/stm32l4/src/bin/b.rs | 24 +++++++++ .../boot/application/stm32wl/.cargo/config.toml | 9 ++++ examples/boot/application/stm32wl/Cargo.toml | 25 ++++++++++ examples/boot/application/stm32wl/README.md | 29 +++++++++++ examples/boot/application/stm32wl/build.rs | 37 ++++++++++++++ examples/boot/application/stm32wl/memory.x | 15 ++++++ examples/boot/application/stm32wl/src/bin/a.rs | 43 ++++++++++++++++ examples/boot/application/stm32wl/src/bin/b.rs | 24 +++++++++ examples/boot/bootloader/nrf/.cargo/config.toml | 20 ++++++++ examples/boot/bootloader/nrf/Cargo.toml | 58 ++++++++++++++++++++++ examples/boot/bootloader/nrf/README.md | 11 ++++ examples/boot/bootloader/nrf/build.rs | 37 ++++++++++++++ examples/boot/bootloader/nrf/memory-bm.x | 18 +++++++ examples/boot/bootloader/nrf/memory-s140.x | 31 ++++++++++++ examples/boot/bootloader/nrf/memory.x | 18 +++++++ examples/boot/bootloader/nrf/src/main.rs | 48 ++++++++++++++++++ examples/boot/bootloader/stm32/Cargo.toml | 57 +++++++++++++++++++++ examples/boot/bootloader/stm32/README.md | 11 ++++ examples/boot/bootloader/stm32/build.rs | 32 ++++++++++++ examples/boot/bootloader/stm32/memory.x | 18 +++++++ examples/boot/bootloader/stm32/src/main.rs | 46 +++++++++++++++++ examples/boot/nrf/.cargo/config.toml | 9 ---- examples/boot/nrf/Cargo.toml | 18 ------- examples/boot/nrf/README.md | 34 ------------- examples/boot/nrf/build.rs | 34 ------------- examples/boot/nrf/memory-bl.x | 18 ------- examples/boot/nrf/memory.x | 15 ------ examples/boot/nrf/src/bin/a.rs | 43 ---------------- examples/boot/nrf/src/bin/b.rs | 23 --------- examples/boot/stm32f3/.cargo/config.toml | 9 ---- examples/boot/stm32f3/Cargo.toml | 25 ---------- examples/boot/stm32f3/README.md | 29 ----------- examples/boot/stm32f3/build.rs | 37 -------------- examples/boot/stm32f3/memory.x | 15 ------ examples/boot/stm32f3/src/bin/a.rs | 40 --------------- examples/boot/stm32f3/src/bin/b.rs | 24 --------- examples/boot/stm32f7/.cargo/config.toml | 9 ---- examples/boot/stm32f7/Cargo.toml | 25 ---------- examples/boot/stm32f7/README.md | 29 ----------- examples/boot/stm32f7/build.rs | 37 -------------- examples/boot/stm32f7/flash-boot.sh | 8 --- examples/boot/stm32f7/memory-bl.x | 18 ------- examples/boot/stm32f7/memory.x | 15 ------ examples/boot/stm32f7/src/bin/a.rs | 40 --------------- examples/boot/stm32f7/src/bin/b.rs | 26 ---------- examples/boot/stm32h7/.cargo/config.toml | 9 ---- examples/boot/stm32h7/Cargo.toml | 25 ---------- examples/boot/stm32h7/README.md | 29 ----------- examples/boot/stm32h7/build.rs | 37 -------------- examples/boot/stm32h7/flash-boot.sh | 8 --- examples/boot/stm32h7/memory-bl.x | 18 ------- examples/boot/stm32h7/memory.x | 15 ------ examples/boot/stm32h7/src/bin/a.rs | 40 --------------- examples/boot/stm32h7/src/bin/b.rs | 26 ---------- examples/boot/stm32l0/.cargo/config.toml | 9 ---- examples/boot/stm32l0/Cargo.toml | 25 ---------- examples/boot/stm32l0/README.md | 29 ----------- examples/boot/stm32l0/build.rs | 37 -------------- examples/boot/stm32l0/memory.x | 15 ------ examples/boot/stm32l0/src/bin/a.rs | 44 ---------------- examples/boot/stm32l0/src/bin/b.rs | 24 --------- examples/boot/stm32l1/.cargo/config.toml | 9 ---- examples/boot/stm32l1/Cargo.toml | 25 ---------- examples/boot/stm32l1/README.md | 29 ----------- examples/boot/stm32l1/build.rs | 37 -------------- examples/boot/stm32l1/memory.x | 15 ------ examples/boot/stm32l1/src/bin/a.rs | 44 ---------------- examples/boot/stm32l1/src/bin/b.rs | 24 --------- examples/boot/stm32l4/.cargo/config.toml | 9 ---- examples/boot/stm32l4/Cargo.toml | 25 ---------- examples/boot/stm32l4/README.md | 29 ----------- examples/boot/stm32l4/build.rs | 37 -------------- examples/boot/stm32l4/memory.x | 15 ------ examples/boot/stm32l4/src/bin/a.rs | 40 --------------- examples/boot/stm32l4/src/bin/b.rs | 24 --------- examples/boot/stm32wl/.cargo/config.toml | 9 ---- examples/boot/stm32wl/Cargo.toml | 25 ---------- examples/boot/stm32wl/README.md | 29 ----------- examples/boot/stm32wl/build.rs | 37 -------------- examples/boot/stm32wl/memory.x | 15 ------ examples/boot/stm32wl/src/bin/a.rs | 43 ---------------- examples/boot/stm32wl/src/bin/b.rs | 24 --------- 135 files changed, 1919 insertions(+), 1514 deletions(-) create mode 100644 examples/boot/application/nrf/.cargo/config.toml create mode 100644 examples/boot/application/nrf/Cargo.toml create mode 100644 examples/boot/application/nrf/README.md create mode 100644 examples/boot/application/nrf/build.rs create mode 100644 examples/boot/application/nrf/memory-bl.x create mode 100644 examples/boot/application/nrf/memory.x create mode 100644 examples/boot/application/nrf/src/bin/a.rs create mode 100644 examples/boot/application/nrf/src/bin/b.rs create mode 100644 examples/boot/application/stm32f3/.cargo/config.toml create mode 100644 examples/boot/application/stm32f3/Cargo.toml create mode 100644 examples/boot/application/stm32f3/README.md create mode 100644 examples/boot/application/stm32f3/build.rs create mode 100644 examples/boot/application/stm32f3/memory.x create mode 100644 examples/boot/application/stm32f3/src/bin/a.rs create mode 100644 examples/boot/application/stm32f3/src/bin/b.rs create mode 100644 examples/boot/application/stm32f7/.cargo/config.toml create mode 100644 examples/boot/application/stm32f7/Cargo.toml create mode 100644 examples/boot/application/stm32f7/README.md create mode 100644 examples/boot/application/stm32f7/build.rs create mode 100755 examples/boot/application/stm32f7/flash-boot.sh create mode 100644 examples/boot/application/stm32f7/memory-bl.x create mode 100644 examples/boot/application/stm32f7/memory.x create mode 100644 examples/boot/application/stm32f7/src/bin/a.rs create mode 100644 examples/boot/application/stm32f7/src/bin/b.rs create mode 100644 examples/boot/application/stm32h7/.cargo/config.toml create mode 100644 examples/boot/application/stm32h7/Cargo.toml create mode 100644 examples/boot/application/stm32h7/README.md create mode 100644 examples/boot/application/stm32h7/build.rs create mode 100755 examples/boot/application/stm32h7/flash-boot.sh create mode 100644 examples/boot/application/stm32h7/memory-bl.x create mode 100644 examples/boot/application/stm32h7/memory.x create mode 100644 examples/boot/application/stm32h7/src/bin/a.rs create mode 100644 examples/boot/application/stm32h7/src/bin/b.rs create mode 100644 examples/boot/application/stm32l0/.cargo/config.toml create mode 100644 examples/boot/application/stm32l0/Cargo.toml create mode 100644 examples/boot/application/stm32l0/README.md create mode 100644 examples/boot/application/stm32l0/build.rs create mode 100644 examples/boot/application/stm32l0/memory.x create mode 100644 examples/boot/application/stm32l0/src/bin/a.rs create mode 100644 examples/boot/application/stm32l0/src/bin/b.rs create mode 100644 examples/boot/application/stm32l1/.cargo/config.toml create mode 100644 examples/boot/application/stm32l1/Cargo.toml create mode 100644 examples/boot/application/stm32l1/README.md create mode 100644 examples/boot/application/stm32l1/build.rs create mode 100644 examples/boot/application/stm32l1/memory.x create mode 100644 examples/boot/application/stm32l1/src/bin/a.rs create mode 100644 examples/boot/application/stm32l1/src/bin/b.rs create mode 100644 examples/boot/application/stm32l4/.cargo/config.toml create mode 100644 examples/boot/application/stm32l4/Cargo.toml create mode 100644 examples/boot/application/stm32l4/README.md create mode 100644 examples/boot/application/stm32l4/build.rs create mode 100644 examples/boot/application/stm32l4/memory.x create mode 100644 examples/boot/application/stm32l4/src/bin/a.rs create mode 100644 examples/boot/application/stm32l4/src/bin/b.rs create mode 100644 examples/boot/application/stm32wl/.cargo/config.toml create mode 100644 examples/boot/application/stm32wl/Cargo.toml create mode 100644 examples/boot/application/stm32wl/README.md create mode 100644 examples/boot/application/stm32wl/build.rs create mode 100644 examples/boot/application/stm32wl/memory.x create mode 100644 examples/boot/application/stm32wl/src/bin/a.rs create mode 100644 examples/boot/application/stm32wl/src/bin/b.rs create mode 100644 examples/boot/bootloader/nrf/.cargo/config.toml create mode 100644 examples/boot/bootloader/nrf/Cargo.toml create mode 100644 examples/boot/bootloader/nrf/README.md create mode 100644 examples/boot/bootloader/nrf/build.rs create mode 100644 examples/boot/bootloader/nrf/memory-bm.x create mode 100644 examples/boot/bootloader/nrf/memory-s140.x create mode 100644 examples/boot/bootloader/nrf/memory.x create mode 100644 examples/boot/bootloader/nrf/src/main.rs create mode 100644 examples/boot/bootloader/stm32/Cargo.toml create mode 100644 examples/boot/bootloader/stm32/README.md create mode 100644 examples/boot/bootloader/stm32/build.rs create mode 100644 examples/boot/bootloader/stm32/memory.x create mode 100644 examples/boot/bootloader/stm32/src/main.rs delete mode 100644 examples/boot/nrf/.cargo/config.toml delete mode 100644 examples/boot/nrf/Cargo.toml delete mode 100644 examples/boot/nrf/README.md delete mode 100644 examples/boot/nrf/build.rs delete mode 100644 examples/boot/nrf/memory-bl.x delete mode 100644 examples/boot/nrf/memory.x delete mode 100644 examples/boot/nrf/src/bin/a.rs delete mode 100644 examples/boot/nrf/src/bin/b.rs delete mode 100644 examples/boot/stm32f3/.cargo/config.toml delete mode 100644 examples/boot/stm32f3/Cargo.toml delete mode 100644 examples/boot/stm32f3/README.md delete mode 100644 examples/boot/stm32f3/build.rs delete mode 100644 examples/boot/stm32f3/memory.x delete mode 100644 examples/boot/stm32f3/src/bin/a.rs delete mode 100644 examples/boot/stm32f3/src/bin/b.rs delete mode 100644 examples/boot/stm32f7/.cargo/config.toml delete mode 100644 examples/boot/stm32f7/Cargo.toml delete mode 100644 examples/boot/stm32f7/README.md delete mode 100644 examples/boot/stm32f7/build.rs delete mode 100755 examples/boot/stm32f7/flash-boot.sh delete mode 100644 examples/boot/stm32f7/memory-bl.x delete mode 100644 examples/boot/stm32f7/memory.x delete mode 100644 examples/boot/stm32f7/src/bin/a.rs delete mode 100644 examples/boot/stm32f7/src/bin/b.rs delete mode 100644 examples/boot/stm32h7/.cargo/config.toml delete mode 100644 examples/boot/stm32h7/Cargo.toml delete mode 100644 examples/boot/stm32h7/README.md delete mode 100644 examples/boot/stm32h7/build.rs delete mode 100755 examples/boot/stm32h7/flash-boot.sh delete mode 100644 examples/boot/stm32h7/memory-bl.x delete mode 100644 examples/boot/stm32h7/memory.x delete mode 100644 examples/boot/stm32h7/src/bin/a.rs delete mode 100644 examples/boot/stm32h7/src/bin/b.rs delete mode 100644 examples/boot/stm32l0/.cargo/config.toml delete mode 100644 examples/boot/stm32l0/Cargo.toml delete mode 100644 examples/boot/stm32l0/README.md delete mode 100644 examples/boot/stm32l0/build.rs delete mode 100644 examples/boot/stm32l0/memory.x delete mode 100644 examples/boot/stm32l0/src/bin/a.rs delete mode 100644 examples/boot/stm32l0/src/bin/b.rs delete mode 100644 examples/boot/stm32l1/.cargo/config.toml delete mode 100644 examples/boot/stm32l1/Cargo.toml delete mode 100644 examples/boot/stm32l1/README.md delete mode 100644 examples/boot/stm32l1/build.rs delete mode 100644 examples/boot/stm32l1/memory.x delete mode 100644 examples/boot/stm32l1/src/bin/a.rs delete mode 100644 examples/boot/stm32l1/src/bin/b.rs delete mode 100644 examples/boot/stm32l4/.cargo/config.toml delete mode 100644 examples/boot/stm32l4/Cargo.toml delete mode 100644 examples/boot/stm32l4/README.md delete mode 100644 examples/boot/stm32l4/build.rs delete mode 100644 examples/boot/stm32l4/memory.x delete mode 100644 examples/boot/stm32l4/src/bin/a.rs delete mode 100644 examples/boot/stm32l4/src/bin/b.rs delete mode 100644 examples/boot/stm32wl/.cargo/config.toml delete mode 100644 examples/boot/stm32wl/Cargo.toml delete mode 100644 examples/boot/stm32wl/README.md delete mode 100644 examples/boot/stm32wl/build.rs delete mode 100644 examples/boot/stm32wl/memory.x delete mode 100644 examples/boot/stm32wl/src/bin/a.rs delete mode 100644 examples/boot/stm32wl/src/bin/b.rs (limited to 'examples') diff --git a/examples/boot/application/nrf/.cargo/config.toml b/examples/boot/application/nrf/.cargo/config.toml new file mode 100644 index 000000000..8ca28df39 --- /dev/null +++ b/examples/boot/application/nrf/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip nRF52840_xxAA" + +[build] +target = "thumbv7em-none-eabi" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml new file mode 100644 index 000000000..0ae7163c3 --- /dev/null +++ b/examples/boot/application/nrf/Cargo.toml @@ -0,0 +1,18 @@ +[package] +edition = "2021" +name = "embassy-boot-nrf-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly"] } +embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } +embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" diff --git a/examples/boot/application/nrf/README.md b/examples/boot/application/nrf/README.md new file mode 100644 index 000000000..703377a20 --- /dev/null +++ b/examples/boot/application/nrf/README.md @@ -0,0 +1,34 @@ +# Examples using bootloader + +Example for nRF52 demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-nrf` + +## Usage + + + +``` +# Use bare metal linker script +cp memory-bl.x ../../bootloader/nrf/memory.x + +# Flash bootloader +cargo flash --manifest-path ../../bootloader/nrf/Cargo.toml --features embassy-nrf/nrf52840 --release --chip nRF52840_xxAA +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip nRF52840_xxAA +``` diff --git a/examples/boot/application/nrf/build.rs b/examples/boot/application/nrf/build.rs new file mode 100644 index 000000000..cd1a264c4 --- /dev/null +++ b/examples/boot/application/nrf/build.rs @@ -0,0 +1,34 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); +} diff --git a/examples/boot/application/nrf/memory-bl.x b/examples/boot/application/nrf/memory-bl.x new file mode 100644 index 000000000..8a32b905f --- /dev/null +++ b/examples/boot/application/nrf/memory-bl.x @@ -0,0 +1,18 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x00000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K + ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K + DFU : ORIGIN = 0x00017000, LENGTH = 68K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); + +__bootloader_active_start = ORIGIN(ACTIVE); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); + +__bootloader_dfu_start = ORIGIN(DFU); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/application/nrf/memory.x b/examples/boot/application/nrf/memory.x new file mode 100644 index 000000000..3a54ca460 --- /dev/null +++ b/examples/boot/application/nrf/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x00000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K + FLASH : ORIGIN = 0x00007000, LENGTH = 64K + DFU : ORIGIN = 0x00017000, LENGTH = 68K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); + +__bootloader_dfu_start = ORIGIN(DFU); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs new file mode 100644 index 000000000..0b9715e49 --- /dev/null +++ b/examples/boot/application/nrf/src/bin/a.rs @@ -0,0 +1,43 @@ +#![no_std] +#![no_main] +#![macro_use] +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +use embassy_boot_nrf::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; +use embassy_nrf::nvmc::Nvmc; +use embassy_nrf::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let mut button = Input::new(p.P0_11, Pull::Up); + let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); + //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); + //let mut button = Input::new(p.P1_02, Pull::Up); + + let nvmc = Nvmc::new(p.NVMC); + let mut nvmc = BlockingAsync::new(nvmc); + + let mut updater = FirmwareUpdater::default(); + loop { + led.set_low(); + button.wait_for_any_edge().await; + if button.is_low() { + let mut offset = 0; + for chunk in APP_B.chunks(4096) { + let mut buf: [u8; 4096] = [0; 4096]; + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); + offset += chunk.len(); + } + updater.update(&mut nvmc).await.unwrap(); + led.set_high(); + cortex_m::peripheral::SCB::sys_reset(); + } + } +} diff --git a/examples/boot/application/nrf/src/bin/b.rs b/examples/boot/application/nrf/src/bin/b.rs new file mode 100644 index 000000000..a06c20f8b --- /dev/null +++ b/examples/boot/application/nrf/src/bin/b.rs @@ -0,0 +1,23 @@ +#![no_std] +#![no_main] +#![macro_use] +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +use embassy::time::{Duration, Timer}; +use embassy_nrf::gpio::{Level, Output, OutputDrive}; +use embassy_nrf::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); + //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(300)).await; + led.set_low(); + Timer::after(Duration::from_millis(300)).await; + } +} diff --git a/examples/boot/application/stm32f3/.cargo/config.toml b/examples/boot/application/stm32f3/.cargo/config.toml new file mode 100644 index 000000000..a76d6cab4 --- /dev/null +++ b/examples/boot/application/stm32f3/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip STM32F303VCTx" + +[build] +target = "thumbv7em-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml new file mode 100644 index 000000000..36fc135fe --- /dev/null +++ b/examples/boot/application/stm32f3/Cargo.toml @@ -0,0 +1,25 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32f3-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", +] diff --git a/examples/boot/application/stm32f3/README.md b/examples/boot/application/stm32f3/README.md new file mode 100644 index 000000000..46f033d5e --- /dev/null +++ b/examples/boot/application/stm32f3/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32F3 demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32f303re --chip STM32F303RETx +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32F303RETx +``` diff --git a/examples/boot/application/stm32f3/build.rs b/examples/boot/application/stm32f3/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32f3/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/application/stm32f3/memory.x b/examples/boot/application/stm32f3/memory.x new file mode 100644 index 000000000..14b2a2c9f --- /dev/null +++ b/examples/boot/application/stm32f3/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + FLASH : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs new file mode 100644 index 000000000..4ff18d7c7 --- /dev/null +++ b/examples/boot/application/stm32f3/src/bin/a.rs @@ -0,0 +1,40 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy_boot_stm32::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::flash::Flash; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let flash = Flash::unlock(p.FLASH); + let mut flash = BlockingAsync::new(flash); + + let button = Input::new(p.PC13, Pull::Up); + let mut button = ExtiInput::new(button, p.EXTI13); + + let mut led = Output::new(p.PA5, Level::Low, Speed::Low); + led.set_high(); + + let mut updater = FirmwareUpdater::default(); + button.wait_for_falling_edge().await; + let mut offset = 0; + for chunk in APP_B.chunks(2048) { + let mut buf: [u8; 2048] = [0; 2048]; + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); + offset += chunk.len(); + } + updater.update(&mut flash).await.unwrap(); + led.set_low(); + cortex_m::peripheral::SCB::sys_reset(); +} diff --git a/examples/boot/application/stm32f3/src/bin/b.rs b/examples/boot/application/stm32f3/src/bin/b.rs new file mode 100644 index 000000000..4487e586e --- /dev/null +++ b/examples/boot/application/stm32f3/src/bin/b.rs @@ -0,0 +1,24 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + let mut led = Output::new(p.PA5, Level::High, Speed::Low); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(500)).await; + + led.set_low(); + Timer::after(Duration::from_millis(500)).await; + } +} diff --git a/examples/boot/application/stm32f7/.cargo/config.toml b/examples/boot/application/stm32f7/.cargo/config.toml new file mode 100644 index 000000000..a90e1ccbb --- /dev/null +++ b/examples/boot/application/stm32f7/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip STM32F767ZITx -v" + +[build] +target = "thumbv7em-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml new file mode 100644 index 000000000..ad4a6fa76 --- /dev/null +++ b/examples/boot/application/stm32f7/Cargo.toml @@ -0,0 +1,25 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32f7-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", +] diff --git a/examples/boot/application/stm32f7/README.md b/examples/boot/application/stm32f7/README.md new file mode 100644 index 000000000..bf9142a1c --- /dev/null +++ b/examples/boot/application/stm32f7/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32F7 demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +./flash-boot.sh +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32F767ZITx +``` diff --git a/examples/boot/application/stm32f7/build.rs b/examples/boot/application/stm32f7/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32f7/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/application/stm32f7/flash-boot.sh b/examples/boot/application/stm32f7/flash-boot.sh new file mode 100755 index 000000000..debdb17a7 --- /dev/null +++ b/examples/boot/application/stm32f7/flash-boot.sh @@ -0,0 +1,8 @@ +#!/bin/bash +mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x +cp memory-bl.x ../../bootloader/stm32/memory.x + +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf + +rm ../../bootloader/stm32/memory.x +mv ../../bootloader/stm32/memory-old.x ../../bootloader/stm32/memory.x diff --git a/examples/boot/application/stm32f7/memory-bl.x b/examples/boot/application/stm32f7/memory-bl.x new file mode 100644 index 000000000..47f3f4d9b --- /dev/null +++ b/examples/boot/application/stm32f7/memory-bl.x @@ -0,0 +1,18 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x08000000, LENGTH = 256K + BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K + ACTIVE : ORIGIN = 0x08080000, LENGTH = 256K + DFU : ORIGIN = 0x080c0000, LENGTH = 512K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 368K + 16K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); + +__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); diff --git a/examples/boot/application/stm32f7/memory.x b/examples/boot/application/stm32f7/memory.x new file mode 100644 index 000000000..1c5537d17 --- /dev/null +++ b/examples/boot/application/stm32f7/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 256K + BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K + FLASH : ORIGIN = 0x08080000, LENGTH = 256K + DFU : ORIGIN = 0x080c0000, LENGTH = 512K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 368K + 16K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs new file mode 100644 index 000000000..9c7921a1a --- /dev/null +++ b/examples/boot/application/stm32f7/src/bin/a.rs @@ -0,0 +1,40 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy_boot_stm32::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::flash::Flash; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let flash = Flash::unlock(p.FLASH); + let mut flash = BlockingAsync::new(flash); + + let button = Input::new(p.PC13, Pull::Down); + let mut button = ExtiInput::new(button, p.EXTI13); + + let mut led = Output::new(p.PB7, Level::Low, Speed::Low); + led.set_high(); + + let mut updater = FirmwareUpdater::default(); + button.wait_for_rising_edge().await; + let mut offset = 0; + let mut buf: [u8; 256 * 1024] = [0; 256 * 1024]; + for chunk in APP_B.chunks(256 * 1024) { + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); + offset += chunk.len(); + } + updater.update(&mut flash).await.unwrap(); + led.set_low(); + cortex_m::peripheral::SCB::sys_reset(); +} diff --git a/examples/boot/application/stm32f7/src/bin/b.rs b/examples/boot/application/stm32f7/src/bin/b.rs new file mode 100644 index 000000000..aa05bbcdd --- /dev/null +++ b/examples/boot/application/stm32f7/src/bin/b.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + Timer::after(Duration::from_millis(300)).await; + let mut led = Output::new(p.PB7, Level::High, Speed::Low); + led.set_high(); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(500)).await; + + led.set_low(); + Timer::after(Duration::from_millis(500)).await; + } +} diff --git a/examples/boot/application/stm32h7/.cargo/config.toml b/examples/boot/application/stm32h7/.cargo/config.toml new file mode 100644 index 000000000..fefdd370e --- /dev/null +++ b/examples/boot/application/stm32h7/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip STM32H743ZITx" + +[build] +target = "thumbv7em-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml new file mode 100644 index 000000000..54530cc5b --- /dev/null +++ b/examples/boot/application/stm32h7/Cargo.toml @@ -0,0 +1,25 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32f7-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", +] diff --git a/examples/boot/application/stm32h7/README.md b/examples/boot/application/stm32h7/README.md new file mode 100644 index 000000000..1fdc305e6 --- /dev/null +++ b/examples/boot/application/stm32h7/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32H7 demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +./flash-boot.sh +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32H743ZITx +``` diff --git a/examples/boot/application/stm32h7/build.rs b/examples/boot/application/stm32h7/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32h7/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/application/stm32h7/flash-boot.sh b/examples/boot/application/stm32h7/flash-boot.sh new file mode 100755 index 000000000..debdb17a7 --- /dev/null +++ b/examples/boot/application/stm32h7/flash-boot.sh @@ -0,0 +1,8 @@ +#!/bin/bash +mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x +cp memory-bl.x ../../bootloader/stm32/memory.x + +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf + +rm ../../bootloader/stm32/memory.x +mv ../../bootloader/stm32/memory-old.x ../../bootloader/stm32/memory.x diff --git a/examples/boot/application/stm32h7/memory-bl.x b/examples/boot/application/stm32h7/memory-bl.x new file mode 100644 index 000000000..c6f447d8b --- /dev/null +++ b/examples/boot/application/stm32h7/memory-bl.x @@ -0,0 +1,18 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x08000000, LENGTH = 128K + BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K + ACTIVE : ORIGIN = 0x08040000, LENGTH = 128K + DFU : ORIGIN = 0x08100000, LENGTH = 512K + RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); + +__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); diff --git a/examples/boot/application/stm32h7/memory.x b/examples/boot/application/stm32h7/memory.x new file mode 100644 index 000000000..497a09e41 --- /dev/null +++ b/examples/boot/application/stm32h7/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 128K + BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K + FLASH : ORIGIN = 0x08040000, LENGTH = 256K + DFU : ORIGIN = 0x08100000, LENGTH = 512K + RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs new file mode 100644 index 000000000..704979dba --- /dev/null +++ b/examples/boot/application/stm32h7/src/bin/a.rs @@ -0,0 +1,40 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy_boot_stm32::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::flash::Flash; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let flash = Flash::unlock(p.FLASH); + let mut flash = BlockingAsync::new(flash); + + let button = Input::new(p.PC13, Pull::Down); + let mut button = ExtiInput::new(button, p.EXTI13); + + let mut led = Output::new(p.PB14, Level::Low, Speed::Low); + led.set_high(); + + let mut updater = FirmwareUpdater::default(); + button.wait_for_rising_edge().await; + let mut offset = 0; + let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; + for chunk in APP_B.chunks(128 * 1024) { + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); + offset += chunk.len(); + } + updater.update(&mut flash).await.unwrap(); + led.set_low(); + cortex_m::peripheral::SCB::sys_reset(); +} diff --git a/examples/boot/application/stm32h7/src/bin/b.rs b/examples/boot/application/stm32h7/src/bin/b.rs new file mode 100644 index 000000000..ea0140253 --- /dev/null +++ b/examples/boot/application/stm32h7/src/bin/b.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + Timer::after(Duration::from_millis(300)).await; + let mut led = Output::new(p.PB14, Level::High, Speed::Low); + led.set_high(); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(500)).await; + + led.set_low(); + Timer::after(Duration::from_millis(500)).await; + } +} diff --git a/examples/boot/application/stm32l0/.cargo/config.toml b/examples/boot/application/stm32l0/.cargo/config.toml new file mode 100644 index 000000000..2627967ab --- /dev/null +++ b/examples/boot/application/stm32l0/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip STM32L072CZTx" + +[build] +target = "thumbv6m-none-eabi" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml new file mode 100644 index 000000000..de7bea47b --- /dev/null +++ b/examples/boot/application/stm32l0/Cargo.toml @@ -0,0 +1,25 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32l0-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", +] diff --git a/examples/boot/application/stm32l0/README.md b/examples/boot/application/stm32l0/README.md new file mode 100644 index 000000000..762bdfe71 --- /dev/null +++ b/examples/boot/application/stm32l0/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32L0 demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32l072cz --chip STM32L072CZTx +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32L072CZTx +``` diff --git a/examples/boot/application/stm32l0/build.rs b/examples/boot/application/stm32l0/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32l0/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/application/stm32l0/memory.x b/examples/boot/application/stm32l0/memory.x new file mode 100644 index 000000000..d0d2bd7bb --- /dev/null +++ b/examples/boot/application/stm32l0/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + FLASH : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs new file mode 100644 index 000000000..ce620347b --- /dev/null +++ b/examples/boot/application/stm32l0/src/bin/a.rs @@ -0,0 +1,44 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::time::{Duration, Timer}; +use embassy_boot_stm32::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::flash::Flash; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let flash = Flash::unlock(p.FLASH); + let mut flash = BlockingAsync::new(flash); + + let button = Input::new(p.PB2, Pull::Up); + let mut button = ExtiInput::new(button, p.EXTI2); + + let mut led = Output::new(p.PB5, Level::Low, Speed::Low); + + led.set_high(); + + let mut updater = FirmwareUpdater::default(); + button.wait_for_falling_edge().await; + let mut offset = 0; + for chunk in APP_B.chunks(128) { + let mut buf: [u8; 128] = [0; 128]; + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); + offset += chunk.len(); + } + + updater.update(&mut flash).await.unwrap(); + led.set_low(); + Timer::after(Duration::from_secs(1)).await; + cortex_m::peripheral::SCB::sys_reset(); +} diff --git a/examples/boot/application/stm32l0/src/bin/b.rs b/examples/boot/application/stm32l0/src/bin/b.rs new file mode 100644 index 000000000..0b585a14c --- /dev/null +++ b/examples/boot/application/stm32l0/src/bin/b.rs @@ -0,0 +1,24 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + let mut led = Output::new(p.PB6, Level::High, Speed::Low); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(500)).await; + + led.set_low(); + Timer::after(Duration::from_millis(500)).await; + } +} diff --git a/examples/boot/application/stm32l1/.cargo/config.toml b/examples/boot/application/stm32l1/.cargo/config.toml new file mode 100644 index 000000000..404b6b55c --- /dev/null +++ b/examples/boot/application/stm32l1/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip STM32L151CBxxA" + +[build] +target = "thumbv7m-none-eabi" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml new file mode 100644 index 000000000..3fd6f639a --- /dev/null +++ b/examples/boot/application/stm32l1/Cargo.toml @@ -0,0 +1,25 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32l1-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", +] diff --git a/examples/boot/application/stm32l1/README.md b/examples/boot/application/stm32l1/README.md new file mode 100644 index 000000000..428dde7b3 --- /dev/null +++ b/examples/boot/application/stm32l1/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32L1 demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32l151cb-a --chip STM32L151CBxxA +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32L151CBxxA +``` diff --git a/examples/boot/application/stm32l1/build.rs b/examples/boot/application/stm32l1/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32l1/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/application/stm32l1/memory.x b/examples/boot/application/stm32l1/memory.x new file mode 100644 index 000000000..d0d2bd7bb --- /dev/null +++ b/examples/boot/application/stm32l1/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + FLASH : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs new file mode 100644 index 000000000..ce620347b --- /dev/null +++ b/examples/boot/application/stm32l1/src/bin/a.rs @@ -0,0 +1,44 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::time::{Duration, Timer}; +use embassy_boot_stm32::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::flash::Flash; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let flash = Flash::unlock(p.FLASH); + let mut flash = BlockingAsync::new(flash); + + let button = Input::new(p.PB2, Pull::Up); + let mut button = ExtiInput::new(button, p.EXTI2); + + let mut led = Output::new(p.PB5, Level::Low, Speed::Low); + + led.set_high(); + + let mut updater = FirmwareUpdater::default(); + button.wait_for_falling_edge().await; + let mut offset = 0; + for chunk in APP_B.chunks(128) { + let mut buf: [u8; 128] = [0; 128]; + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); + offset += chunk.len(); + } + + updater.update(&mut flash).await.unwrap(); + led.set_low(); + Timer::after(Duration::from_secs(1)).await; + cortex_m::peripheral::SCB::sys_reset(); +} diff --git a/examples/boot/application/stm32l1/src/bin/b.rs b/examples/boot/application/stm32l1/src/bin/b.rs new file mode 100644 index 000000000..0b585a14c --- /dev/null +++ b/examples/boot/application/stm32l1/src/bin/b.rs @@ -0,0 +1,24 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + let mut led = Output::new(p.PB6, Level::High, Speed::Low); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(500)).await; + + led.set_low(); + Timer::after(Duration::from_millis(500)).await; + } +} diff --git a/examples/boot/application/stm32l4/.cargo/config.toml b/examples/boot/application/stm32l4/.cargo/config.toml new file mode 100644 index 000000000..43520e323 --- /dev/null +++ b/examples/boot/application/stm32l4/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip STM32L475VG" + +[build] +target = "thumbv7em-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml new file mode 100644 index 000000000..7284af662 --- /dev/null +++ b/examples/boot/application/stm32l4/Cargo.toml @@ -0,0 +1,25 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32l4-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", +] diff --git a/examples/boot/application/stm32l4/README.md b/examples/boot/application/stm32l4/README.md new file mode 100644 index 000000000..83f50748c --- /dev/null +++ b/examples/boot/application/stm32l4/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32L4 demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32l475vg --chip STM32L475VG +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32L475VG +``` diff --git a/examples/boot/application/stm32l4/build.rs b/examples/boot/application/stm32l4/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32l4/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/application/stm32l4/memory.x b/examples/boot/application/stm32l4/memory.x new file mode 100644 index 000000000..14b2a2c9f --- /dev/null +++ b/examples/boot/application/stm32l4/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + FLASH : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs new file mode 100644 index 000000000..bf6099355 --- /dev/null +++ b/examples/boot/application/stm32l4/src/bin/a.rs @@ -0,0 +1,40 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy_boot_stm32::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::flash::Flash; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let flash = Flash::unlock(p.FLASH); + let mut flash = BlockingAsync::new(flash); + + let button = Input::new(p.PC13, Pull::Up); + let mut button = ExtiInput::new(button, p.EXTI13); + + let mut led = Output::new(p.PB14, Level::Low, Speed::Low); + led.set_high(); + + let mut updater = FirmwareUpdater::default(); + button.wait_for_falling_edge().await; + let mut offset = 0; + for chunk in APP_B.chunks(2048) { + let mut buf: [u8; 2048] = [0; 2048]; + buf[..chunk.len()].copy_from_slice(chunk); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); + offset += chunk.len(); + } + updater.update(&mut flash).await.unwrap(); + led.set_low(); + cortex_m::peripheral::SCB::sys_reset(); +} diff --git a/examples/boot/application/stm32l4/src/bin/b.rs b/examples/boot/application/stm32l4/src/bin/b.rs new file mode 100644 index 000000000..4487e586e --- /dev/null +++ b/examples/boot/application/stm32l4/src/bin/b.rs @@ -0,0 +1,24 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + let mut led = Output::new(p.PA5, Level::High, Speed::Low); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(500)).await; + + led.set_low(); + Timer::after(Duration::from_millis(500)).await; + } +} diff --git a/examples/boot/application/stm32wl/.cargo/config.toml b/examples/boot/application/stm32wl/.cargo/config.toml new file mode 100644 index 000000000..e395d75b4 --- /dev/null +++ b/examples/boot/application/stm32wl/.cargo/config.toml @@ -0,0 +1,9 @@ +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +# replace your chip as listed in `probe-run --list-chips` +runner = "probe-run --chip STM32WLE5JCIx" + +[build] +target = "thumbv7em-none-eabihf" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml new file mode 100644 index 000000000..ca22e6134 --- /dev/null +++ b/examples/boot/application/stm32wl/Cargo.toml @@ -0,0 +1,25 @@ +[package] +edition = "2021" +name = "embassy-boot-stm32wl-examples" +version = "0.1.0" + +[dependencies] +embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] } +embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } +embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } +embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } + +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } +panic-reset = { version = "0.1.1" } +embedded-hal = { version = "0.2.6" } + +cortex-m = "0.7.3" +cortex-m-rt = "0.7.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-stm32/defmt", + "embassy-boot-stm32/defmt", +] diff --git a/examples/boot/application/stm32wl/README.md b/examples/boot/application/stm32wl/README.md new file mode 100644 index 000000000..c8dce0387 --- /dev/null +++ b/examples/boot/application/stm32wl/README.md @@ -0,0 +1,29 @@ +# Examples using bootloader + +Example for STM32WL demonstrating the bootloader. The example consists of application binaries, 'a' +which allows you to press a button to start the DFU process, and 'b' which is the updated +application. + + +## Prerequisites + +* `cargo-binutils` +* `cargo-flash` +* `embassy-boot-stm32` + +## Usage + +``` +# Flash bootloader +cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32wl55jc-cm4 --chip STM32WLE5JCIx +# Build 'b' +cargo build --release --bin b +# Generate binary for 'b' +cargo objcopy --release --bin b -- -O binary b.bin +``` + +# Flash `a` (which includes b.bin) + +``` +cargo flash --release --bin a --chip STM32WLE5JCIx +``` diff --git a/examples/boot/application/stm32wl/build.rs b/examples/boot/application/stm32wl/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32wl/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/application/stm32wl/memory.x b/examples/boot/application/stm32wl/memory.x new file mode 100644 index 000000000..14b2a2c9f --- /dev/null +++ b/examples/boot/application/stm32wl/memory.x @@ -0,0 +1,15 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + FLASH : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs new file mode 100644 index 000000000..dc1eb9bed --- /dev/null +++ b/examples/boot/application/stm32wl/src/bin/a.rs @@ -0,0 +1,43 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy_boot_stm32::FirmwareUpdater; +use embassy_embedded_hal::adapter::BlockingAsync; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::flash::Flash; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +static APP_B: &[u8] = include_bytes!("../../b.bin"); + +#[embassy::main] +async fn main(_s: embassy::executor::Spawner, p: Peripherals) { + let flash = Flash::unlock(p.FLASH); + let mut flash = BlockingAsync::new(flash); + + let button = Input::new(p.PA0, Pull::Up); + let mut button = ExtiInput::new(button, p.EXTI0); + + let mut led = Output::new(p.PB9, Level::Low, Speed::Low); + led.set_high(); + + let mut updater = FirmwareUpdater::default(); + button.wait_for_falling_edge().await; + //defmt::info!("Starting update"); + let mut offset = 0; + for chunk in APP_B.chunks(2048) { + let mut buf: [u8; 2048] = [0; 2048]; + buf[..chunk.len()].copy_from_slice(chunk); + // defmt::info!("Writing chunk at 0x{:x}", offset); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); + offset += chunk.len(); + } + updater.update(&mut flash).await.unwrap(); + //defmt::info!("Marked as updated"); + led.set_low(); + cortex_m::peripheral::SCB::sys_reset(); +} diff --git a/examples/boot/application/stm32wl/src/bin/b.rs b/examples/boot/application/stm32wl/src/bin/b.rs new file mode 100644 index 000000000..f2344bd53 --- /dev/null +++ b/examples/boot/application/stm32wl/src/bin/b.rs @@ -0,0 +1,24 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::Peripherals; +use panic_reset as _; + +#[embassy::main] +async fn main(_spawner: Spawner, p: Peripherals) { + let mut led = Output::new(p.PB15, Level::High, Speed::Low); + + loop { + led.set_high(); + Timer::after(Duration::from_millis(500)).await; + + led.set_low(); + Timer::after(Duration::from_millis(500)).await; + } +} diff --git a/examples/boot/bootloader/nrf/.cargo/config.toml b/examples/boot/bootloader/nrf/.cargo/config.toml new file mode 100644 index 000000000..1060800a3 --- /dev/null +++ b/examples/boot/bootloader/nrf/.cargo/config.toml @@ -0,0 +1,20 @@ +[unstable] +build-std = ["core"] +build-std-features = ["panic_immediate_abort"] + +[target.'cfg(all(target_arch = "arm", target_os = "none"))'] +#runner = "./fruitrunner" +runner = "probe-run --chip nrf52840_xxAA" + +rustflags = [ + # Code-size optimizations. + "-Z", "trap-unreachable=no", + #"-C", "no-vectorize-loops", + "-C", "force-frame-pointers=yes", +] + +[build] +target = "thumbv7em-none-eabi" + +[env] +DEFMT_LOG = "trace" diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml new file mode 100644 index 000000000..8eb98623c --- /dev/null +++ b/examples/boot/bootloader/nrf/Cargo.toml @@ -0,0 +1,58 @@ +[package] +edition = "2021" +name = "nrf-bootloader-example" +version = "0.1.0" +description = "Bootloader for nRF chips" + +[dependencies] +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } + +embassy = { path = "../../../../embassy", default-features = false } +embassy-nrf = { path = "../../../../embassy-nrf", default-features = false, features = ["nightly"] } +embassy-boot-nrf = { path = "../../../../embassy-boot/nrf", default-features = false } +cortex-m = { version = "0.7" } +cortex-m-rt = { version = "0.7" } +cfg-if = "1.0.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-boot-nrf/defmt", + "embassy-nrf/defmt", +] +softdevice = [ + "embassy-boot-nrf/softdevice", +] +debug = ["defmt-rtt"] + +[profile.dev] +debug = 2 +debug-assertions = true +incremental = false +opt-level = 'z' +overflow-checks = true + +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false +incremental = false +lto = 'fat' +opt-level = 'z' +overflow-checks = false + +# do not optimize proc-macro crates = faster builds from scratch +[profile.dev.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false + +[profile.release.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false diff --git a/examples/boot/bootloader/nrf/README.md b/examples/boot/bootloader/nrf/README.md new file mode 100644 index 000000000..23497a038 --- /dev/null +++ b/examples/boot/bootloader/nrf/README.md @@ -0,0 +1,11 @@ +# Bootloader for nRF + +The bootloader uses `embassy-boot` to interact with the flash. + +# Usage + +Flash the bootloader + +``` +cargo flash --features embassy-nrf/nrf52832 --release --chip nRF52832_xxAA +``` diff --git a/examples/boot/bootloader/nrf/build.rs b/examples/boot/bootloader/nrf/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/bootloader/nrf/build.rs @@ -0,0 +1,37 @@ +//! This build script copies the `memory.x` file from the crate root into +//! a directory where the linker can always find it at build time. +//! For many projects this is optional, as the linker always searches the +//! project root directory -- wherever `Cargo.toml` is. However, if you +//! are using a workspace or have a more complicated build setup, this +//! build script becomes required. Additionally, by requesting that +//! Cargo re-run the build script whenever `memory.x` is changed, +//! updating `memory.x` ensures a rebuild of the application with the +//! new memory settings. + +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } +} diff --git a/examples/boot/bootloader/nrf/memory-bm.x b/examples/boot/bootloader/nrf/memory-bm.x new file mode 100644 index 000000000..8a32b905f --- /dev/null +++ b/examples/boot/bootloader/nrf/memory-bm.x @@ -0,0 +1,18 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x00000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K + ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K + DFU : ORIGIN = 0x00017000, LENGTH = 68K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); + +__bootloader_active_start = ORIGIN(ACTIVE); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); + +__bootloader_dfu_start = ORIGIN(DFU); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/bootloader/nrf/memory-s140.x b/examples/boot/bootloader/nrf/memory-s140.x new file mode 100644 index 000000000..105db9972 --- /dev/null +++ b/examples/boot/bootloader/nrf/memory-s140.x @@ -0,0 +1,31 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + MBR : ORIGIN = 0x00000000, LENGTH = 4K + SOFTDEVICE : ORIGIN = 0x00001000, LENGTH = 155648 + ACTIVE : ORIGIN = 0x00027000, LENGTH = 425984 + DFU : ORIGIN = 0x0008F000, LENGTH = 430080 + FLASH : ORIGIN = 0x000f9000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x000ff000, LENGTH = 4K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x2fff8 + uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4 +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); + +__bootloader_active_start = ORIGIN(ACTIVE); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); + +__bootloader_dfu_start = ORIGIN(DFU); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); + +__bootloader_start = ORIGIN(FLASH); + +SECTIONS +{ + .uicr_bootloader_start_address : + { + LONG(__bootloader_start) + } > uicr_bootloader_start_address +} diff --git a/examples/boot/bootloader/nrf/memory.x b/examples/boot/bootloader/nrf/memory.x new file mode 100644 index 000000000..8a32b905f --- /dev/null +++ b/examples/boot/bootloader/nrf/memory.x @@ -0,0 +1,18 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x00000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K + ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K + DFU : ORIGIN = 0x00017000, LENGTH = 68K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); + +__bootloader_active_start = ORIGIN(ACTIVE); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); + +__bootloader_dfu_start = ORIGIN(DFU); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs new file mode 100644 index 000000000..bc7e0755f --- /dev/null +++ b/examples/boot/bootloader/nrf/src/main.rs @@ -0,0 +1,48 @@ +#![no_std] +#![no_main] + +use cortex_m_rt::{entry, exception}; +#[cfg(feature = "defmt")] +use defmt_rtt as _; +use embassy_boot_nrf::*; +use embassy_nrf::nvmc::Nvmc; + +#[entry] +fn main() -> ! { + let p = embassy_nrf::init(Default::default()); + + // Uncomment this if you are debugging the bootloader with debugger/RTT attached, + // as it prevents a hard fault when accessing flash 'too early' after boot. + /* + for i in 0..10000000 { + cortex_m::asm::nop(); + } + */ + + let mut bl = BootLoader::default(); + let start = bl.prepare(&mut SingleFlashProvider::new(&mut WatchdogFlash::start( + Nvmc::new(p.NVMC), + p.WDT, + 5, + ))); + unsafe { bl.load(start) } +} + +#[no_mangle] +#[cfg_attr(target_os = "none", link_section = ".HardFault.user")] +unsafe extern "C" fn HardFault() { + cortex_m::peripheral::SCB::sys_reset(); +} + +#[exception] +unsafe fn DefaultHandler(_: i16) -> ! { + const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; + let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; + + panic!("DefaultHandler #{:?}", irqn); +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + cortex_m::asm::udf(); +} diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml new file mode 100644 index 000000000..b99a8fbcd --- /dev/null +++ b/examples/boot/bootloader/stm32/Cargo.toml @@ -0,0 +1,57 @@ +[package] +edition = "2021" +name = "stm32-bootloader-example" +version = "0.1.0" +description = "Example bootloader for STM32 chips" + +[dependencies] +defmt = { version = "0.3", optional = true } +defmt-rtt = { version = "0.3", optional = true } + +embassy = { path = "../../../../embassy", default-features = false } +embassy-stm32 = { path = "../../../../embassy-stm32", default-features = false, features = ["nightly"] } +embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32", default-features = false } +cortex-m = { version = "0.7" } +cortex-m-rt = { version = "0.7" } +embedded-storage = "0.3.0" +embedded-storage-async = "0.3.0" +cfg-if = "1.0.0" + +[features] +defmt = [ + "dep:defmt", + "embassy-boot-stm32/defmt", + "embassy-stm32/defmt", +] +debug = ["defmt-rtt"] + +[profile.dev] +debug = 2 +debug-assertions = true +incremental = false +opt-level = 'z' +overflow-checks = true + +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false +incremental = false +lto = 'fat' +opt-level = 'z' +overflow-checks = false + +# do not optimize proc-macro crates = faster builds from scratch +[profile.dev.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false + +[profile.release.build-override] +codegen-units = 8 +debug = false +debug-assertions = false +opt-level = 0 +overflow-checks = false diff --git a/examples/boot/bootloader/stm32/README.md b/examples/boot/bootloader/stm32/README.md new file mode 100644 index 000000000..a82b730b9 --- /dev/null +++ b/examples/boot/bootloader/stm32/README.md @@ -0,0 +1,11 @@ +# Bootloader for STM32 + +The bootloader uses `embassy-boot` to interact with the flash. + +# Usage + +Flash the bootloader + +``` +cargo flash --features embassy-stm32/stm32wl55jc-cm4 --release --chip STM32WLE5JCIx +``` diff --git a/examples/boot/bootloader/stm32/build.rs b/examples/boot/bootloader/stm32/build.rs new file mode 100644 index 000000000..3997702f6 --- /dev/null +++ b/examples/boot/bootloader/stm32/build.rs @@ -0,0 +1,32 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put `memory.x` in our output directory and ensure it's + // on the linker search path. + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + // By default, Cargo will re-run a build script whenever + // any file in the project changes. By specifying `memory.x` + // here, we ensure the build script is only re-run when + // `memory.x` is changed. + println!("cargo:rerun-if-changed=memory.x"); + + println!("cargo:rustc-link-arg-bins=--nmagic"); + println!("cargo:rustc-link-arg-bins=-Tlink.x"); + if env::var("CARGO_FEATURE_DEFMT").is_ok() { + println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + } + + let target = env::var("TARGET").unwrap(); + if target.starts_with("thumbv6m-") { + println!("cargo:rustc-cfg=armv6m"); + } +} diff --git a/examples/boot/bootloader/stm32/memory.x b/examples/boot/bootloader/stm32/memory.x new file mode 100644 index 000000000..110c23259 --- /dev/null +++ b/examples/boot/bootloader/stm32/memory.x @@ -0,0 +1,18 @@ +MEMORY +{ + /* NOTE 1 K = 1 KiBi = 1024 bytes */ + FLASH : ORIGIN = 0x08000000, LENGTH = 24K + BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K + ACTIVE : ORIGIN = 0x08008000, LENGTH = 32K + DFU : ORIGIN = 0x08010000, LENGTH = 36K + RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K +} + +__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); +__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); + +__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); +__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); + +__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); +__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs new file mode 100644 index 000000000..45c511ced --- /dev/null +++ b/examples/boot/bootloader/stm32/src/main.rs @@ -0,0 +1,46 @@ +#![no_std] +#![no_main] + +use cortex_m_rt::{entry, exception}; +#[cfg(feature = "defmt")] +use defmt_rtt as _; +use embassy_boot_stm32::*; +use embassy_stm32::flash::{Flash, ERASE_SIZE}; + +#[entry] +fn main() -> ! { + let p = embassy_stm32::init(Default::default()); + + // Uncomment this if you are debugging the bootloader with debugger/RTT attached, + // as it prevents a hard fault when accessing flash 'too early' after boot. + /* + for i in 0..10000000 { + cortex_m::asm::nop(); + } + */ + + let mut bl: BootLoader = BootLoader::default(); + let mut flash = Flash::unlock(p.FLASH); + let start = bl.prepare(&mut SingleFlashProvider::new(&mut flash)); + core::mem::drop(flash); + unsafe { bl.load(start) } +} + +#[no_mangle] +#[cfg_attr(target_os = "none", link_section = ".HardFault.user")] +unsafe extern "C" fn HardFault() { + cortex_m::peripheral::SCB::sys_reset(); +} + +#[exception] +unsafe fn DefaultHandler(_: i16) -> ! { + const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; + let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; + + panic!("DefaultHandler #{:?}", irqn); +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + cortex_m::asm::udf(); +} diff --git a/examples/boot/nrf/.cargo/config.toml b/examples/boot/nrf/.cargo/config.toml deleted file mode 100644 index 8ca28df39..000000000 --- a/examples/boot/nrf/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip nRF52840_xxAA" - -[build] -target = "thumbv7em-none-eabi" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/nrf/Cargo.toml b/examples/boot/nrf/Cargo.toml deleted file mode 100644 index 0a0b76e67..000000000 --- a/examples/boot/nrf/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-nrf-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] } -embassy-nrf = { version = "0.1.0", path = "../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } -embassy-boot-nrf = { version = "0.1.0", path = "../../../embassy-boot/nrf" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" diff --git a/examples/boot/nrf/README.md b/examples/boot/nrf/README.md deleted file mode 100644 index 1f25ffc05..000000000 --- a/examples/boot/nrf/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# Examples using bootloader - -Example for nRF52 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-nrf` - -## Usage - - - -``` -# Use bare metal linker script -cp memory-bl.x ../../../embassy-boot/nrf/memory.x - -# Flash bootloader -cargo flash --manifest-path ../../../embassy-boot/nrf/Cargo.toml --features embassy-nrf/nrf52840 --release --chip nRF52840_xxAA -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip nRF52840_xxAA -``` diff --git a/examples/boot/nrf/build.rs b/examples/boot/nrf/build.rs deleted file mode 100644 index cd1a264c4..000000000 --- a/examples/boot/nrf/build.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); -} diff --git a/examples/boot/nrf/memory-bl.x b/examples/boot/nrf/memory-bl.x deleted file mode 100644 index 8a32b905f..000000000 --- a/examples/boot/nrf/memory-bl.x +++ /dev/null @@ -1,18 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - FLASH : ORIGIN = 0x00000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K - ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K - DFU : ORIGIN = 0x00017000, LENGTH = 68K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); - -__bootloader_active_start = ORIGIN(ACTIVE); -__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); - -__bootloader_dfu_start = ORIGIN(DFU); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/nrf/memory.x b/examples/boot/nrf/memory.x deleted file mode 100644 index 3a54ca460..000000000 --- a/examples/boot/nrf/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x00000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K - FLASH : ORIGIN = 0x00007000, LENGTH = 64K - DFU : ORIGIN = 0x00017000, LENGTH = 68K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); - -__bootloader_dfu_start = ORIGIN(DFU); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/nrf/src/bin/a.rs b/examples/boot/nrf/src/bin/a.rs deleted file mode 100644 index 0b9715e49..000000000 --- a/examples/boot/nrf/src/bin/a.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![no_std] -#![no_main] -#![macro_use] -#![feature(generic_associated_types)] -#![feature(type_alias_impl_trait)] - -use embassy_boot_nrf::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; -use embassy_nrf::nvmc::Nvmc; -use embassy_nrf::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let mut button = Input::new(p.P0_11, Pull::Up); - let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); - //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); - //let mut button = Input::new(p.P1_02, Pull::Up); - - let nvmc = Nvmc::new(p.NVMC); - let mut nvmc = BlockingAsync::new(nvmc); - - let mut updater = FirmwareUpdater::default(); - loop { - led.set_low(); - button.wait_for_any_edge().await; - if button.is_low() { - let mut offset = 0; - for chunk in APP_B.chunks(4096) { - let mut buf: [u8; 4096] = [0; 4096]; - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); - offset += chunk.len(); - } - updater.update(&mut nvmc).await.unwrap(); - led.set_high(); - cortex_m::peripheral::SCB::sys_reset(); - } - } -} diff --git a/examples/boot/nrf/src/bin/b.rs b/examples/boot/nrf/src/bin/b.rs deleted file mode 100644 index a06c20f8b..000000000 --- a/examples/boot/nrf/src/bin/b.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![no_std] -#![no_main] -#![macro_use] -#![feature(generic_associated_types)] -#![feature(type_alias_impl_trait)] - -use embassy::time::{Duration, Timer}; -use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); - //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(300)).await; - led.set_low(); - Timer::after(Duration::from_millis(300)).await; - } -} diff --git a/examples/boot/stm32f3/.cargo/config.toml b/examples/boot/stm32f3/.cargo/config.toml deleted file mode 100644 index a76d6cab4..000000000 --- a/examples/boot/stm32f3/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32F303VCTx" - -[build] -target = "thumbv7em-none-eabihf" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/stm32f3/Cargo.toml b/examples/boot/stm32f3/Cargo.toml deleted file mode 100644 index 017813691..000000000 --- a/examples/boot/stm32f3/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-stm32f3-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly", "time-tick-32768hz"] } -embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] } -embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" - -[features] -defmt = [ - "dep:defmt", - "embassy-stm32/defmt", - "embassy-boot-stm32/defmt", -] diff --git a/examples/boot/stm32f3/README.md b/examples/boot/stm32f3/README.md deleted file mode 100644 index e92ffb692..000000000 --- a/examples/boot/stm32f3/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Examples using bootloader - -Example for STM32F3 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-stm32` - -## Usage - -``` -# Flash bootloader -cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f303re --chip STM32F303RETx -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip STM32F303RETx -``` diff --git a/examples/boot/stm32f3/build.rs b/examples/boot/stm32f3/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/examples/boot/stm32f3/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); - if env::var("CARGO_FEATURE_DEFMT").is_ok() { - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); - } -} diff --git a/examples/boot/stm32f3/memory.x b/examples/boot/stm32f3/memory.x deleted file mode 100644 index 14b2a2c9f..000000000 --- a/examples/boot/stm32f3/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K - FLASH : ORIGIN = 0x08008000, LENGTH = 32K - DFU : ORIGIN = 0x08010000, LENGTH = 36K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/stm32f3/src/bin/a.rs b/examples/boot/stm32f3/src/bin/a.rs deleted file mode 100644 index 4ff18d7c7..000000000 --- a/examples/boot/stm32f3/src/bin/a.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy_boot_stm32::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_stm32::exti::ExtiInput; -use embassy_stm32::flash::Flash; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let flash = Flash::unlock(p.FLASH); - let mut flash = BlockingAsync::new(flash); - - let button = Input::new(p.PC13, Pull::Up); - let mut button = ExtiInput::new(button, p.EXTI13); - - let mut led = Output::new(p.PA5, Level::Low, Speed::Low); - led.set_high(); - - let mut updater = FirmwareUpdater::default(); - button.wait_for_falling_edge().await; - let mut offset = 0; - for chunk in APP_B.chunks(2048) { - let mut buf: [u8; 2048] = [0; 2048]; - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); - offset += chunk.len(); - } - updater.update(&mut flash).await.unwrap(); - led.set_low(); - cortex_m::peripheral::SCB::sys_reset(); -} diff --git a/examples/boot/stm32f3/src/bin/b.rs b/examples/boot/stm32f3/src/bin/b.rs deleted file mode 100644 index 4487e586e..000000000 --- a/examples/boot/stm32f3/src/bin/b.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { - let mut led = Output::new(p.PA5, Level::High, Speed::Low); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/examples/boot/stm32f7/.cargo/config.toml b/examples/boot/stm32f7/.cargo/config.toml deleted file mode 100644 index a90e1ccbb..000000000 --- a/examples/boot/stm32f7/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32F767ZITx -v" - -[build] -target = "thumbv7em-none-eabihf" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/stm32f7/Cargo.toml b/examples/boot/stm32f7/Cargo.toml deleted file mode 100644 index 07aa73892..000000000 --- a/examples/boot/stm32f7/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-stm32f7-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly", "time-tick-32768hz"] } -embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] } -embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" - -[features] -defmt = [ - "dep:defmt", - "embassy-stm32/defmt", - "embassy-boot-stm32/defmt", -] diff --git a/examples/boot/stm32f7/README.md b/examples/boot/stm32f7/README.md deleted file mode 100644 index bf9142a1c..000000000 --- a/examples/boot/stm32f7/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Examples using bootloader - -Example for STM32F7 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-stm32` - -## Usage - -``` -# Flash bootloader -./flash-boot.sh -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip STM32F767ZITx -``` diff --git a/examples/boot/stm32f7/build.rs b/examples/boot/stm32f7/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/examples/boot/stm32f7/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); - if env::var("CARGO_FEATURE_DEFMT").is_ok() { - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); - } -} diff --git a/examples/boot/stm32f7/flash-boot.sh b/examples/boot/stm32f7/flash-boot.sh deleted file mode 100755 index 86074ffa3..000000000 --- a/examples/boot/stm32f7/flash-boot.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -mv ../../../embassy-boot/stm32/memory.x ../../../embassy-boot/stm32/memory-old.x -cp memory-bl.x ../../../embassy-boot/stm32/memory.x - -cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf - -rm ../../../embassy-boot/stm32/memory.x -mv ../../../embassy-boot/stm32/memory-old.x ../../../embassy-boot/stm32/memory.x diff --git a/examples/boot/stm32f7/memory-bl.x b/examples/boot/stm32f7/memory-bl.x deleted file mode 100644 index 47f3f4d9b..000000000 --- a/examples/boot/stm32f7/memory-bl.x +++ /dev/null @@ -1,18 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - FLASH : ORIGIN = 0x08000000, LENGTH = 256K - BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K - ACTIVE : ORIGIN = 0x08080000, LENGTH = 256K - DFU : ORIGIN = 0x080c0000, LENGTH = 512K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 368K + 16K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); - -__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); -__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); diff --git a/examples/boot/stm32f7/memory.x b/examples/boot/stm32f7/memory.x deleted file mode 100644 index 1c5537d17..000000000 --- a/examples/boot/stm32f7/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 256K - BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K - FLASH : ORIGIN = 0x08080000, LENGTH = 256K - DFU : ORIGIN = 0x080c0000, LENGTH = 512K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 368K + 16K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/stm32f7/src/bin/a.rs b/examples/boot/stm32f7/src/bin/a.rs deleted file mode 100644 index 9c7921a1a..000000000 --- a/examples/boot/stm32f7/src/bin/a.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy_boot_stm32::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_stm32::exti::ExtiInput; -use embassy_stm32::flash::Flash; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let flash = Flash::unlock(p.FLASH); - let mut flash = BlockingAsync::new(flash); - - let button = Input::new(p.PC13, Pull::Down); - let mut button = ExtiInput::new(button, p.EXTI13); - - let mut led = Output::new(p.PB7, Level::Low, Speed::Low); - led.set_high(); - - let mut updater = FirmwareUpdater::default(); - button.wait_for_rising_edge().await; - let mut offset = 0; - let mut buf: [u8; 256 * 1024] = [0; 256 * 1024]; - for chunk in APP_B.chunks(256 * 1024) { - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); - offset += chunk.len(); - } - updater.update(&mut flash).await.unwrap(); - led.set_low(); - cortex_m::peripheral::SCB::sys_reset(); -} diff --git a/examples/boot/stm32f7/src/bin/b.rs b/examples/boot/stm32f7/src/bin/b.rs deleted file mode 100644 index aa05bbcdd..000000000 --- a/examples/boot/stm32f7/src/bin/b.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { - Timer::after(Duration::from_millis(300)).await; - let mut led = Output::new(p.PB7, Level::High, Speed::Low); - led.set_high(); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/examples/boot/stm32h7/.cargo/config.toml b/examples/boot/stm32h7/.cargo/config.toml deleted file mode 100644 index fefdd370e..000000000 --- a/examples/boot/stm32h7/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32H743ZITx" - -[build] -target = "thumbv7em-none-eabihf" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/stm32h7/Cargo.toml b/examples/boot/stm32h7/Cargo.toml deleted file mode 100644 index d47cb65cc..000000000 --- a/examples/boot/stm32h7/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-stm32f7-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly", "time-tick-32768hz"] } -embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } -embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" - -[features] -defmt = [ - "dep:defmt", - "embassy-stm32/defmt", - "embassy-boot-stm32/defmt", -] diff --git a/examples/boot/stm32h7/README.md b/examples/boot/stm32h7/README.md deleted file mode 100644 index 1fdc305e6..000000000 --- a/examples/boot/stm32h7/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Examples using bootloader - -Example for STM32H7 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-stm32` - -## Usage - -``` -# Flash bootloader -./flash-boot.sh -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip STM32H743ZITx -``` diff --git a/examples/boot/stm32h7/build.rs b/examples/boot/stm32h7/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/examples/boot/stm32h7/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); - if env::var("CARGO_FEATURE_DEFMT").is_ok() { - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); - } -} diff --git a/examples/boot/stm32h7/flash-boot.sh b/examples/boot/stm32h7/flash-boot.sh deleted file mode 100755 index a910b7312..000000000 --- a/examples/boot/stm32h7/flash-boot.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -mv ../../../embassy-boot/stm32/memory.x ../../../embassy-boot/stm32/memory-old.x -cp memory-bl.x ../../../embassy-boot/stm32/memory.x - -cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32H743ZITx --target thumbv7em-none-eabihf - -rm ../../../embassy-boot/stm32/memory.x -mv ../../../embassy-boot/stm32/memory-old.x ../../../embassy-boot/stm32/memory.x diff --git a/examples/boot/stm32h7/memory-bl.x b/examples/boot/stm32h7/memory-bl.x deleted file mode 100644 index c6f447d8b..000000000 --- a/examples/boot/stm32h7/memory-bl.x +++ /dev/null @@ -1,18 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - FLASH : ORIGIN = 0x08000000, LENGTH = 128K - BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K - ACTIVE : ORIGIN = 0x08040000, LENGTH = 128K - DFU : ORIGIN = 0x08100000, LENGTH = 512K - RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); - -__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); -__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); diff --git a/examples/boot/stm32h7/memory.x b/examples/boot/stm32h7/memory.x deleted file mode 100644 index 497a09e41..000000000 --- a/examples/boot/stm32h7/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 128K - BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K - FLASH : ORIGIN = 0x08040000, LENGTH = 256K - DFU : ORIGIN = 0x08100000, LENGTH = 512K - RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/stm32h7/src/bin/a.rs b/examples/boot/stm32h7/src/bin/a.rs deleted file mode 100644 index 704979dba..000000000 --- a/examples/boot/stm32h7/src/bin/a.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy_boot_stm32::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_stm32::exti::ExtiInput; -use embassy_stm32::flash::Flash; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let flash = Flash::unlock(p.FLASH); - let mut flash = BlockingAsync::new(flash); - - let button = Input::new(p.PC13, Pull::Down); - let mut button = ExtiInput::new(button, p.EXTI13); - - let mut led = Output::new(p.PB14, Level::Low, Speed::Low); - led.set_high(); - - let mut updater = FirmwareUpdater::default(); - button.wait_for_rising_edge().await; - let mut offset = 0; - let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; - for chunk in APP_B.chunks(128 * 1024) { - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); - offset += chunk.len(); - } - updater.update(&mut flash).await.unwrap(); - led.set_low(); - cortex_m::peripheral::SCB::sys_reset(); -} diff --git a/examples/boot/stm32h7/src/bin/b.rs b/examples/boot/stm32h7/src/bin/b.rs deleted file mode 100644 index ea0140253..000000000 --- a/examples/boot/stm32h7/src/bin/b.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { - Timer::after(Duration::from_millis(300)).await; - let mut led = Output::new(p.PB14, Level::High, Speed::Low); - led.set_high(); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/examples/boot/stm32l0/.cargo/config.toml b/examples/boot/stm32l0/.cargo/config.toml deleted file mode 100644 index 2627967ab..000000000 --- a/examples/boot/stm32l0/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32L072CZTx" - -[build] -target = "thumbv6m-none-eabi" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/stm32l0/Cargo.toml b/examples/boot/stm32l0/Cargo.toml deleted file mode 100644 index fbc4fb711..000000000 --- a/examples/boot/stm32l0/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-stm32l0-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly", "time-tick-32768hz"] } -embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] } -embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" - -[features] -defmt = [ - "dep:defmt", - "embassy-stm32/defmt", - "embassy-boot-stm32/defmt", -] diff --git a/examples/boot/stm32l0/README.md b/examples/boot/stm32l0/README.md deleted file mode 100644 index a0e8021fc..000000000 --- a/examples/boot/stm32l0/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Examples using bootloader - -Example for STM32L0 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-stm32` - -## Usage - -``` -# Flash bootloader -cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32l072cz --chip STM32L072CZTx -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip STM32L072CZTx -``` diff --git a/examples/boot/stm32l0/build.rs b/examples/boot/stm32l0/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/examples/boot/stm32l0/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); - if env::var("CARGO_FEATURE_DEFMT").is_ok() { - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); - } -} diff --git a/examples/boot/stm32l0/memory.x b/examples/boot/stm32l0/memory.x deleted file mode 100644 index d0d2bd7bb..000000000 --- a/examples/boot/stm32l0/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K - FLASH : ORIGIN = 0x08008000, LENGTH = 32K - DFU : ORIGIN = 0x08010000, LENGTH = 36K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/stm32l0/src/bin/a.rs b/examples/boot/stm32l0/src/bin/a.rs deleted file mode 100644 index ce620347b..000000000 --- a/examples/boot/stm32l0/src/bin/a.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::time::{Duration, Timer}; -use embassy_boot_stm32::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_stm32::exti::ExtiInput; -use embassy_stm32::flash::Flash; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let flash = Flash::unlock(p.FLASH); - let mut flash = BlockingAsync::new(flash); - - let button = Input::new(p.PB2, Pull::Up); - let mut button = ExtiInput::new(button, p.EXTI2); - - let mut led = Output::new(p.PB5, Level::Low, Speed::Low); - - led.set_high(); - - let mut updater = FirmwareUpdater::default(); - button.wait_for_falling_edge().await; - let mut offset = 0; - for chunk in APP_B.chunks(128) { - let mut buf: [u8; 128] = [0; 128]; - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); - offset += chunk.len(); - } - - updater.update(&mut flash).await.unwrap(); - led.set_low(); - Timer::after(Duration::from_secs(1)).await; - cortex_m::peripheral::SCB::sys_reset(); -} diff --git a/examples/boot/stm32l0/src/bin/b.rs b/examples/boot/stm32l0/src/bin/b.rs deleted file mode 100644 index 0b585a14c..000000000 --- a/examples/boot/stm32l0/src/bin/b.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { - let mut led = Output::new(p.PB6, Level::High, Speed::Low); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/examples/boot/stm32l1/.cargo/config.toml b/examples/boot/stm32l1/.cargo/config.toml deleted file mode 100644 index 404b6b55c..000000000 --- a/examples/boot/stm32l1/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32L151CBxxA" - -[build] -target = "thumbv7m-none-eabi" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/stm32l1/Cargo.toml b/examples/boot/stm32l1/Cargo.toml deleted file mode 100644 index f3f05f611..000000000 --- a/examples/boot/stm32l1/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-stm32l1-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly", "time-tick-32768hz"] } -embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] } -embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" - -[features] -defmt = [ - "dep:defmt", - "embassy-stm32/defmt", - "embassy-boot-stm32/defmt", -] diff --git a/examples/boot/stm32l1/README.md b/examples/boot/stm32l1/README.md deleted file mode 100644 index 0d4accbff..000000000 --- a/examples/boot/stm32l1/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Examples using bootloader - -Example for STM32L1 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-stm32` - -## Usage - -``` -# Flash bootloader -cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32l151cb-a --chip STM32L151CBxxA -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip STM32L151CBxxA -``` diff --git a/examples/boot/stm32l1/build.rs b/examples/boot/stm32l1/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/examples/boot/stm32l1/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); - if env::var("CARGO_FEATURE_DEFMT").is_ok() { - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); - } -} diff --git a/examples/boot/stm32l1/memory.x b/examples/boot/stm32l1/memory.x deleted file mode 100644 index d0d2bd7bb..000000000 --- a/examples/boot/stm32l1/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K - FLASH : ORIGIN = 0x08008000, LENGTH = 32K - DFU : ORIGIN = 0x08010000, LENGTH = 36K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/stm32l1/src/bin/a.rs b/examples/boot/stm32l1/src/bin/a.rs deleted file mode 100644 index ce620347b..000000000 --- a/examples/boot/stm32l1/src/bin/a.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::time::{Duration, Timer}; -use embassy_boot_stm32::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_stm32::exti::ExtiInput; -use embassy_stm32::flash::Flash; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let flash = Flash::unlock(p.FLASH); - let mut flash = BlockingAsync::new(flash); - - let button = Input::new(p.PB2, Pull::Up); - let mut button = ExtiInput::new(button, p.EXTI2); - - let mut led = Output::new(p.PB5, Level::Low, Speed::Low); - - led.set_high(); - - let mut updater = FirmwareUpdater::default(); - button.wait_for_falling_edge().await; - let mut offset = 0; - for chunk in APP_B.chunks(128) { - let mut buf: [u8; 128] = [0; 128]; - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); - offset += chunk.len(); - } - - updater.update(&mut flash).await.unwrap(); - led.set_low(); - Timer::after(Duration::from_secs(1)).await; - cortex_m::peripheral::SCB::sys_reset(); -} diff --git a/examples/boot/stm32l1/src/bin/b.rs b/examples/boot/stm32l1/src/bin/b.rs deleted file mode 100644 index 0b585a14c..000000000 --- a/examples/boot/stm32l1/src/bin/b.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { - let mut led = Output::new(p.PB6, Level::High, Speed::Low); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/examples/boot/stm32l4/.cargo/config.toml b/examples/boot/stm32l4/.cargo/config.toml deleted file mode 100644 index 43520e323..000000000 --- a/examples/boot/stm32l4/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32L475VG" - -[build] -target = "thumbv7em-none-eabihf" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/stm32l4/Cargo.toml b/examples/boot/stm32l4/Cargo.toml deleted file mode 100644 index 1b7b2202f..000000000 --- a/examples/boot/stm32l4/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-stm32l4-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly", "time-tick-32768hz"] } -embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] } -embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" - -[features] -defmt = [ - "dep:defmt", - "embassy-stm32/defmt", - "embassy-boot-stm32/defmt", -] diff --git a/examples/boot/stm32l4/README.md b/examples/boot/stm32l4/README.md deleted file mode 100644 index 8966c2fb5..000000000 --- a/examples/boot/stm32l4/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Examples using bootloader - -Example for STM32L4 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-stm32` - -## Usage - -``` -# Flash bootloader -cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32l475vg --chip STM32L475VG -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip STM32L475VG -``` diff --git a/examples/boot/stm32l4/build.rs b/examples/boot/stm32l4/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/examples/boot/stm32l4/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); - if env::var("CARGO_FEATURE_DEFMT").is_ok() { - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); - } -} diff --git a/examples/boot/stm32l4/memory.x b/examples/boot/stm32l4/memory.x deleted file mode 100644 index 14b2a2c9f..000000000 --- a/examples/boot/stm32l4/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K - FLASH : ORIGIN = 0x08008000, LENGTH = 32K - DFU : ORIGIN = 0x08010000, LENGTH = 36K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/stm32l4/src/bin/a.rs b/examples/boot/stm32l4/src/bin/a.rs deleted file mode 100644 index bf6099355..000000000 --- a/examples/boot/stm32l4/src/bin/a.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy_boot_stm32::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_stm32::exti::ExtiInput; -use embassy_stm32::flash::Flash; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let flash = Flash::unlock(p.FLASH); - let mut flash = BlockingAsync::new(flash); - - let button = Input::new(p.PC13, Pull::Up); - let mut button = ExtiInput::new(button, p.EXTI13); - - let mut led = Output::new(p.PB14, Level::Low, Speed::Low); - led.set_high(); - - let mut updater = FirmwareUpdater::default(); - button.wait_for_falling_edge().await; - let mut offset = 0; - for chunk in APP_B.chunks(2048) { - let mut buf: [u8; 2048] = [0; 2048]; - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); - offset += chunk.len(); - } - updater.update(&mut flash).await.unwrap(); - led.set_low(); - cortex_m::peripheral::SCB::sys_reset(); -} diff --git a/examples/boot/stm32l4/src/bin/b.rs b/examples/boot/stm32l4/src/bin/b.rs deleted file mode 100644 index 4487e586e..000000000 --- a/examples/boot/stm32l4/src/bin/b.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { - let mut led = Output::new(p.PA5, Level::High, Speed::Low); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/examples/boot/stm32wl/.cargo/config.toml b/examples/boot/stm32wl/.cargo/config.toml deleted file mode 100644 index e395d75b4..000000000 --- a/examples/boot/stm32wl/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32WLE5JCIx" - -[build] -target = "thumbv7em-none-eabihf" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/stm32wl/Cargo.toml b/examples/boot/stm32wl/Cargo.toml deleted file mode 100644 index 1bd69ae42..000000000 --- a/examples/boot/stm32wl/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-stm32wl-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly", "time-tick-32768hz"] } -embassy-stm32 = { version = "0.1.0", path = "../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] } -embassy-boot-stm32 = { version = "0.1.0", path = "../../../embassy-boot/stm32" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" - -[features] -defmt = [ - "dep:defmt", - "embassy-stm32/defmt", - "embassy-boot-stm32/defmt", -] diff --git a/examples/boot/stm32wl/README.md b/examples/boot/stm32wl/README.md deleted file mode 100644 index edcdacf91..000000000 --- a/examples/boot/stm32wl/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Examples using bootloader - -Example for STM32WL demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-stm32` - -## Usage - -``` -# Flash bootloader -cargo flash --manifest-path ../../../embassy-boot/stm32/Cargo.toml --release --features embassy-stm32/stm32wl55jc-cm4 --chip STM32WLE5JCIx -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip STM32WLE5JCIx -``` diff --git a/examples/boot/stm32wl/build.rs b/examples/boot/stm32wl/build.rs deleted file mode 100644 index e1da69328..000000000 --- a/examples/boot/stm32wl/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); - if env::var("CARGO_FEATURE_DEFMT").is_ok() { - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); - } -} diff --git a/examples/boot/stm32wl/memory.x b/examples/boot/stm32wl/memory.x deleted file mode 100644 index 14b2a2c9f..000000000 --- a/examples/boot/stm32wl/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K - FLASH : ORIGIN = 0x08008000, LENGTH = 32K - DFU : ORIGIN = 0x08010000, LENGTH = 36K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); - -__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); diff --git a/examples/boot/stm32wl/src/bin/a.rs b/examples/boot/stm32wl/src/bin/a.rs deleted file mode 100644 index dc1eb9bed..000000000 --- a/examples/boot/stm32wl/src/bin/a.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy_boot_stm32::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_stm32::exti::ExtiInput; -use embassy_stm32::flash::Flash; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let flash = Flash::unlock(p.FLASH); - let mut flash = BlockingAsync::new(flash); - - let button = Input::new(p.PA0, Pull::Up); - let mut button = ExtiInput::new(button, p.EXTI0); - - let mut led = Output::new(p.PB9, Level::Low, Speed::Low); - led.set_high(); - - let mut updater = FirmwareUpdater::default(); - button.wait_for_falling_edge().await; - //defmt::info!("Starting update"); - let mut offset = 0; - for chunk in APP_B.chunks(2048) { - let mut buf: [u8; 2048] = [0; 2048]; - buf[..chunk.len()].copy_from_slice(chunk); - // defmt::info!("Writing chunk at 0x{:x}", offset); - updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); - offset += chunk.len(); - } - updater.update(&mut flash).await.unwrap(); - //defmt::info!("Marked as updated"); - led.set_low(); - cortex_m::peripheral::SCB::sys_reset(); -} diff --git a/examples/boot/stm32wl/src/bin/b.rs b/examples/boot/stm32wl/src/bin/b.rs deleted file mode 100644 index f2344bd53..000000000 --- a/examples/boot/stm32wl/src/bin/b.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; -use embassy::executor::Spawner; -use embassy::time::{Duration, Timer}; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embassy_stm32::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_spawner: Spawner, p: Peripherals) { - let mut led = Output::new(p.PB15, Level::High, Speed::Low); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(500)).await; - - led.set_low(); - Timer::after(Duration::from_millis(500)).await; - } -} -- cgit