aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/application
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-06-24 19:56:15 +0200
committerUlf Lilleengen <[email protected]>2022-06-24 19:56:15 +0200
commit776be79f7bb10b09e795e2ea93bb795a653c9b4c (patch)
tree269046d330ee503c84049bb8fc47baf0297ecb80 /examples/boot/application
parent84628d36cf743193cbf0e7d47ef1cfa9fb590890 (diff)
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.
Diffstat (limited to 'examples/boot/application')
-rw-r--r--examples/boot/application/nrf/.cargo/config.toml9
-rw-r--r--examples/boot/application/nrf/Cargo.toml18
-rw-r--r--examples/boot/application/nrf/README.md34
-rw-r--r--examples/boot/application/nrf/build.rs34
-rw-r--r--examples/boot/application/nrf/memory-bl.x18
-rw-r--r--examples/boot/application/nrf/memory.x15
-rw-r--r--examples/boot/application/nrf/src/bin/a.rs43
-rw-r--r--examples/boot/application/nrf/src/bin/b.rs23
-rw-r--r--examples/boot/application/stm32f3/.cargo/config.toml9
-rw-r--r--examples/boot/application/stm32f3/Cargo.toml25
-rw-r--r--examples/boot/application/stm32f3/README.md29
-rw-r--r--examples/boot/application/stm32f3/build.rs37
-rw-r--r--examples/boot/application/stm32f3/memory.x15
-rw-r--r--examples/boot/application/stm32f3/src/bin/a.rs40
-rw-r--r--examples/boot/application/stm32f3/src/bin/b.rs24
-rw-r--r--examples/boot/application/stm32f7/.cargo/config.toml9
-rw-r--r--examples/boot/application/stm32f7/Cargo.toml25
-rw-r--r--examples/boot/application/stm32f7/README.md29
-rw-r--r--examples/boot/application/stm32f7/build.rs37
-rwxr-xr-xexamples/boot/application/stm32f7/flash-boot.sh8
-rw-r--r--examples/boot/application/stm32f7/memory-bl.x18
-rw-r--r--examples/boot/application/stm32f7/memory.x15
-rw-r--r--examples/boot/application/stm32f7/src/bin/a.rs40
-rw-r--r--examples/boot/application/stm32f7/src/bin/b.rs26
-rw-r--r--examples/boot/application/stm32h7/.cargo/config.toml9
-rw-r--r--examples/boot/application/stm32h7/Cargo.toml25
-rw-r--r--examples/boot/application/stm32h7/README.md29
-rw-r--r--examples/boot/application/stm32h7/build.rs37
-rwxr-xr-xexamples/boot/application/stm32h7/flash-boot.sh8
-rw-r--r--examples/boot/application/stm32h7/memory-bl.x18
-rw-r--r--examples/boot/application/stm32h7/memory.x15
-rw-r--r--examples/boot/application/stm32h7/src/bin/a.rs40
-rw-r--r--examples/boot/application/stm32h7/src/bin/b.rs26
-rw-r--r--examples/boot/application/stm32l0/.cargo/config.toml9
-rw-r--r--examples/boot/application/stm32l0/Cargo.toml25
-rw-r--r--examples/boot/application/stm32l0/README.md29
-rw-r--r--examples/boot/application/stm32l0/build.rs37
-rw-r--r--examples/boot/application/stm32l0/memory.x15
-rw-r--r--examples/boot/application/stm32l0/src/bin/a.rs44
-rw-r--r--examples/boot/application/stm32l0/src/bin/b.rs24
-rw-r--r--examples/boot/application/stm32l1/.cargo/config.toml9
-rw-r--r--examples/boot/application/stm32l1/Cargo.toml25
-rw-r--r--examples/boot/application/stm32l1/README.md29
-rw-r--r--examples/boot/application/stm32l1/build.rs37
-rw-r--r--examples/boot/application/stm32l1/memory.x15
-rw-r--r--examples/boot/application/stm32l1/src/bin/a.rs44
-rw-r--r--examples/boot/application/stm32l1/src/bin/b.rs24
-rw-r--r--examples/boot/application/stm32l4/.cargo/config.toml9
-rw-r--r--examples/boot/application/stm32l4/Cargo.toml25
-rw-r--r--examples/boot/application/stm32l4/README.md29
-rw-r--r--examples/boot/application/stm32l4/build.rs37
-rw-r--r--examples/boot/application/stm32l4/memory.x15
-rw-r--r--examples/boot/application/stm32l4/src/bin/a.rs40
-rw-r--r--examples/boot/application/stm32l4/src/bin/b.rs24
-rw-r--r--examples/boot/application/stm32wl/.cargo/config.toml9
-rw-r--r--examples/boot/application/stm32wl/Cargo.toml25
-rw-r--r--examples/boot/application/stm32wl/README.md29
-rw-r--r--examples/boot/application/stm32wl/build.rs37
-rw-r--r--examples/boot/application/stm32wl/memory.x15
-rw-r--r--examples/boot/application/stm32wl/src/bin/a.rs43
-rw-r--r--examples/boot/application/stm32wl/src/bin/b.rs24
61 files changed, 1514 insertions, 0 deletions
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip nRF52840_xxAA"
4
5[build]
6target = "thumbv7em-none-eabi"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-nrf-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly"] }
8embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] }
9embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-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 @@
1# Examples using bootloader
2
3Example for nRF52 demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-nrf`
13
14## Usage
15
16
17
18```
19# Use bare metal linker script
20cp memory-bl.x ../../bootloader/nrf/memory.x
21
22# Flash bootloader
23cargo flash --manifest-path ../../bootloader/nrf/Cargo.toml --features embassy-nrf/nrf52840 --release --chip nRF52840_xxAA
24# Build 'b'
25cargo build --release --bin b
26# Generate binary for 'b'
27cargo objcopy --release --bin b -- -O binary b.bin
28```
29
30# Flash `a` (which includes b.bin)
31
32```
33cargo flash --release --bin a --chip nRF52840_xxAA
34```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34}
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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 FLASH : ORIGIN = 0x00000000, LENGTH = 24K
5 BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K
6 ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K
7 DFU : ORIGIN = 0x00017000, LENGTH = 68K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE);
13
14__bootloader_active_start = ORIGIN(ACTIVE);
15__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE);
16
17__bootloader_dfu_start = ORIGIN(DFU);
18__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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x00000000, LENGTH = 24K
5 BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K
6 FLASH : ORIGIN = 0x00007000, LENGTH = 64K
7 DFU : ORIGIN = 0x00017000, LENGTH = 68K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE);
13
14__bootloader_dfu_start = ORIGIN(DFU);
15__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 @@
1#![no_std]
2#![no_main]
3#![macro_use]
4#![feature(generic_associated_types)]
5#![feature(type_alias_impl_trait)]
6
7use embassy_boot_nrf::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
10use embassy_nrf::nvmc::Nvmc;
11use embassy_nrf::Peripherals;
12use panic_reset as _;
13
14static APP_B: &[u8] = include_bytes!("../../b.bin");
15
16#[embassy::main]
17async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
18 let mut button = Input::new(p.P0_11, Pull::Up);
19 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
20 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
21 //let mut button = Input::new(p.P1_02, Pull::Up);
22
23 let nvmc = Nvmc::new(p.NVMC);
24 let mut nvmc = BlockingAsync::new(nvmc);
25
26 let mut updater = FirmwareUpdater::default();
27 loop {
28 led.set_low();
29 button.wait_for_any_edge().await;
30 if button.is_low() {
31 let mut offset = 0;
32 for chunk in APP_B.chunks(4096) {
33 let mut buf: [u8; 4096] = [0; 4096];
34 buf[..chunk.len()].copy_from_slice(chunk);
35 updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap();
36 offset += chunk.len();
37 }
38 updater.update(&mut nvmc).await.unwrap();
39 led.set_high();
40 cortex_m::peripheral::SCB::sys_reset();
41 }
42 }
43}
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 @@
1#![no_std]
2#![no_main]
3#![macro_use]
4#![feature(generic_associated_types)]
5#![feature(type_alias_impl_trait)]
6
7use embassy::time::{Duration, Timer};
8use embassy_nrf::gpio::{Level, Output, OutputDrive};
9use embassy_nrf::Peripherals;
10use panic_reset as _;
11
12#[embassy::main]
13async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
14 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
15 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
16
17 loop {
18 led.set_high();
19 Timer::after(Duration::from_millis(300)).await;
20 led.set_low();
21 Timer::after(Duration::from_millis(300)).await;
22 }
23}
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32F303VCTx"
4
5[build]
6target = "thumbv7em-none-eabihf"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-stm32f3-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] }
8embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] }
9embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19
20[features]
21defmt = [
22 "dep:defmt",
23 "embassy-stm32/defmt",
24 "embassy-boot-stm32/defmt",
25]
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 @@
1# Examples using bootloader
2
3Example for STM32F3 demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-stm32`
13
14## Usage
15
16```
17# Flash bootloader
18cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32f303re --chip STM32F303RETx
19# Build 'b'
20cargo build --release --bin b
21# Generate binary for 'b'
22cargo objcopy --release --bin b -- -O binary b.bin
23```
24
25# Flash `a` (which includes b.bin)
26
27```
28cargo flash --release --bin a --chip STM32F303RETx
29```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 if env::var("CARGO_FEATURE_DEFMT").is_ok() {
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36 }
37}
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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K
5 BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
6 FLASH : ORIGIN = 0x08008000, LENGTH = 32K
7 DFU : ORIGIN = 0x08010000, LENGTH = 36K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
13
14__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
15__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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _;
14
15static APP_B: &[u8] = include_bytes!("../../b.bin");
16
17#[embassy::main]
18async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
19 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash);
21
22 let button = Input::new(p.PC13, Pull::Up);
23 let mut button = ExtiInput::new(button, p.EXTI13);
24
25 let mut led = Output::new(p.PA5, Level::Low, Speed::Low);
26 led.set_high();
27
28 let mut updater = FirmwareUpdater::default();
29 button.wait_for_falling_edge().await;
30 let mut offset = 0;
31 for chunk in APP_B.chunks(2048) {
32 let mut buf: [u8; 2048] = [0; 2048];
33 buf[..chunk.len()].copy_from_slice(chunk);
34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
35 offset += chunk.len();
36 }
37 updater.update(&mut flash).await.unwrap();
38 led.set_low();
39 cortex_m::peripheral::SCB::sys_reset();
40}
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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
16
17 loop {
18 led.set_high();
19 Timer::after(Duration::from_millis(500)).await;
20
21 led.set_low();
22 Timer::after(Duration::from_millis(500)).await;
23 }
24}
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32F767ZITx -v"
4
5[build]
6target = "thumbv7em-none-eabihf"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-stm32f7-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] }
8embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] }
9embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19
20[features]
21defmt = [
22 "dep:defmt",
23 "embassy-stm32/defmt",
24 "embassy-boot-stm32/defmt",
25]
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 @@
1# Examples using bootloader
2
3Example for STM32F7 demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-stm32`
13
14## Usage
15
16```
17# Flash bootloader
18./flash-boot.sh
19# Build 'b'
20cargo build --release --bin b
21# Generate binary for 'b'
22cargo objcopy --release --bin b -- -O binary b.bin
23```
24
25# Flash `a` (which includes b.bin)
26
27```
28cargo flash --release --bin a --chip STM32F767ZITx
29```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 if env::var("CARGO_FEATURE_DEFMT").is_ok() {
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36 }
37}
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 @@
1#!/bin/bash
2mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x
3cp memory-bl.x ../../bootloader/stm32/memory.x
4
5cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf
6
7rm ../../bootloader/stm32/memory.x
8mv ../../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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 FLASH : ORIGIN = 0x08000000, LENGTH = 256K
5 BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K
6 ACTIVE : ORIGIN = 0x08080000, LENGTH = 256K
7 DFU : ORIGIN = 0x080c0000, LENGTH = 512K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 368K + 16K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH);
13
14__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH);
15__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH);
16
17__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH);
18__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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 256K
5 BOOTLOADER_STATE : ORIGIN = 0x08040000, LENGTH = 256K
6 FLASH : ORIGIN = 0x08080000, LENGTH = 256K
7 DFU : ORIGIN = 0x080c0000, LENGTH = 512K
8 RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 368K + 16K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
13
14__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
15__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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _;
14
15static APP_B: &[u8] = include_bytes!("../../b.bin");
16
17#[embassy::main]
18async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
19 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash);
21
22 let button = Input::new(p.PC13, Pull::Down);
23 let mut button = ExtiInput::new(button, p.EXTI13);
24
25 let mut led = Output::new(p.PB7, Level::Low, Speed::Low);
26 led.set_high();
27
28 let mut updater = FirmwareUpdater::default();
29 button.wait_for_rising_edge().await;
30 let mut offset = 0;
31 let mut buf: [u8; 256 * 1024] = [0; 256 * 1024];
32 for chunk in APP_B.chunks(256 * 1024) {
33 buf[..chunk.len()].copy_from_slice(chunk);
34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
35 offset += chunk.len();
36 }
37 updater.update(&mut flash).await.unwrap();
38 led.set_low();
39 cortex_m::peripheral::SCB::sys_reset();
40}
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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 Timer::after(Duration::from_millis(300)).await;
16 let mut led = Output::new(p.PB7, Level::High, Speed::Low);
17 led.set_high();
18
19 loop {
20 led.set_high();
21 Timer::after(Duration::from_millis(500)).await;
22
23 led.set_low();
24 Timer::after(Duration::from_millis(500)).await;
25 }
26}
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32H743ZITx"
4
5[build]
6target = "thumbv7em-none-eabihf"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-stm32f7-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] }
8embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] }
9embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19
20[features]
21defmt = [
22 "dep:defmt",
23 "embassy-stm32/defmt",
24 "embassy-boot-stm32/defmt",
25]
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 @@
1# Examples using bootloader
2
3Example for STM32H7 demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-stm32`
13
14## Usage
15
16```
17# Flash bootloader
18./flash-boot.sh
19# Build 'b'
20cargo build --release --bin b
21# Generate binary for 'b'
22cargo objcopy --release --bin b -- -O binary b.bin
23```
24
25# Flash `a` (which includes b.bin)
26
27```
28cargo flash --release --bin a --chip STM32H743ZITx
29```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 if env::var("CARGO_FEATURE_DEFMT").is_ok() {
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36 }
37}
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 @@
1#!/bin/bash
2mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x
3cp memory-bl.x ../../bootloader/stm32/memory.x
4
5cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf
6
7rm ../../bootloader/stm32/memory.x
8mv ../../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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 FLASH : ORIGIN = 0x08000000, LENGTH = 128K
5 BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K
6 ACTIVE : ORIGIN = 0x08040000, LENGTH = 128K
7 DFU : ORIGIN = 0x08100000, LENGTH = 512K
8 RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH);
13
14__bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH);
15__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH);
16
17__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH);
18__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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 128K
5 BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K
6 FLASH : ORIGIN = 0x08040000, LENGTH = 256K
7 DFU : ORIGIN = 0x08100000, LENGTH = 512K
8 RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 368K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
13
14__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
15__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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _;
14
15static APP_B: &[u8] = include_bytes!("../../b.bin");
16
17#[embassy::main]
18async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
19 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash);
21
22 let button = Input::new(p.PC13, Pull::Down);
23 let mut button = ExtiInput::new(button, p.EXTI13);
24
25 let mut led = Output::new(p.PB14, Level::Low, Speed::Low);
26 led.set_high();
27
28 let mut updater = FirmwareUpdater::default();
29 button.wait_for_rising_edge().await;
30 let mut offset = 0;
31 let mut buf: [u8; 128 * 1024] = [0; 128 * 1024];
32 for chunk in APP_B.chunks(128 * 1024) {
33 buf[..chunk.len()].copy_from_slice(chunk);
34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
35 offset += chunk.len();
36 }
37 updater.update(&mut flash).await.unwrap();
38 led.set_low();
39 cortex_m::peripheral::SCB::sys_reset();
40}
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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 Timer::after(Duration::from_millis(300)).await;
16 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
17 led.set_high();
18
19 loop {
20 led.set_high();
21 Timer::after(Duration::from_millis(500)).await;
22
23 led.set_low();
24 Timer::after(Duration::from_millis(500)).await;
25 }
26}
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32L072CZTx"
4
5[build]
6target = "thumbv6m-none-eabi"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-stm32l0-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] }
8embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] }
9embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19
20[features]
21defmt = [
22 "dep:defmt",
23 "embassy-stm32/defmt",
24 "embassy-boot-stm32/defmt",
25]
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 @@
1# Examples using bootloader
2
3Example for STM32L0 demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-stm32`
13
14## Usage
15
16```
17# Flash bootloader
18cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32l072cz --chip STM32L072CZTx
19# Build 'b'
20cargo build --release --bin b
21# Generate binary for 'b'
22cargo objcopy --release --bin b -- -O binary b.bin
23```
24
25# Flash `a` (which includes b.bin)
26
27```
28cargo flash --release --bin a --chip STM32L072CZTx
29```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 if env::var("CARGO_FEATURE_DEFMT").is_ok() {
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36 }
37}
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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K
5 BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
6 FLASH : ORIGIN = 0x08008000, LENGTH = 32K
7 DFU : ORIGIN = 0x08010000, LENGTH = 36K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
13
14__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
15__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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::time::{Duration, Timer};
8use embassy_boot_stm32::FirmwareUpdater;
9use embassy_embedded_hal::adapter::BlockingAsync;
10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash;
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::Peripherals;
14use panic_reset as _;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin");
17
18#[embassy::main]
19async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
20 let flash = Flash::unlock(p.FLASH);
21 let mut flash = BlockingAsync::new(flash);
22
23 let button = Input::new(p.PB2, Pull::Up);
24 let mut button = ExtiInput::new(button, p.EXTI2);
25
26 let mut led = Output::new(p.PB5, Level::Low, Speed::Low);
27
28 led.set_high();
29
30 let mut updater = FirmwareUpdater::default();
31 button.wait_for_falling_edge().await;
32 let mut offset = 0;
33 for chunk in APP_B.chunks(128) {
34 let mut buf: [u8; 128] = [0; 128];
35 buf[..chunk.len()].copy_from_slice(chunk);
36 updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap();
37 offset += chunk.len();
38 }
39
40 updater.update(&mut flash).await.unwrap();
41 led.set_low();
42 Timer::after(Duration::from_secs(1)).await;
43 cortex_m::peripheral::SCB::sys_reset();
44}
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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 let mut led = Output::new(p.PB6, Level::High, Speed::Low);
16
17 loop {
18 led.set_high();
19 Timer::after(Duration::from_millis(500)).await;
20
21 led.set_low();
22 Timer::after(Duration::from_millis(500)).await;
23 }
24}
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32L151CBxxA"
4
5[build]
6target = "thumbv7m-none-eabi"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-stm32l1-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] }
8embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] }
9embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19
20[features]
21defmt = [
22 "dep:defmt",
23 "embassy-stm32/defmt",
24 "embassy-boot-stm32/defmt",
25]
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 @@
1# Examples using bootloader
2
3Example for STM32L1 demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-stm32`
13
14## Usage
15
16```
17# Flash bootloader
18cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32l151cb-a --chip STM32L151CBxxA
19# Build 'b'
20cargo build --release --bin b
21# Generate binary for 'b'
22cargo objcopy --release --bin b -- -O binary b.bin
23```
24
25# Flash `a` (which includes b.bin)
26
27```
28cargo flash --release --bin a --chip STM32L151CBxxA
29```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 if env::var("CARGO_FEATURE_DEFMT").is_ok() {
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36 }
37}
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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K
5 BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
6 FLASH : ORIGIN = 0x08008000, LENGTH = 32K
7 DFU : ORIGIN = 0x08010000, LENGTH = 36K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 16K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
13
14__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
15__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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::time::{Duration, Timer};
8use embassy_boot_stm32::FirmwareUpdater;
9use embassy_embedded_hal::adapter::BlockingAsync;
10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash;
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::Peripherals;
14use panic_reset as _;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin");
17
18#[embassy::main]
19async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
20 let flash = Flash::unlock(p.FLASH);
21 let mut flash = BlockingAsync::new(flash);
22
23 let button = Input::new(p.PB2, Pull::Up);
24 let mut button = ExtiInput::new(button, p.EXTI2);
25
26 let mut led = Output::new(p.PB5, Level::Low, Speed::Low);
27
28 led.set_high();
29
30 let mut updater = FirmwareUpdater::default();
31 button.wait_for_falling_edge().await;
32 let mut offset = 0;
33 for chunk in APP_B.chunks(128) {
34 let mut buf: [u8; 128] = [0; 128];
35 buf[..chunk.len()].copy_from_slice(chunk);
36 updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap();
37 offset += chunk.len();
38 }
39
40 updater.update(&mut flash).await.unwrap();
41 led.set_low();
42 Timer::after(Duration::from_secs(1)).await;
43 cortex_m::peripheral::SCB::sys_reset();
44}
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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 let mut led = Output::new(p.PB6, Level::High, Speed::Low);
16
17 loop {
18 led.set_high();
19 Timer::after(Duration::from_millis(500)).await;
20
21 led.set_low();
22 Timer::after(Duration::from_millis(500)).await;
23 }
24}
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32L475VG"
4
5[build]
6target = "thumbv7em-none-eabihf"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-stm32l4-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] }
8embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] }
9embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19
20[features]
21defmt = [
22 "dep:defmt",
23 "embassy-stm32/defmt",
24 "embassy-boot-stm32/defmt",
25]
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 @@
1# Examples using bootloader
2
3Example for STM32L4 demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-stm32`
13
14## Usage
15
16```
17# Flash bootloader
18cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32l475vg --chip STM32L475VG
19# Build 'b'
20cargo build --release --bin b
21# Generate binary for 'b'
22cargo objcopy --release --bin b -- -O binary b.bin
23```
24
25# Flash `a` (which includes b.bin)
26
27```
28cargo flash --release --bin a --chip STM32L475VG
29```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 if env::var("CARGO_FEATURE_DEFMT").is_ok() {
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36 }
37}
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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K
5 BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
6 FLASH : ORIGIN = 0x08008000, LENGTH = 32K
7 DFU : ORIGIN = 0x08010000, LENGTH = 36K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
13
14__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
15__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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _;
14
15static APP_B: &[u8] = include_bytes!("../../b.bin");
16
17#[embassy::main]
18async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
19 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash);
21
22 let button = Input::new(p.PC13, Pull::Up);
23 let mut button = ExtiInput::new(button, p.EXTI13);
24
25 let mut led = Output::new(p.PB14, Level::Low, Speed::Low);
26 led.set_high();
27
28 let mut updater = FirmwareUpdater::default();
29 button.wait_for_falling_edge().await;
30 let mut offset = 0;
31 for chunk in APP_B.chunks(2048) {
32 let mut buf: [u8; 2048] = [0; 2048];
33 buf[..chunk.len()].copy_from_slice(chunk);
34 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
35 offset += chunk.len();
36 }
37 updater.update(&mut flash).await.unwrap();
38 led.set_low();
39 cortex_m::peripheral::SCB::sys_reset();
40}
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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 let mut led = Output::new(p.PA5, Level::High, Speed::Low);
16
17 loop {
18 led.set_high();
19 Timer::after(Duration::from_millis(500)).await;
20
21 led.set_low();
22 Timer::after(Duration::from_millis(500)).await;
23 }
24}
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 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32WLE5JCIx"
4
5[build]
6target = "thumbv7em-none-eabihf"
7
8[env]
9DEFMT_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 @@
1[package]
2edition = "2021"
3name = "embassy-boot-stm32wl-examples"
4version = "0.1.0"
5
6[dependencies]
7embassy = { version = "0.1.0", path = "../../../../embassy", features = ["nightly", "time-tick-32768hz"] }
8embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] }
9embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" }
10embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
11
12defmt = { version = "0.3", optional = true }
13defmt-rtt = { version = "0.3", optional = true }
14panic-reset = { version = "0.1.1" }
15embedded-hal = { version = "0.2.6" }
16
17cortex-m = "0.7.3"
18cortex-m-rt = "0.7.0"
19
20[features]
21defmt = [
22 "dep:defmt",
23 "embassy-stm32/defmt",
24 "embassy-boot-stm32/defmt",
25]
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 @@
1# Examples using bootloader
2
3Example for STM32WL demonstrating the bootloader. The example consists of application binaries, 'a'
4which allows you to press a button to start the DFU process, and 'b' which is the updated
5application.
6
7
8## Prerequisites
9
10* `cargo-binutils`
11* `cargo-flash`
12* `embassy-boot-stm32`
13
14## Usage
15
16```
17# Flash bootloader
18cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32wl55jc-cm4 --chip STM32WLE5JCIx
19# Build 'b'
20cargo build --release --bin b
21# Generate binary for 'b'
22cargo objcopy --release --bin b -- -O binary b.bin
23```
24
25# Flash `a` (which includes b.bin)
26
27```
28cargo flash --release --bin a --chip STM32WLE5JCIx
29```
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 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 if env::var("CARGO_FEATURE_DEFMT").is_ok() {
35 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
36 }
37}
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 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K
5 BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K
6 FLASH : ORIGIN = 0x08008000, LENGTH = 32K
7 DFU : ORIGIN = 0x08010000, LENGTH = 36K
8 RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K
9}
10
11__bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
12__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER);
13
14__bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER);
15__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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater;
8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_stm32::exti::ExtiInput;
10use embassy_stm32::flash::Flash;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::Peripherals;
13use panic_reset as _;
14
15static APP_B: &[u8] = include_bytes!("../../b.bin");
16
17#[embassy::main]
18async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
19 let flash = Flash::unlock(p.FLASH);
20 let mut flash = BlockingAsync::new(flash);
21
22 let button = Input::new(p.PA0, Pull::Up);
23 let mut button = ExtiInput::new(button, p.EXTI0);
24
25 let mut led = Output::new(p.PB9, Level::Low, Speed::Low);
26 led.set_high();
27
28 let mut updater = FirmwareUpdater::default();
29 button.wait_for_falling_edge().await;
30 //defmt::info!("Starting update");
31 let mut offset = 0;
32 for chunk in APP_B.chunks(2048) {
33 let mut buf: [u8; 2048] = [0; 2048];
34 buf[..chunk.len()].copy_from_slice(chunk);
35 // defmt::info!("Writing chunk at 0x{:x}", offset);
36 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
37 offset += chunk.len();
38 }
39 updater.update(&mut flash).await.unwrap();
40 //defmt::info!("Marked as updated");
41 led.set_low();
42 cortex_m::peripheral::SCB::sys_reset();
43}
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 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use panic_reset as _;
12
13#[embassy::main]
14async fn main(_spawner: Spawner, p: Peripherals) {
15 let mut led = Output::new(p.PB15, Level::High, Speed::Low);
16
17 loop {
18 led.set_high();
19 Timer::after(Duration::from_millis(500)).await;
20
21 led.set_low();
22 Timer::after(Duration::from_millis(500)).await;
23 }
24}