diff options
Diffstat (limited to 'examples/boot')
47 files changed, 986 insertions, 163 deletions
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml index dbbe0fddc..55053bc33 100644 --- a/examples/boot/application/nrf/Cargo.toml +++ b/examples/boot/application/nrf/Cargo.toml | |||
| @@ -1,20 +1,21 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-nrf-examples" | 3 | name = "embassy-boot-nrf-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-16384", "arch-cortex-m", "executor-thread", "integrated-timers", "arch-cortex-m", "executor-thread"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [] } |
| 11 | embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] } | 12 | embassy-nrf = { version = "0.8.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] } |
| 12 | embassy-boot = { version = "0.2.0", path = "../../../../embassy-boot", features = [] } | 13 | embassy-boot = { version = "0.6.1", path = "../../../../embassy-boot", features = [] } |
| 13 | embassy-boot-nrf = { version = "0.2.0", path = "../../../../embassy-boot-nrf", features = [] } | 14 | embassy-boot-nrf = { version = "0.9.0", path = "../../../../embassy-boot-nrf", features = [] } |
| 14 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 15 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 15 | 16 | ||
| 16 | defmt = { version = "0.3", optional = true } | 17 | defmt = { version = "1.0.1", optional = true } |
| 17 | defmt-rtt = { version = "0.4", optional = true } | 18 | defmt-rtt = { version = "1.0.0", optional = true } |
| 18 | panic-reset = { version = "0.1.1" } | 19 | panic-reset = { version = "0.1.1" } |
| 19 | embedded-hal = { version = "0.2.6" } | 20 | embedded-hal = { version = "0.2.6" } |
| 20 | 21 | ||
| @@ -32,3 +33,12 @@ defmt = [ | |||
| 32 | "embassy-boot-nrf/defmt", | 33 | "embassy-boot-nrf/defmt", |
| 33 | "embassy-sync/defmt", | 34 | "embassy-sync/defmt", |
| 34 | ] | 35 | ] |
| 36 | |||
| 37 | [package.metadata.embassy] | ||
| 38 | build = [ | ||
| 39 | { target = "thumbv7em-none-eabi", features = ["embassy-nrf/nrf52840", "skip-include"], artifact-dir = "out/examples/boot/nrf52840" }, | ||
| 40 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9160-ns", "skip-include"], artifact-dir = "out/examples/boot/nrf9160" }, | ||
| 41 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9120-ns", "skip-include"], artifact-dir = "out/examples/boot/nrf9120" }, | ||
| 42 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9151-ns", "skip-include"], artifact-dir = "out/examples/boot/nrf9151" }, | ||
| 43 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9161-ns", "skip-include"], artifact-dir = "out/examples/boot/nrf9161" } | ||
| 44 | ] | ||
diff --git a/examples/boot/application/nrf/build.rs b/examples/boot/application/nrf/build.rs index cd1a264c4..e1da69328 100644 --- a/examples/boot/application/nrf/build.rs +++ b/examples/boot/application/nrf/build.rs | |||
| @@ -31,4 +31,7 @@ fn main() { | |||
| 31 | 31 | ||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); |
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | 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 | } | ||
| 34 | } | 37 | } |
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 851a3d721..2c1d1a7bb 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -2,6 +2,9 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![macro_use] | 3 | #![macro_use] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "defmt")] | ||
| 6 | use defmt_rtt as _; | ||
| 7 | use embassy_boot::State; | ||
| 5 | use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig}; | 8 | use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig}; |
| 6 | use embassy_embedded_hal::adapter::BlockingAsync; | 9 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 7 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| @@ -22,6 +25,7 @@ async fn main(_spawner: Spawner) { | |||
| 22 | 25 | ||
| 23 | let mut button = Input::new(p.P0_11, Pull::Up); | 26 | let mut button = Input::new(p.P0_11, Pull::Up); |
| 24 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | 27 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); |
| 28 | let mut led_reverted = Output::new(p.P0_14, Level::High, OutputDrive::Standard); | ||
| 25 | 29 | ||
| 26 | //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); | 30 | //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); |
| 27 | //let mut button = Input::new(p.P1_02, Pull::Up); | 31 | //let mut button = Input::new(p.P1_02, Pull::Up); |
| @@ -53,6 +57,13 @@ async fn main(_spawner: Spawner) { | |||
| 53 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc, &nvmc); | 57 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc, &nvmc); |
| 54 | let mut magic = [0; 4]; | 58 | let mut magic = [0; 4]; |
| 55 | let mut updater = FirmwareUpdater::new(config, &mut magic); | 59 | let mut updater = FirmwareUpdater::new(config, &mut magic); |
| 60 | let state = updater.get_state().await.unwrap(); | ||
| 61 | if state == State::Revert { | ||
| 62 | led_reverted.set_low(); | ||
| 63 | } else { | ||
| 64 | led_reverted.set_high(); | ||
| 65 | } | ||
| 66 | |||
| 56 | loop { | 67 | loop { |
| 57 | led.set_low(); | 68 | led.set_low(); |
| 58 | button.wait_for_any_edge().await; | 69 | button.wait_for_any_edge().await; |
diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml index d4341e8f6..70a2c28c3 100644 --- a/examples/boot/application/rp/Cargo.toml +++ b/examples/boot/application/rp/Cargo.toml | |||
| @@ -1,20 +1,21 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-rp-examples" | 3 | name = "embassy-boot-rp-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-16384", "arch-cortex-m", "executor-thread", "integrated-timers", "arch-cortex-m", "executor-thread"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [] } |
| 11 | embassy-rp = { version = "0.1.0", path = "../../../../embassy-rp", features = ["time-driver", ] } | 12 | embassy-rp = { version = "0.8.0", path = "../../../../embassy-rp", features = ["time-driver", "rp2040"] } |
| 12 | embassy-boot-rp = { version = "0.2.0", path = "../../../../embassy-boot-rp", features = [] } | 13 | embassy-boot-rp = { version = "0.8.0", path = "../../../../embassy-boot-rp", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = "0.3" | 16 | defmt = "1.0.1" |
| 16 | defmt-rtt = "0.4" | 17 | defmt-rtt = "1.0.0" |
| 17 | panic-probe = { version = "0.3", features = ["print-defmt"], optional = true } | 18 | panic-probe = { version = "1.0.0", features = ["print-defmt"], optional = true } |
| 18 | panic-reset = { version = "0.1.1", optional = true } | 19 | panic-reset = { version = "0.1.1", optional = true } |
| 19 | embedded-hal = { version = "0.2.6" } | 20 | embedded-hal = { version = "0.2.6" } |
| 20 | 21 | ||
| @@ -34,3 +35,8 @@ skip-include = [] | |||
| 34 | 35 | ||
| 35 | [profile.release] | 36 | [profile.release] |
| 36 | debug = true | 37 | debug = true |
| 38 | |||
| 39 | [package.metadata.embassy] | ||
| 40 | build = [ | ||
| 41 | { target = "thumbv6m-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/rp" } | ||
| 42 | ] | ||
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs index ede0c07da..e6d7b3d4f 100644 --- a/examples/boot/application/rp/src/bin/a.rs +++ b/examples/boot/application/rp/src/bin/a.rs | |||
| @@ -54,7 +54,7 @@ async fn main(_s: Spawner) { | |||
| 54 | for chunk in APP_B.chunks(4096) { | 54 | for chunk in APP_B.chunks(4096) { |
| 55 | buf.0[..chunk.len()].copy_from_slice(chunk); | 55 | buf.0[..chunk.len()].copy_from_slice(chunk); |
| 56 | defmt::info!("writing block at offset {}", offset); | 56 | defmt::info!("writing block at offset {}", offset); |
| 57 | writer.write(offset, &buf.0[..]).unwrap(); | 57 | writer.write(offset, &buf.0[..chunk.len()]).unwrap(); |
| 58 | offset += chunk.len() as u32; | 58 | offset += chunk.len() as u32; |
| 59 | } | 59 | } |
| 60 | watchdog.feed(); | 60 | watchdog.feed(); |
diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index c203ffc9f..2dc75d939 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32f3-examples" | 3 | name = "embassy-boot-stm32f3-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f303re", "time-driver-any", "exti"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32f303re", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32" } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32" } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "1.0.1", optional = true } |
| 16 | defmt-rtt = { version = "0.4", optional = true } | 17 | defmt-rtt = { version = "1.0.0", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 18 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 19 | embedded-hal = { version = "0.2.6" } |
| 19 | 20 | ||
| @@ -29,3 +30,8 @@ defmt = [ | |||
| 29 | "embassy-sync/defmt", | 30 | "embassy-sync/defmt", |
| 30 | ] | 31 | ] |
| 31 | skip-include = [] | 32 | skip-include = [] |
| 33 | |||
| 34 | [package.metadata.embassy] | ||
| 35 | build = [ | ||
| 36 | { target = "thumbv7em-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/stm32f3" } | ||
| 37 | ] | ||
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index ed13eab65..5c372fb19 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32f7-examples" | 3 | name = "embassy-boot-stm32f7-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti", "single-bank"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "1.0.1", optional = true } |
| 16 | defmt-rtt = { version = "0.4", optional = true } | 17 | defmt-rtt = { version = "1.0.0", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 18 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 19 | embedded-hal = { version = "0.2.6" } |
| 19 | embedded-storage = "0.3.1" | 20 | embedded-storage = "0.3.1" |
| @@ -30,3 +31,8 @@ defmt = [ | |||
| 30 | "embassy-sync/defmt", | 31 | "embassy-sync/defmt", |
| 31 | ] | 32 | ] |
| 32 | skip-include = [] | 33 | skip-include = [] |
| 34 | |||
| 35 | [package.metadata.embassy] | ||
| 36 | build = [ | ||
| 37 | { target = "thumbv7em-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/stm32f7" } | ||
| 38 | ] | ||
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index f25e9815d..641a2ba96 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32h7-examples" | 3 | name = "embassy-boot-stm32h7-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32h743zi", "time-driver-any", "exti"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32h743zi", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "1.0.1", optional = true } |
| 16 | defmt-rtt = { version = "0.4", optional = true } | 17 | defmt-rtt = { version = "1.0.0", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 18 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 19 | embedded-hal = { version = "0.2.6" } |
| 19 | embedded-storage = "0.3.1" | 20 | embedded-storage = "0.3.1" |
| @@ -30,3 +31,8 @@ defmt = [ | |||
| 30 | "embassy-sync/defmt", | 31 | "embassy-sync/defmt", |
| 31 | ] | 32 | ] |
| 32 | skip-include = [] | 33 | skip-include = [] |
| 34 | |||
| 35 | [package.metadata.embassy] | ||
| 36 | build = [ | ||
| 37 | { target = "thumbv7em-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/stm32h7" } | ||
| 38 | ] | ||
diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index c1a47dfe4..4a168be15 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32l0-examples" | 3 | name = "embassy-boot-stm32l0-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l072cz", "time-driver-any", "exti", "memory-x"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32l072cz", "time-driver-any", "exti", "memory-x"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "1.0.1", optional = true } |
| 16 | defmt-rtt = { version = "0.4", optional = true } | 17 | defmt-rtt = { version = "1.0.0", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 18 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 19 | embedded-hal = { version = "0.2.6" } |
| 19 | 20 | ||
| @@ -29,3 +30,8 @@ defmt = [ | |||
| 29 | "embassy-sync/defmt", | 30 | "embassy-sync/defmt", |
| 30 | ] | 31 | ] |
| 31 | skip-include = [] | 32 | skip-include = [] |
| 33 | |||
| 34 | [package.metadata.embassy] | ||
| 35 | build = [ | ||
| 36 | { target = "thumbv6m-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/stm32l0" } | ||
| 37 | ] | ||
diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index 1e83d3113..af2cb3881 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32l1-examples" | 3 | name = "embassy-boot-stm32l1-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l151cb-a", "time-driver-any", "exti"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32l151cb-a", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "1.0.1", optional = true } |
| 16 | defmt-rtt = { version = "0.4", optional = true } | 17 | defmt-rtt = { version = "1.0.0", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 18 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 19 | embedded-hal = { version = "0.2.6" } |
| 19 | 20 | ||
| @@ -29,3 +30,8 @@ defmt = [ | |||
| 29 | "embassy-sync/defmt", | 30 | "embassy-sync/defmt", |
| 30 | ] | 31 | ] |
| 31 | skip-include = [] | 32 | skip-include = [] |
| 33 | |||
| 34 | [package.metadata.embassy] | ||
| 35 | build = [ | ||
| 36 | { target = "thumbv7m-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/stm32l1" } | ||
| 37 | ] | ||
diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index bca292681..032e934aa 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32l4-examples" | 3 | name = "embassy-boot-stm32l4-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "time-driver-any", "exti"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "1.0.1", optional = true } |
| 16 | defmt-rtt = { version = "0.4", optional = true } | 17 | defmt-rtt = { version = "1.0.0", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 18 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 19 | embedded-hal = { version = "0.2.6" } |
| 19 | 20 | ||
| @@ -29,3 +30,8 @@ defmt = [ | |||
| 29 | "embassy-sync/defmt", | 30 | "embassy-sync/defmt", |
| 30 | ] | 31 | ] |
| 31 | skip-include = [] | 32 | skip-include = [] |
| 33 | |||
| 34 | [package.metadata.embassy] | ||
| 35 | build = [ | ||
| 36 | { target = "thumbv7em-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/stm32l4" } | ||
| 37 | ] | ||
diff --git a/examples/boot/application/stm32wb-dfu/Cargo.toml b/examples/boot/application/stm32wb-dfu/Cargo.toml index 0484e6ceb..ea4c26681 100644 --- a/examples/boot/application/stm32wb-dfu/Cargo.toml +++ b/examples/boot/application/stm32wb-dfu/Cargo.toml | |||
| @@ -1,21 +1,22 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32wb-dfu-examples" | 3 | name = "embassy-boot-stm32wb-dfu-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wb55rg", "time-driver-any", "exti"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32wb55rg", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | embassy-usb = { version = "0.2.0", path = "../../../../embassy-usb" } | 15 | embassy-usb = { version = "0.5.1", path = "../../../../embassy-usb" } |
| 15 | embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["application", "cortex-m"] } | 16 | embassy-usb-dfu = { version = "0.2.0", path = "../../../../embassy-usb-dfu", features = ["application", "cortex-m"] } |
| 16 | 17 | ||
| 17 | defmt = { version = "0.3", optional = true } | 18 | defmt = { version = "1.0.1", optional = true } |
| 18 | defmt-rtt = { version = "0.4", optional = true } | 19 | defmt-rtt = { version = "1.0.0", optional = true } |
| 19 | panic-reset = { version = "0.1.1" } | 20 | panic-reset = { version = "0.1.1" } |
| 20 | embedded-hal = { version = "0.2.6" } | 21 | embedded-hal = { version = "0.2.6" } |
| 21 | 22 | ||
| @@ -30,3 +31,8 @@ defmt = [ | |||
| 30 | "embassy-boot-stm32/defmt", | 31 | "embassy-boot-stm32/defmt", |
| 31 | "embassy-sync/defmt", | 32 | "embassy-sync/defmt", |
| 32 | ] | 33 | ] |
| 34 | |||
| 35 | [package.metadata.embassy] | ||
| 36 | build = [ | ||
| 37 | { target = "thumbv7em-none-eabi", artifact-dir = "out/examples/boot/stm32wb-dfu" } | ||
| 38 | ] | ||
diff --git a/examples/boot/application/stm32wb-dfu/memory.x b/examples/boot/application/stm32wb-dfu/memory.x index ff1b800d2..f1e6b053c 100644 --- a/examples/boot/application/stm32wb-dfu/memory.x +++ b/examples/boot/application/stm32wb-dfu/memory.x | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | MEMORY | 1 | MEMORY |
| 2 | { | 2 | { |
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 48K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x0800C000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 128K | 6 | FLASH : ORIGIN = 0x0800D000, LENGTH = 120K |
| 7 | DFU : ORIGIN = 0x08028000, LENGTH = 132K | 7 | DFU : ORIGIN = 0x0802B000, LENGTH = 120K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32wb-dfu/secrets/key.sec b/examples/boot/application/stm32wb-dfu/secrets/key.sec new file mode 100644 index 000000000..52e7f125b --- /dev/null +++ b/examples/boot/application/stm32wb-dfu/secrets/key.sec | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | untrusted comment: signify secret key | ||
| 2 | RWRCSwAAAAATdHQF3B4jEIoNZrjADRp2LbjJjNdNNzKwTCe4IB6mDNq96pe53nbNxwbdCc/T4hrz7W+Kx1MwrZ0Yz5xebSK5Z0Kh/3Cdf039U5f+eoTDS2fIGbohyUbrtwKzjyE0qXI= | ||
diff --git a/examples/boot/application/stm32wb-dfu/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs index 0ab99ff90..1ae28bf3a 100644 --- a/examples/boot/application/stm32wb-dfu/src/main.rs +++ b/examples/boot/application/stm32wb-dfu/src/main.rs | |||
| @@ -13,15 +13,20 @@ use embassy_stm32::usb::{self, Driver}; | |||
| 13 | use embassy_stm32::{bind_interrupts, peripherals}; | 13 | use embassy_stm32::{bind_interrupts, peripherals}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | 14 | use embassy_sync::blocking_mutex::Mutex; |
| 15 | use embassy_time::Duration; | 15 | use embassy_time::Duration; |
| 16 | use embassy_usb::Builder; | 16 | use embassy_usb::{Builder, msos}; |
| 17 | use embassy_usb_dfu::consts::DfuAttributes; | 17 | use embassy_usb_dfu::consts::DfuAttributes; |
| 18 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; | 18 | use embassy_usb_dfu::{Control, ResetImmediate, usb_dfu}; |
| 19 | use panic_reset as _; | 19 | use panic_reset as _; |
| 20 | 20 | ||
| 21 | bind_interrupts!(struct Irqs { | 21 | bind_interrupts!(struct Irqs { |
| 22 | USB_LP => usb::InterruptHandler<peripherals::USB>; | 22 | USB_LP => usb::InterruptHandler<peripherals::USB>; |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | // This is a randomly generated GUID to allow clients on Windows to find your device. | ||
| 26 | // | ||
| 27 | // N.B. update to a custom GUID for your own device! | ||
| 28 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; | ||
| 29 | |||
| 25 | #[embassy_executor::main] | 30 | #[embassy_executor::main] |
| 26 | async fn main(_spawner: Spawner) { | 31 | async fn main(_spawner: Spawner) { |
| 27 | let mut config = embassy_stm32::Config::default(); | 32 | let mut config = embassy_stm32::Config::default(); |
| @@ -44,7 +49,7 @@ async fn main(_spawner: Spawner) { | |||
| 44 | let mut config_descriptor = [0; 256]; | 49 | let mut config_descriptor = [0; 256]; |
| 45 | let mut bos_descriptor = [0; 256]; | 50 | let mut bos_descriptor = [0; 256]; |
| 46 | let mut control_buf = [0; 64]; | 51 | let mut control_buf = [0; 64]; |
| 47 | let mut state = Control::new(firmware_state, DfuAttributes::CAN_DOWNLOAD); | 52 | let mut state = Control::new(firmware_state, DfuAttributes::CAN_DOWNLOAD, ResetImmediate); |
| 48 | let mut builder = Builder::new( | 53 | let mut builder = Builder::new( |
| 49 | driver, | 54 | driver, |
| 50 | config, | 55 | config, |
| @@ -54,7 +59,28 @@ async fn main(_spawner: Spawner) { | |||
| 54 | &mut control_buf, | 59 | &mut control_buf, |
| 55 | ); | 60 | ); |
| 56 | 61 | ||
| 57 | usb_dfu::<_, _, ResetImmediate>(&mut builder, &mut state, Duration::from_millis(2500)); | 62 | // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows. |
| 63 | // Otherwise users need to do this manually using a tool like Zadig. | ||
| 64 | // | ||
| 65 | // It seems these always need to be at added at the device level for this to work and for | ||
| 66 | // composite devices they also need to be added on the function level (as shown later). | ||
| 67 | // | ||
| 68 | builder.msos_descriptor(msos::windows_version::WIN8_1, 2); | ||
| 69 | builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 70 | builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 71 | "DeviceInterfaceGUIDs", | ||
| 72 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 73 | )); | ||
| 74 | |||
| 75 | usb_dfu(&mut builder, &mut state, Duration::from_millis(2500), |func| { | ||
| 76 | // You likely don't have to add these function level headers if your USB device is not composite | ||
| 77 | // (i.e. if your device does not expose another interface in addition to DFU) | ||
| 78 | func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 79 | func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 80 | "DeviceInterfaceGUIDs", | ||
| 81 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 82 | )); | ||
| 83 | }); | ||
| 58 | 84 | ||
| 59 | let mut dev = builder.build(); | 85 | let mut dev = builder.build(); |
| 60 | dev.run().await | 86 | dev.run().await |
diff --git a/examples/boot/application/stm32wba-dfu/.cargo/config.toml b/examples/boot/application/stm32wba-dfu/.cargo/config.toml new file mode 100644 index 000000000..a18ec3944 --- /dev/null +++ b/examples/boot/application/stm32wba-dfu/.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-rs chip list` | ||
| 3 | runner = "probe-rs run --chip STM32WBA65RI" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv8m.main-none-eabihf" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_LOG = "trace" | ||
diff --git a/examples/boot/application/stm32wba-dfu/Cargo.toml b/examples/boot/application/stm32wba-dfu/Cargo.toml new file mode 100644 index 000000000..d6f7dc3b6 --- /dev/null +++ b/examples/boot/application/stm32wba-dfu/Cargo.toml | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2024" | ||
| 3 | name = "embassy-boot-stm32wba-dfu-examples" | ||
| 4 | version = "0.1.0" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | publish = false | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } | ||
| 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } | ||
| 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | ||
| 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32wba65ri", "time-driver-any", "exti"] } | ||
| 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } | ||
| 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } | ||
| 15 | embassy-usb = { version = "0.5.1", path = "../../../../embassy-usb" } | ||
| 16 | embassy-usb-dfu = { version = "0.2.0", path = "../../../../embassy-usb-dfu", features = ["application", "cortex-m"] } | ||
| 17 | |||
| 18 | defmt = { version = "1.0.1", optional = true } | ||
| 19 | defmt-rtt = { version = "1.0.0", optional = true } | ||
| 20 | panic-reset = { version = "0.1.1" } | ||
| 21 | embedded-hal = { version = "0.2.6" } | ||
| 22 | |||
| 23 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | ||
| 24 | cortex-m-rt = "0.7.0" | ||
| 25 | |||
| 26 | [features] | ||
| 27 | defmt = [ | ||
| 28 | "dep:defmt", | ||
| 29 | "dep:defmt-rtt", | ||
| 30 | "embassy-stm32/defmt", | ||
| 31 | "embassy-boot-stm32/defmt", | ||
| 32 | "embassy-sync/defmt", | ||
| 33 | ] | ||
| 34 | |||
| 35 | [package.metadata.embassy] | ||
| 36 | build = [ | ||
| 37 | { target = "thumbv8m.main-none-eabihf", artifact-dir = "out/examples/boot/stm32wba-dfu" } | ||
| 38 | ] | ||
diff --git a/examples/boot/application/stm32wba-dfu/README.md b/examples/boot/application/stm32wba-dfu/README.md new file mode 100644 index 000000000..30692034c --- /dev/null +++ b/examples/boot/application/stm32wba-dfu/README.md | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # Examples using bootloader | ||
| 2 | |||
| 3 | Example for STM32WBA demonstrating the USB DFU application. | ||
| 4 | |||
| 5 | ## Usage | ||
| 6 | |||
| 7 | ``` | ||
| 8 | cargo flash --release --chip STM32WBA65RI | ||
| 9 | ``` | ||
diff --git a/examples/boot/application/stm32wba-dfu/build.rs b/examples/boot/application/stm32wba-dfu/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32wba-dfu/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 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn 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/stm32wba-dfu/memory.x b/examples/boot/application/stm32wba-dfu/memory.x new file mode 100644 index 000000000..fcdb6b6d2 --- /dev/null +++ b/examples/boot/application/stm32wba-dfu/memory.x | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 80K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08014000, LENGTH = 8K | ||
| 6 | FLASH : ORIGIN = 0x08016000, LENGTH = 120K | ||
| 7 | DFU : ORIGIN = 0x0803C000, LENGTH = 160K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 400K | ||
| 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/stm32wba-dfu/secrets/key.sec b/examples/boot/application/stm32wba-dfu/secrets/key.sec new file mode 100644 index 000000000..52e7f125b --- /dev/null +++ b/examples/boot/application/stm32wba-dfu/secrets/key.sec | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | untrusted comment: signify secret key | ||
| 2 | RWRCSwAAAAATdHQF3B4jEIoNZrjADRp2LbjJjNdNNzKwTCe4IB6mDNq96pe53nbNxwbdCc/T4hrz7W+Kx1MwrZ0Yz5xebSK5Z0Kh/3Cdf039U5f+eoTDS2fIGbohyUbrtwKzjyE0qXI= | ||
diff --git a/examples/boot/application/stm32wba-dfu/src/main.rs b/examples/boot/application/stm32wba-dfu/src/main.rs new file mode 100644 index 000000000..8adb2e7c0 --- /dev/null +++ b/examples/boot/application/stm32wba-dfu/src/main.rs | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 6 | #[cfg(feature = "defmt")] | ||
| 7 | use defmt_rtt as _; | ||
| 8 | use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareState, FirmwareUpdaterConfig}; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | ||
| 11 | use embassy_stm32::usb::{self, Driver}; | ||
| 12 | use embassy_stm32::{bind_interrupts, peripherals}; | ||
| 13 | use embassy_sync::blocking_mutex::Mutex; | ||
| 14 | use embassy_time::Duration; | ||
| 15 | use embassy_usb::{Builder, msos}; | ||
| 16 | use embassy_usb_dfu::consts::DfuAttributes; | ||
| 17 | use embassy_usb_dfu::{Control, ResetImmediate, usb_dfu}; | ||
| 18 | use panic_reset as _; | ||
| 19 | |||
| 20 | bind_interrupts!(struct Irqs { | ||
| 21 | USB_OTG_HS => usb::InterruptHandler<peripherals::USB_OTG_HS>; | ||
| 22 | }); | ||
| 23 | |||
| 24 | // This is a randomly generated GUID to allow clients on Windows to find your device. | ||
| 25 | // | ||
| 26 | // N.B. update to a custom GUID for your own device! | ||
| 27 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; | ||
| 28 | |||
| 29 | #[embassy_executor::main] | ||
| 30 | async fn main(_spawner: Spawner) { | ||
| 31 | let mut config = embassy_stm32::Config::default(); | ||
| 32 | |||
| 33 | { | ||
| 34 | use embassy_stm32::rcc::*; | ||
| 35 | config.rcc.pll1 = Some(Pll { | ||
| 36 | source: PllSource::HSI, | ||
| 37 | prediv: PllPreDiv::DIV1, // PLLM = 1 → HSI / 1 = 16 MHz | ||
| 38 | mul: PllMul::MUL30, // PLLN = 30 → 16 MHz * 30 = 480 MHz VCO | ||
| 39 | divr: Some(PllDiv::DIV5), // PLLR = 5 → 96 MHz (Sysclk) | ||
| 40 | divq: Some(PllDiv::DIV10), // PLLQ = 10 → 48 MHz | ||
| 41 | divp: Some(PllDiv::DIV30), // PLLP = 30 → 16 MHz (USB_OTG_HS) | ||
| 42 | frac: Some(0), // Fractional part (disabled) | ||
| 43 | }); | ||
| 44 | |||
| 45 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 46 | config.rcc.apb1_pre = APBPrescaler::DIV1; | ||
| 47 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 48 | config.rcc.apb7_pre = APBPrescaler::DIV1; | ||
| 49 | config.rcc.ahb5_pre = AHB5Prescaler::DIV4; | ||
| 50 | |||
| 51 | config.rcc.voltage_scale = VoltageScale::RANGE1; | ||
| 52 | config.rcc.mux.otghssel = mux::Otghssel::PLL1_P; | ||
| 53 | config.rcc.sys = Sysclk::PLL1_R; | ||
| 54 | } | ||
| 55 | |||
| 56 | let p = embassy_stm32::init(config); | ||
| 57 | let flash = Flash::new_blocking(p.FLASH); | ||
| 58 | let flash = Mutex::new(RefCell::new(flash)); | ||
| 59 | |||
| 60 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); | ||
| 61 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 62 | let mut firmware_state = BlockingFirmwareState::from_config(config, &mut magic.0); | ||
| 63 | firmware_state.mark_booted().expect("Failed to mark booted"); | ||
| 64 | |||
| 65 | // Create the driver, from the HAL. | ||
| 66 | let mut ep_out_buffer = [0u8; 256]; | ||
| 67 | let mut config = embassy_stm32::usb::Config::default(); | ||
| 68 | config.vbus_detection = false; | ||
| 69 | |||
| 70 | let driver = Driver::new_hs(p.USB_OTG_HS, Irqs, p.PD6, p.PD7, &mut ep_out_buffer, config); | ||
| 71 | let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); | ||
| 72 | config.manufacturer = Some("Embassy"); | ||
| 73 | config.product = Some("USB-DFU Runtime example"); | ||
| 74 | config.serial_number = Some("1235678"); | ||
| 75 | |||
| 76 | let mut config_descriptor = [0; 256]; | ||
| 77 | let mut bos_descriptor = [0; 256]; | ||
| 78 | let mut control_buf = [0; 64]; | ||
| 79 | let mut state = Control::new(firmware_state, DfuAttributes::CAN_DOWNLOAD, ResetImmediate); | ||
| 80 | let mut builder = Builder::new( | ||
| 81 | driver, | ||
| 82 | config, | ||
| 83 | &mut config_descriptor, | ||
| 84 | &mut bos_descriptor, | ||
| 85 | &mut [], | ||
| 86 | &mut control_buf, | ||
| 87 | ); | ||
| 88 | |||
| 89 | // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows. | ||
| 90 | // Otherwise users need to do this manually using a tool like Zadig. | ||
| 91 | // | ||
| 92 | // It seems these always need to be at added at the device level for this to work and for | ||
| 93 | // composite devices they also need to be added on the function level (as shown later). | ||
| 94 | |||
| 95 | builder.msos_descriptor(msos::windows_version::WIN8_1, 2); | ||
| 96 | builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 97 | builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 98 | "DeviceInterfaceGUIDs", | ||
| 99 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 100 | )); | ||
| 101 | |||
| 102 | usb_dfu(&mut builder, &mut state, Duration::from_millis(1000), |func| { | ||
| 103 | // You likely don't have to add these function level headers if your USB device is not composite | ||
| 104 | // (i.e. if your device does not expose another interface in addition to DFU) | ||
| 105 | func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 106 | func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 107 | "DeviceInterfaceGUIDs", | ||
| 108 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 109 | )); | ||
| 110 | }); | ||
| 111 | |||
| 112 | let mut dev = builder.build(); | ||
| 113 | dev.run().await | ||
| 114 | } | ||
diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index b785a1968..c7fa811c9 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml | |||
| @@ -1,19 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "embassy-boot-stm32wl-examples" | 3 | name = "embassy-boot-stm32wl-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 9 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wl55jc-cm4", "time-driver-any", "exti"] } | 12 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32wl55jc-cm4", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | 13 | embassy-boot-stm32 = { version = "0.6.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.5.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 15 | ||
| 15 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "1.0.1", optional = true } |
| 16 | defmt-rtt = { version = "0.4", optional = true } | 17 | defmt-rtt = { version = "1.0.0", optional = true } |
| 17 | panic-reset = { version = "0.1.1" } | 18 | panic-reset = { version = "0.1.1" } |
| 18 | embedded-hal = { version = "0.2.6" } | 19 | embedded-hal = { version = "0.2.6" } |
| 19 | 20 | ||
| @@ -29,3 +30,8 @@ defmt = [ | |||
| 29 | "embassy-sync/defmt", | 30 | "embassy-sync/defmt", |
| 30 | ] | 31 | ] |
| 31 | skip-include = [] | 32 | skip-include = [] |
| 33 | |||
| 34 | [package.metadata.embassy] | ||
| 35 | build = [ | ||
| 36 | { target = "thumbv7em-none-eabi", features = ["skip-include"], artifact-dir = "out/examples/boot/stm32wl" } | ||
| 37 | ] | ||
diff --git a/examples/boot/application/stm32wl/memory.x b/examples/boot/application/stm32wl/memory.x index e1d4e7fa8..20109e37e 100644 --- a/examples/boot/application/stm32wl/memory.x +++ b/examples/boot/application/stm32wl/memory.x | |||
| @@ -5,7 +5,8 @@ MEMORY | |||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08018000, LENGTH = 68K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 68K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | SHARED_RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128 |
| 9 | RAM (rwx) : ORIGIN = 0x20000080, LENGTH = 32K - 128 | ||
| 9 | } | 10 | } |
| 10 | 11 | ||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | 12 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); |
| @@ -13,3 +14,11 @@ __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - O | |||
| 13 | 14 | ||
| 14 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); | 15 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); |
| 15 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); | 16 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); |
| 17 | |||
| 18 | SECTIONS | ||
| 19 | { | ||
| 20 | .shared_data : | ||
| 21 | { | ||
| 22 | *(.shared_data) | ||
| 23 | } > SHARED_RAM | ||
| 24 | } | ||
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index 9f4f0b238..3f381fd80 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs | |||
| @@ -1,11 +1,14 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::mem::MaybeUninit; | ||
| 5 | |||
| 4 | #[cfg(feature = "defmt")] | 6 | #[cfg(feature = "defmt")] |
| 5 | use defmt_rtt::*; | 7 | use defmt_rtt::*; |
| 6 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig}; | 8 | use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig}; |
| 7 | use embassy_embedded_hal::adapter::BlockingAsync; | 9 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 8 | use embassy_executor::Spawner; | 10 | use embassy_executor::Spawner; |
| 11 | use embassy_stm32::SharedData; | ||
| 9 | use embassy_stm32::exti::ExtiInput; | 12 | use embassy_stm32::exti::ExtiInput; |
| 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 13 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | 14 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| @@ -17,9 +20,12 @@ static APP_B: &[u8] = &[0, 1, 2, 3]; | |||
| 17 | #[cfg(not(feature = "skip-include"))] | 20 | #[cfg(not(feature = "skip-include"))] |
| 18 | static APP_B: &[u8] = include_bytes!("../../b.bin"); | 21 | static APP_B: &[u8] = include_bytes!("../../b.bin"); |
| 19 | 22 | ||
| 23 | #[unsafe(link_section = ".shared_data")] | ||
| 24 | static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit(); | ||
| 25 | |||
| 20 | #[embassy_executor::main] | 26 | #[embassy_executor::main] |
| 21 | async fn main(_spawner: Spawner) { | 27 | async fn main(_spawner: Spawner) { |
| 22 | let p = embassy_stm32::init(Default::default()); | 28 | let p = embassy_stm32::init_primary(Default::default(), &SHARED_DATA); |
| 23 | let flash = Flash::new_blocking(p.FLASH); | 29 | let flash = Flash::new_blocking(p.FLASH); |
| 24 | let flash = Mutex::new(BlockingAsync::new(flash)); | 30 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 25 | 31 | ||
diff --git a/examples/boot/application/stm32wl/src/bin/b.rs b/examples/boot/application/stm32wl/src/bin/b.rs index e954d8b91..952e94a58 100644 --- a/examples/boot/application/stm32wl/src/bin/b.rs +++ b/examples/boot/application/stm32wl/src/bin/b.rs | |||
| @@ -1,16 +1,22 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::mem::MaybeUninit; | ||
| 5 | |||
| 4 | #[cfg(feature = "defmt")] | 6 | #[cfg(feature = "defmt")] |
| 5 | use defmt_rtt::*; | 7 | use defmt_rtt::*; |
| 6 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::SharedData; | ||
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 10 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 9 | use panic_reset as _; | 12 | use panic_reset as _; |
| 10 | 13 | ||
| 14 | #[unsafe(link_section = ".shared_data")] | ||
| 15 | static SHARED_DATA: MaybeUninit<SharedData> = MaybeUninit::uninit(); | ||
| 16 | |||
| 11 | #[embassy_executor::main] | 17 | #[embassy_executor::main] |
| 12 | async fn main(_spawner: Spawner) { | 18 | async fn main(_spawner: Spawner) { |
| 13 | let p = embassy_stm32::init(Default::default()); | 19 | let p = embassy_stm32::init_primary(Default::default(), &SHARED_DATA); |
| 14 | let mut led = Output::new(p.PB15, Level::High, Speed::Low); | 20 | let mut led = Output::new(p.PB15, Level::High, Speed::Low); |
| 15 | 21 | ||
| 16 | loop { | 22 | loop { |
diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml index 9d5d51a13..1fea2b7d7 100644 --- a/examples/boot/bootloader/nrf/Cargo.toml +++ b/examples/boot/bootloader/nrf/Cargo.toml | |||
| @@ -1,18 +1,19 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "nrf-bootloader-example" | 3 | name = "nrf-bootloader-example" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | description = "Bootloader for nRF chips" | 5 | description = "Bootloader for nRF chips" |
| 6 | license = "MIT OR Apache-2.0" | 6 | license = "MIT OR Apache-2.0" |
| 7 | publish = false | ||
| 7 | 8 | ||
| 8 | [dependencies] | 9 | [dependencies] |
| 9 | defmt = { version = "0.3", optional = true } | 10 | defmt = { version = "1.0.1", optional = true } |
| 10 | defmt-rtt = { version = "0.4", optional = true } | 11 | defmt-rtt = { version = "1.0.0", optional = true } |
| 11 | 12 | ||
| 12 | embassy-nrf = { path = "../../../../embassy-nrf", features = [] } | 13 | embassy-nrf = { path = "../../../../embassy-nrf", features = [] } |
| 13 | embassy-boot-nrf = { path = "../../../../embassy-boot-nrf" } | 14 | embassy-boot-nrf = { path = "../../../../embassy-boot-nrf" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 15 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 16 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 16 | cortex-m-rt = { version = "0.7" } | 17 | cortex-m-rt = { version = "0.7" } |
| 17 | cfg-if = "1.0.0" | 18 | cfg-if = "1.0.0" |
| 18 | 19 | ||
| @@ -57,3 +58,12 @@ debug = false | |||
| 57 | debug-assertions = false | 58 | debug-assertions = false |
| 58 | opt-level = 0 | 59 | opt-level = 0 |
| 59 | overflow-checks = false | 60 | overflow-checks = false |
| 61 | |||
| 62 | [package.metadata.embassy] | ||
| 63 | build = [ | ||
| 64 | { target = "thumbv7em-none-eabi", features = ["embassy-nrf/nrf52840"] }, | ||
| 65 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9160-ns"] }, | ||
| 66 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9120-ns"] }, | ||
| 67 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9151-ns"] }, | ||
| 68 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-nrf/nrf9161-ns"] } | ||
| 69 | ] | ||
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs index 67c700437..76c4c1048 100644 --- a/examples/boot/bootloader/nrf/src/main.rs +++ b/examples/boot/bootloader/nrf/src/main.rs | |||
| @@ -8,7 +8,7 @@ use cortex_m_rt::{entry, exception}; | |||
| 8 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 9 | use embassy_boot_nrf::*; | 9 | use embassy_boot_nrf::*; |
| 10 | use embassy_nrf::nvmc::Nvmc; | 10 | use embassy_nrf::nvmc::Nvmc; |
| 11 | use embassy_nrf::wdt; | 11 | use embassy_nrf::wdt::{self, HaltConfig, SleepConfig}; |
| 12 | use embassy_sync::blocking_mutex::Mutex; | 12 | use embassy_sync::blocking_mutex::Mutex; |
| 13 | 13 | ||
| 14 | #[entry] | 14 | #[entry] |
| @@ -25,8 +25,8 @@ fn main() -> ! { | |||
| 25 | 25 | ||
| 26 | let mut wdt_config = wdt::Config::default(); | 26 | let mut wdt_config = wdt::Config::default(); |
| 27 | wdt_config.timeout_ticks = 32768 * 5; // timeout seconds | 27 | wdt_config.timeout_ticks = 32768 * 5; // timeout seconds |
| 28 | wdt_config.run_during_sleep = true; | 28 | wdt_config.action_during_sleep = SleepConfig::RUN; |
| 29 | wdt_config.run_during_debug_halt = false; | 29 | wdt_config.action_during_debug_halt = HaltConfig::PAUSE; |
| 30 | 30 | ||
| 31 | let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config); | 31 | let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config); |
| 32 | let flash = Mutex::new(RefCell::new(flash)); | 32 | let flash = Mutex::new(RefCell::new(flash)); |
| @@ -38,8 +38,8 @@ fn main() -> ! { | |||
| 38 | unsafe { bl.load(active_offset) } | 38 | unsafe { bl.load(active_offset) } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | #[no_mangle] | 41 | #[unsafe(no_mangle)] |
| 42 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | 42 | #[cfg_attr(target_os = "none", unsafe(link_section = ".HardFault.user"))] |
| 43 | unsafe extern "C" fn HardFault() { | 43 | unsafe extern "C" fn HardFault() { |
| 44 | cortex_m::peripheral::SCB::sys_reset(); | 44 | cortex_m::peripheral::SCB::sys_reset(); |
| 45 | } | 45 | } |
| @@ -47,7 +47,7 @@ unsafe extern "C" fn HardFault() { | |||
| 47 | #[exception] | 47 | #[exception] |
| 48 | unsafe fn DefaultHandler(_: i16) -> ! { | 48 | unsafe fn DefaultHandler(_: i16) -> ! { |
| 49 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | 49 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; |
| 50 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | 50 | let irqn = unsafe { core::ptr::read_volatile(SCB_ICSR) } as u8 as i16 - 16; |
| 51 | 51 | ||
| 52 | panic!("DefaultHandler #{:?}", irqn); | 52 | panic!("DefaultHandler #{:?}", irqn); |
| 53 | } | 53 | } |
diff --git a/examples/boot/bootloader/rp/Cargo.toml b/examples/boot/bootloader/rp/Cargo.toml index c15c980ca..188bcab36 100644 --- a/examples/boot/bootloader/rp/Cargo.toml +++ b/examples/boot/bootloader/rp/Cargo.toml | |||
| @@ -1,17 +1,18 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "rp-bootloader-example" | 3 | name = "rp-bootloader-example" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | description = "Example bootloader for RP2040 chips" | 5 | description = "Example bootloader for RP2040 chips" |
| 6 | license = "MIT OR Apache-2.0" | 6 | license = "MIT OR Apache-2.0" |
| 7 | publish = false | ||
| 7 | 8 | ||
| 8 | [dependencies] | 9 | [dependencies] |
| 9 | defmt = { version = "0.3", optional = true } | 10 | defmt = { version = "1.0.1", optional = true } |
| 10 | defmt-rtt = { version = "0.4", optional = true } | 11 | defmt-rtt = { version = "1.0.0", optional = true } |
| 11 | 12 | ||
| 12 | embassy-rp = { path = "../../../../embassy-rp", features = [] } | 13 | embassy-rp = { path = "../../../../embassy-rp", features = ["rp2040"] } |
| 13 | embassy-boot-rp = { path = "../../../../embassy-boot-rp" } | 14 | embassy-boot-rp = { path = "../../../../embassy-boot-rp" } |
| 14 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 15 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 15 | embassy-time = { path = "../../../../embassy-time", features = [] } | 16 | embassy-time = { path = "../../../../embassy-time", features = [] } |
| 16 | 17 | ||
| 17 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 18 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| @@ -31,3 +32,8 @@ defmt = [ | |||
| 31 | [profile.release] | 32 | [profile.release] |
| 32 | debug = true | 33 | debug = true |
| 33 | opt-level = 's' | 34 | opt-level = 's' |
| 35 | |||
| 36 | [package.metadata.embassy] | ||
| 37 | build = [ | ||
| 38 | { target = "thumbv6m-none-eabi" } | ||
| 39 | ] | ||
diff --git a/examples/boot/bootloader/rp/memory.x b/examples/boot/bootloader/rp/memory.x index c3b54976e..88b5bbb15 100644 --- a/examples/boot/bootloader/rp/memory.x +++ b/examples/boot/bootloader/rp/memory.x | |||
| @@ -2,7 +2,7 @@ MEMORY | |||
| 2 | { | 2 | { |
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 | 4 | BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 |
| 5 | FLASH : ORIGIN = 0x10000100, LENGTH = 24K | 5 | FLASH : ORIGIN = 0x10000100, LENGTH = 24K - 0x100 |
| 6 | BOOTLOADER_STATE : ORIGIN = 0x10006000, LENGTH = 4K | 6 | BOOTLOADER_STATE : ORIGIN = 0x10006000, LENGTH = 4K |
| 7 | ACTIVE : ORIGIN = 0x10007000, LENGTH = 512K | 7 | ACTIVE : ORIGIN = 0x10007000, LENGTH = 512K |
| 8 | DFU : ORIGIN = 0x10087000, LENGTH = 516K | 8 | DFU : ORIGIN = 0x10087000, LENGTH = 516K |
diff --git a/examples/boot/bootloader/rp/src/main.rs b/examples/boot/bootloader/rp/src/main.rs index 25b1657b8..7ebefd374 100644 --- a/examples/boot/bootloader/rp/src/main.rs +++ b/examples/boot/bootloader/rp/src/main.rs | |||
| @@ -34,8 +34,8 @@ fn main() -> ! { | |||
| 34 | unsafe { bl.load(embassy_rp::flash::FLASH_BASE as u32 + active_offset) } | 34 | unsafe { bl.load(embassy_rp::flash::FLASH_BASE as u32 + active_offset) } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | #[no_mangle] | 37 | #[unsafe(no_mangle)] |
| 38 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | 38 | #[cfg_attr(target_os = "none", unsafe(link_section = ".HardFault.user"))] |
| 39 | unsafe extern "C" fn HardFault() { | 39 | unsafe extern "C" fn HardFault() { |
| 40 | cortex_m::peripheral::SCB::sys_reset(); | 40 | cortex_m::peripheral::SCB::sys_reset(); |
| 41 | } | 41 | } |
| @@ -43,7 +43,7 @@ unsafe extern "C" fn HardFault() { | |||
| 43 | #[exception] | 43 | #[exception] |
| 44 | unsafe fn DefaultHandler(_: i16) -> ! { | 44 | unsafe fn DefaultHandler(_: i16) -> ! { |
| 45 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | 45 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; |
| 46 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | 46 | let irqn = unsafe { core::ptr::read_volatile(SCB_ICSR) } as u8 as i16 - 16; |
| 47 | 47 | ||
| 48 | panic!("DefaultHandler #{:?}", irqn); | 48 | panic!("DefaultHandler #{:?}", irqn); |
| 49 | } | 49 | } |
diff --git a/examples/boot/bootloader/stm32-dual-bank/Cargo.toml b/examples/boot/bootloader/stm32-dual-bank/Cargo.toml index b91b05412..cf68921dc 100644 --- a/examples/boot/bootloader/stm32-dual-bank/Cargo.toml +++ b/examples/boot/bootloader/stm32-dual-bank/Cargo.toml | |||
| @@ -1,13 +1,14 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "stm32-bootloader-dual-bank-flash-example" | 3 | name = "stm32-bootloader-dual-bank-flash-example" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | description = "Example bootloader for dual-bank flash STM32 chips" | 5 | description = "Example bootloader for dual-bank flash STM32 chips" |
| 6 | license = "MIT OR Apache-2.0" | 6 | license = "MIT OR Apache-2.0" |
| 7 | publish = false | ||
| 7 | 8 | ||
| 8 | [dependencies] | 9 | [dependencies] |
| 9 | defmt = { version = "0.3", optional = true } | 10 | defmt = { version = "1.0.1", optional = true } |
| 10 | defmt-rtt = { version = "0.4", optional = true } | 11 | defmt-rtt = { version = "1.0.0", optional = true } |
| 11 | 12 | ||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | 13 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } |
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | 14 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } |
| @@ -15,7 +16,7 @@ cortex-m = { version = "0.7.6", features = [ | |||
| 15 | "inline-asm", | 16 | "inline-asm", |
| 16 | "critical-section-single-core", | 17 | "critical-section-single-core", |
| 17 | ] } | 18 | ] } |
| 18 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 19 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 19 | cortex-m-rt = { version = "0.7" } | 20 | cortex-m-rt = { version = "0.7" } |
| 20 | embedded-storage = "0.3.1" | 21 | embedded-storage = "0.3.1" |
| 21 | embedded-storage-async = "0.4.0" | 22 | embedded-storage-async = "0.4.0" |
| @@ -54,3 +55,8 @@ debug = false | |||
| 54 | debug-assertions = false | 55 | debug-assertions = false |
| 55 | opt-level = 0 | 56 | opt-level = 0 |
| 56 | overflow-checks = false | 57 | overflow-checks = false |
| 58 | |||
| 59 | [package.metadata.embassy] | ||
| 60 | build = [ | ||
| 61 | { target = "thumbv7em-none-eabi", features = ["embassy-stm32/stm32h743zi"] } | ||
| 62 | ] | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/src/main.rs b/examples/boot/bootloader/stm32-dual-bank/src/main.rs index 4d2e82d26..f0063fb5c 100644 --- a/examples/boot/bootloader/stm32-dual-bank/src/main.rs +++ b/examples/boot/bootloader/stm32-dual-bank/src/main.rs | |||
| @@ -7,7 +7,7 @@ use cortex_m_rt::{entry, exception}; | |||
| 7 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 8 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 9 | use embassy_boot_stm32::*; | 9 | use embassy_boot_stm32::*; |
| 10 | use embassy_stm32::flash::{Flash, BANK1_REGION}; | 10 | use embassy_stm32::flash::{BANK1_REGION, Flash}; |
| 11 | use embassy_sync::blocking_mutex::Mutex; | 11 | use embassy_sync::blocking_mutex::Mutex; |
| 12 | 12 | ||
| 13 | #[entry] | 13 | #[entry] |
| @@ -33,8 +33,8 @@ fn main() -> ! { | |||
| 33 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | 33 | unsafe { bl.load(BANK1_REGION.base + active_offset) } |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | #[no_mangle] | 36 | #[unsafe(no_mangle)] |
| 37 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | 37 | #[cfg_attr(target_os = "none", unsafe(link_section = ".HardFault.user"))] |
| 38 | unsafe extern "C" fn HardFault() { | 38 | unsafe extern "C" fn HardFault() { |
| 39 | cortex_m::peripheral::SCB::sys_reset(); | 39 | cortex_m::peripheral::SCB::sys_reset(); |
| 40 | } | 40 | } |
| @@ -42,7 +42,7 @@ unsafe extern "C" fn HardFault() { | |||
| 42 | #[exception] | 42 | #[exception] |
| 43 | unsafe fn DefaultHandler(_: i16) -> ! { | 43 | unsafe fn DefaultHandler(_: i16) -> ! { |
| 44 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | 44 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; |
| 45 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | 45 | let irqn = unsafe { core::ptr::read_volatile(SCB_ICSR) } as u8 as i16 - 16; |
| 46 | 46 | ||
| 47 | panic!("DefaultHandler #{:?}", irqn); | 47 | panic!("DefaultHandler #{:?}", irqn); |
| 48 | } | 48 | } |
diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml index 541186949..e457310b9 100644 --- a/examples/boot/bootloader/stm32/Cargo.toml +++ b/examples/boot/bootloader/stm32/Cargo.toml | |||
| @@ -1,18 +1,19 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "stm32-bootloader-example" | 3 | name = "stm32-bootloader-example" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | description = "Example bootloader for STM32 chips" | 5 | description = "Example bootloader for STM32 chips" |
| 6 | license = "MIT OR Apache-2.0" | 6 | license = "MIT OR Apache-2.0" |
| 7 | publish = false | ||
| 7 | 8 | ||
| 8 | [dependencies] | 9 | [dependencies] |
| 9 | defmt = { version = "0.3", optional = true } | 10 | defmt = { version = "1.0.1", optional = true } |
| 10 | defmt-rtt = { version = "0.4", optional = true } | 11 | defmt-rtt = { version = "1.0.0", optional = true } |
| 11 | 12 | ||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | 13 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } |
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | 14 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 15 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 16 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 16 | cortex-m-rt = { version = "0.7" } | 17 | cortex-m-rt = { version = "0.7" } |
| 17 | embedded-storage = "0.3.1" | 18 | embedded-storage = "0.3.1" |
| 18 | embedded-storage-async = "0.4.0" | 19 | embedded-storage-async = "0.4.0" |
| @@ -56,3 +57,8 @@ debug = false | |||
| 56 | debug-assertions = false | 57 | debug-assertions = false |
| 57 | opt-level = 0 | 58 | opt-level = 0 |
| 58 | overflow-checks = false | 59 | overflow-checks = false |
| 60 | |||
| 61 | [package.metadata.embassy] | ||
| 62 | build = [ | ||
| 63 | { target = "thumbv7em-none-eabi", features = ["embassy-stm32/stm32l496zg"] } | ||
| 64 | ] | ||
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs index 99a7a6a6b..383ad912d 100644 --- a/examples/boot/bootloader/stm32/src/main.rs +++ b/examples/boot/bootloader/stm32/src/main.rs | |||
| @@ -7,7 +7,7 @@ use cortex_m_rt::{entry, exception}; | |||
| 7 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 8 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 9 | use embassy_boot_stm32::*; | 9 | use embassy_boot_stm32::*; |
| 10 | use embassy_stm32::flash::{Flash, BANK1_REGION}; | 10 | use embassy_stm32::flash::{BANK1_REGION, Flash}; |
| 11 | use embassy_sync::blocking_mutex::Mutex; | 11 | use embassy_sync::blocking_mutex::Mutex; |
| 12 | 12 | ||
| 13 | #[entry] | 13 | #[entry] |
| @@ -32,8 +32,8 @@ fn main() -> ! { | |||
| 32 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | 32 | unsafe { bl.load(BANK1_REGION.base + active_offset) } |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | #[no_mangle] | 35 | #[unsafe(no_mangle)] |
| 36 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | 36 | #[cfg_attr(target_os = "none", unsafe(link_section = ".HardFault.user"))] |
| 37 | unsafe extern "C" fn HardFault() { | 37 | unsafe extern "C" fn HardFault() { |
| 38 | cortex_m::peripheral::SCB::sys_reset(); | 38 | cortex_m::peripheral::SCB::sys_reset(); |
| 39 | } | 39 | } |
| @@ -41,7 +41,7 @@ unsafe extern "C" fn HardFault() { | |||
| 41 | #[exception] | 41 | #[exception] |
| 42 | unsafe fn DefaultHandler(_: i16) -> ! { | 42 | unsafe fn DefaultHandler(_: i16) -> ! { |
| 43 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | 43 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; |
| 44 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | 44 | let irqn = unsafe { core::ptr::read_volatile(SCB_ICSR) } as u8 as i16 - 16; |
| 45 | 45 | ||
| 46 | panic!("DefaultHandler #{:?}", irqn); | 46 | panic!("DefaultHandler #{:?}", irqn); |
| 47 | } | 47 | } |
diff --git a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml index 9950ed7b6..75b7081df 100644 --- a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml +++ b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml | |||
| @@ -1,25 +1,26 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | edition = "2021" | 2 | edition = "2024" |
| 3 | name = "stm32wb-dfu-bootloader-example" | 3 | name = "stm32wb-dfu-bootloader-example" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | description = "Example USB DFUbootloader for the STM32WB series of chips" | 5 | description = "Example USB DFUbootloader for the STM32WB series of chips" |
| 6 | license = "MIT OR Apache-2.0" | 6 | license = "MIT OR Apache-2.0" |
| 7 | publish = false | ||
| 7 | 8 | ||
| 8 | [dependencies] | 9 | [dependencies] |
| 9 | defmt = { version = "0.3", optional = true } | 10 | defmt = { version = "1.0.1", optional = true } |
| 10 | defmt-rtt = { version = "0.4", optional = true } | 11 | defmt-rtt = { version = "1.0.0", optional = true } |
| 11 | 12 | ||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | 13 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } |
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | 14 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 15 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { version = "0.6.0", path = "../../../../embassy-sync" } | 16 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } |
| 16 | cortex-m-rt = { version = "0.7" } | 17 | cortex-m-rt = { version = "0.7" } |
| 17 | embedded-storage = "0.3.1" | 18 | embedded-storage = "0.3.1" |
| 18 | embedded-storage-async = "0.4.0" | 19 | embedded-storage-async = "0.4.0" |
| 19 | cfg-if = "1.0.0" | 20 | cfg-if = "1.0.0" |
| 20 | embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["dfu", "cortex-m"] } | 21 | embassy-usb-dfu = { version = "0.2.0", path = "../../../../embassy-usb-dfu", features = ["dfu", "cortex-m"] } |
| 21 | embassy-usb = { version = "0.2.0", path = "../../../../embassy-usb", default-features = false } | 22 | embassy-usb = { version = "0.5.1", path = "../../../../embassy-usb", default-features = false } |
| 22 | embassy-futures = { version = "0.1.1", path = "../../../../embassy-futures" } | 23 | embassy-futures = { version = "0.1.2", path = "../../../../embassy-futures" } |
| 23 | 24 | ||
| 24 | [features] | 25 | [features] |
| 25 | defmt = [ | 26 | defmt = [ |
| @@ -30,6 +31,7 @@ defmt = [ | |||
| 30 | "embassy-usb/defmt", | 31 | "embassy-usb/defmt", |
| 31 | "embassy-usb-dfu/defmt" | 32 | "embassy-usb-dfu/defmt" |
| 32 | ] | 33 | ] |
| 34 | verify = ["embassy-usb-dfu/ed25519-salty"] | ||
| 33 | 35 | ||
| 34 | [profile.dev] | 36 | [profile.dev] |
| 35 | debug = 2 | 37 | debug = 2 |
| @@ -61,3 +63,9 @@ debug = false | |||
| 61 | debug-assertions = false | 63 | debug-assertions = false |
| 62 | opt-level = 0 | 64 | opt-level = 0 |
| 63 | overflow-checks = false | 65 | overflow-checks = false |
| 66 | |||
| 67 | [package.metadata.embassy] | ||
| 68 | build = [ | ||
| 69 | { target = "thumbv7em-none-eabi", features = ["embassy-stm32/stm32wb55rg"] }, | ||
| 70 | { target = "thumbv7em-none-eabi", features = ["embassy-stm32/stm32wb55rg", "verify"] } | ||
| 71 | ] | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/README.md b/examples/boot/bootloader/stm32wb-dfu/README.md index d5c6ea57c..99a7002c4 100644 --- a/examples/boot/bootloader/stm32wb-dfu/README.md +++ b/examples/boot/bootloader/stm32wb-dfu/README.md | |||
| @@ -1,11 +1,63 @@ | |||
| 1 | # Bootloader for STM32 | 1 | # Bootloader for STM32 |
| 2 | 2 | ||
| 3 | The bootloader uses `embassy-boot` to interact with the flash. | 3 | This bootloader implementation uses `embassy-boot` and `embassy-usb-dfu` to manage firmware updates and interact with the flash memory on STM32WB55 devices. |
| 4 | 4 | ||
| 5 | # Usage | 5 | ## Prerequisites |
| 6 | 6 | ||
| 7 | Flash the bootloader | 7 | - Rust toolchain with `cargo` installed |
| 8 | - `cargo-flash` for flashing the bootloader | ||
| 9 | - `dfu-util` for firmware updates | ||
| 10 | - `cargo-binutils` for binary generation | ||
| 11 | |||
| 12 | ## Usage | ||
| 13 | |||
| 14 | ### 1. Flash the Bootloader | ||
| 15 | |||
| 16 | First, flash the bootloader to your device: | ||
| 8 | 17 | ||
| 9 | ``` | 18 | ``` |
| 10 | cargo flash --features embassy-stm32/stm32wb55rg --release --chip STM32WB55RGVx | 19 | cargo flash --features embassy-stm32/stm32wb55rg --release --chip STM32WB55RGVx |
| 11 | ``` | 20 | ``` |
| 21 | |||
| 22 | ### 2. Build and Flash Application | ||
| 23 | |||
| 24 | Generate your application binary and flash it using DFU: | ||
| 25 | |||
| 26 | ``` | ||
| 27 | cargo objcopy --release -- -O binary fw.bin | ||
| 28 | dfu-util -d c0de:cafe -w -D fw.bin | ||
| 29 | ``` | ||
| 30 | |||
| 31 | ### 3. Sign Updates Before Flashing (Optional) | ||
| 32 | |||
| 33 | Currently, embassy-usb-dfu only supports a limited implementation of the generic support for ed25519-based update verfication in embassy-boot. This implementation assumes that a signature is simply concatenated to the end of an update binary. For more details, please see https://embassy.dev/book/#_verification and/or refer to the documentation for embassy-boot-dfu. | ||
| 34 | |||
| 35 | To sign (and then verify) application updates, you will first need to generate a key pair: | ||
| 36 | |||
| 37 | ``` | ||
| 38 | signify-openbsd -G -n -p secrets/key.pub -s secrets/key.sec | ||
| 39 | tail -n1 secrets/key.pub | base64 -d -i - | dd ibs=10 skip=1 > secrets/key.pub.short | ||
| 40 | ``` | ||
| 41 | |||
| 42 | Then you will need to sign all you binaries with the private key: | ||
| 43 | |||
| 44 | ``` | ||
| 45 | cargo objcopy --release -- -O binary fw.bin | ||
| 46 | shasum -a 512 -b fw.bin | head -c128 | xxd -p -r > target/fw-hash.txt | ||
| 47 | signify-openbsd -S -s secrets/key.sec -m target/fw-hash.txt -x target/fw-hash.sig | ||
| 48 | cp fw.bin fw-signed.bin | ||
| 49 | tail -n1 target/fw-hash.sig | base64 -d -i - | dd ibs=10 skip=1 >> fw-signed.bin | ||
| 50 | dfu-util -d c0de:cafe -w -D fw-signed.bin | ||
| 51 | ``` | ||
| 52 | |||
| 53 | Finally, as shown in this example with the `verify` feature flag enabled, you then need to embed the public key into your bootloader so that it can verify update signatures. | ||
| 54 | |||
| 55 | N.B. Please note that the exact steps above are NOT a good example of how to manage your keys securely. In a production environment, you should take great care to ensure that (at least the private key) is protected and not leaked into your version control system. | ||
| 56 | |||
| 57 | ## Troubleshooting | ||
| 58 | |||
| 59 | - Make sure your device is in DFU mode before flashing | ||
| 60 | - Verify the USB VID:PID matches your device (c0de:cafe) | ||
| 61 | - Check USB connections if the device is not detected | ||
| 62 | - Make sure the transfer size option of `dfu-util` matches the bootloader configuration. By default, `dfu-util` will use the transfer size reported by the device, but you can override it with the `-t` option if needed. | ||
| 63 | - Make sure `control_buf` size is larger than or equal to the `usb_dfu` `BLOCK_SIZE` parameter (in this example, both are set to 4096 bytes). | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/memory.x b/examples/boot/bootloader/stm32wb-dfu/memory.x index 858062631..77c4d2ee2 100644 --- a/examples/boot/bootloader/stm32wb-dfu/memory.x +++ b/examples/boot/bootloader/stm32wb-dfu/memory.x | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | MEMORY | 1 | MEMORY |
| 2 | { | 2 | { |
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 24K | 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 48K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x0800C000, LENGTH = 4K |
| 6 | ACTIVE : ORIGIN = 0x08008000, LENGTH = 128K | 6 | ACTIVE : ORIGIN = 0x0800D000, LENGTH = 120K |
| 7 | DFU : ORIGIN = 0x08028000, LENGTH = 132K | 7 | DFU : ORIGIN = 0x0802B000, LENGTH = 120K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/secrets/key.pub.short b/examples/boot/bootloader/stm32wb-dfu/secrets/key.pub.short new file mode 100644 index 000000000..7a4de8585 --- /dev/null +++ b/examples/boot/bootloader/stm32wb-dfu/secrets/key.pub.short | |||
| @@ -0,0 +1 @@ | |||
| gB��p�M�S��z��Kg��!�F���!4�r \ No newline at end of file | |||
diff --git a/examples/boot/bootloader/stm32wb-dfu/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs index 093b39f9d..9ee82846d 100644 --- a/examples/boot/bootloader/stm32wb-dfu/src/main.rs +++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs | |||
| @@ -7,19 +7,30 @@ use cortex_m_rt::{entry, exception}; | |||
| 7 | #[cfg(feature = "defmt")] | 7 | #[cfg(feature = "defmt")] |
| 8 | use defmt_rtt as _; | 8 | use defmt_rtt as _; |
| 9 | use embassy_boot_stm32::*; | 9 | use embassy_boot_stm32::*; |
| 10 | use embassy_stm32::flash::{Flash, BANK1_REGION, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{BANK1_REGION, Flash, WRITE_SIZE}; |
| 11 | use embassy_stm32::rcc::WPAN_DEFAULT; | 11 | use embassy_stm32::rcc::WPAN_DEFAULT; |
| 12 | use embassy_stm32::usb::Driver; | 12 | use embassy_stm32::usb::Driver; |
| 13 | use embassy_stm32::{bind_interrupts, peripherals, usb}; | 13 | use embassy_stm32::{bind_interrupts, peripherals, usb}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | 14 | use embassy_sync::blocking_mutex::Mutex; |
| 15 | use embassy_usb::Builder; | 15 | use embassy_usb::{Builder, msos}; |
| 16 | use embassy_usb_dfu::consts::DfuAttributes; | 16 | use embassy_usb_dfu::consts::DfuAttributes; |
| 17 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; | 17 | use embassy_usb_dfu::{Control, ResetImmediate, usb_dfu}; |
| 18 | 18 | ||
| 19 | bind_interrupts!(struct Irqs { | 19 | bind_interrupts!(struct Irqs { |
| 20 | USB_LP => usb::InterruptHandler<peripherals::USB>; | 20 | USB_LP => usb::InterruptHandler<peripherals::USB>; |
| 21 | }); | 21 | }); |
| 22 | 22 | ||
| 23 | // This is a randomly generated GUID to allow clients on Windows to find your device. | ||
| 24 | // | ||
| 25 | // N.B. update to a custom GUID for your own device! | ||
| 26 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; | ||
| 27 | |||
| 28 | // This is a randomly generated example key. | ||
| 29 | // | ||
| 30 | // N.B. Please replace with your own! | ||
| 31 | #[cfg(feature = "verify")] | ||
| 32 | static PUBLIC_SIGNING_KEY: &[u8; 32] = include_bytes!("../secrets/key.pub.short"); | ||
| 33 | |||
| 23 | #[entry] | 34 | #[entry] |
| 24 | fn main() -> ! { | 35 | fn main() -> ! { |
| 25 | let mut config = embassy_stm32::Config::default(); | 36 | let mut config = embassy_stm32::Config::default(); |
| @@ -52,7 +63,13 @@ fn main() -> ! { | |||
| 52 | let mut config_descriptor = [0; 256]; | 63 | let mut config_descriptor = [0; 256]; |
| 53 | let mut bos_descriptor = [0; 256]; | 64 | let mut bos_descriptor = [0; 256]; |
| 54 | let mut control_buf = [0; 4096]; | 65 | let mut control_buf = [0; 4096]; |
| 55 | let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD); | 66 | |
| 67 | #[cfg(not(feature = "verify"))] | ||
| 68 | let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate); | ||
| 69 | |||
| 70 | #[cfg(feature = "verify")] | ||
| 71 | let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate, PUBLIC_SIGNING_KEY); | ||
| 72 | |||
| 56 | let mut builder = Builder::new( | 73 | let mut builder = Builder::new( |
| 57 | driver, | 74 | driver, |
| 58 | config, | 75 | config, |
| @@ -62,7 +79,28 @@ fn main() -> ! { | |||
| 62 | &mut control_buf, | 79 | &mut control_buf, |
| 63 | ); | 80 | ); |
| 64 | 81 | ||
| 65 | usb_dfu::<_, _, _, ResetImmediate, 4096>(&mut builder, &mut state); | 82 | // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows. |
| 83 | // Otherwise users need to do this manually using a tool like Zadig. | ||
| 84 | // | ||
| 85 | // It seems these always need to be at added at the device level for this to work and for | ||
| 86 | // composite devices they also need to be added on the function level (as shown later). | ||
| 87 | // | ||
| 88 | builder.msos_descriptor(msos::windows_version::WIN8_1, 2); | ||
| 89 | builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 90 | builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 91 | "DeviceInterfaceGUIDs", | ||
| 92 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 93 | )); | ||
| 94 | |||
| 95 | usb_dfu::<_, _, _, _, 4096>(&mut builder, &mut state, |func| { | ||
| 96 | // You likely don't have to add these function level headers if your USB device is not composite | ||
| 97 | // (i.e. if your device does not expose another interface in addition to DFU) | ||
| 98 | func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 99 | func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 100 | "DeviceInterfaceGUIDs", | ||
| 101 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 102 | )); | ||
| 103 | }); | ||
| 66 | 104 | ||
| 67 | let mut dev = builder.build(); | 105 | let mut dev = builder.build(); |
| 68 | embassy_futures::block_on(dev.run()); | 106 | embassy_futures::block_on(dev.run()); |
| @@ -71,8 +109,8 @@ fn main() -> ! { | |||
| 71 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | 109 | unsafe { bl.load(BANK1_REGION.base + active_offset) } |
| 72 | } | 110 | } |
| 73 | 111 | ||
| 74 | #[no_mangle] | 112 | #[unsafe(no_mangle)] |
| 75 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | 113 | #[cfg_attr(target_os = "none", unsafe(link_section = ".HardFault.user"))] |
| 76 | unsafe extern "C" fn HardFault() { | 114 | unsafe extern "C" fn HardFault() { |
| 77 | cortex_m::peripheral::SCB::sys_reset(); | 115 | cortex_m::peripheral::SCB::sys_reset(); |
| 78 | } | 116 | } |
| @@ -80,7 +118,7 @@ unsafe extern "C" fn HardFault() { | |||
| 80 | #[exception] | 118 | #[exception] |
| 81 | unsafe fn DefaultHandler(_: i16) -> ! { | 119 | unsafe fn DefaultHandler(_: i16) -> ! { |
| 82 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | 120 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; |
| 83 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | 121 | let irqn = unsafe { core::ptr::read_volatile(SCB_ICSR) } as u8 as i16 - 16; |
| 84 | 122 | ||
| 85 | panic!("DefaultHandler #{:?}", irqn); | 123 | panic!("DefaultHandler #{:?}", irqn); |
| 86 | } | 124 | } |
diff --git a/examples/boot/bootloader/stm32wba-dfu/.cargo/config.toml b/examples/boot/bootloader/stm32wba-dfu/.cargo/config.toml new file mode 100644 index 000000000..1896068d8 --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/.cargo/config.toml | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | runner = "probe-rs run --chip STM32WBA65RI" | ||
| 3 | |||
| 4 | [build] | ||
| 5 | target = "thumbv8m.main-none-eabihf" | ||
| 6 | |||
| 7 | [env] | ||
| 8 | DEFMT_LOG = "trace" | ||
diff --git a/examples/boot/bootloader/stm32wba-dfu/Cargo.toml b/examples/boot/bootloader/stm32wba-dfu/Cargo.toml new file mode 100644 index 000000000..eee2b2f71 --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/Cargo.toml | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2024" | ||
| 3 | name = "stm32wba6-dfu-bootloader-example" | ||
| 4 | version = "0.1.0" | ||
| 5 | description = "Example USB DFUbootloader for the STM32WBA series of chips" | ||
| 6 | license = "MIT OR Apache-2.0" | ||
| 7 | publish = false | ||
| 8 | |||
| 9 | [dependencies] | ||
| 10 | defmt = { version = "1.0.1", optional = true } | ||
| 11 | defmt-rtt = { version = "1.0.0", optional = true } | ||
| 12 | |||
| 13 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | ||
| 14 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | ||
| 15 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | ||
| 16 | embassy-sync = { version = "0.7.2", path = "../../../../embassy-sync" } | ||
| 17 | cortex-m-rt = { version = "0.7" } | ||
| 18 | embedded-storage = "0.3.1" | ||
| 19 | embedded-storage-async = "0.4.0" | ||
| 20 | cfg-if = "1.0.0" | ||
| 21 | embassy-usb-dfu = { version = "0.2.0", path = "../../../../embassy-usb-dfu", features = ["dfu", "cortex-m"] } | ||
| 22 | embassy-usb = { version = "0.5.1", path = "../../../../embassy-usb", default-features = false } | ||
| 23 | embassy-futures = { version = "0.1.2", path = "../../../../embassy-futures" } | ||
| 24 | |||
| 25 | [features] | ||
| 26 | defmt = [ | ||
| 27 | "dep:defmt", | ||
| 28 | "dep:defmt-rtt", | ||
| 29 | "embassy-boot-stm32/defmt", | ||
| 30 | "embassy-stm32/defmt", | ||
| 31 | "embassy-usb/defmt", | ||
| 32 | "embassy-usb-dfu/defmt" | ||
| 33 | ] | ||
| 34 | verify = ["embassy-usb-dfu/ed25519-salty"] | ||
| 35 | |||
| 36 | [profile.dev] | ||
| 37 | debug = 2 | ||
| 38 | debug-assertions = true | ||
| 39 | incremental = false | ||
| 40 | opt-level = 'z' | ||
| 41 | overflow-checks = true | ||
| 42 | |||
| 43 | [profile.release] | ||
| 44 | codegen-units = 1 | ||
| 45 | debug = 2 | ||
| 46 | debug-assertions = false | ||
| 47 | incremental = false | ||
| 48 | lto = 'fat' | ||
| 49 | opt-level = 'z' | ||
| 50 | overflow-checks = false | ||
| 51 | |||
| 52 | # do not optimize proc-macro crates = faster builds from scratch | ||
| 53 | [profile.dev.build-override] | ||
| 54 | codegen-units = 8 | ||
| 55 | debug = false | ||
| 56 | debug-assertions = false | ||
| 57 | opt-level = 0 | ||
| 58 | overflow-checks = false | ||
| 59 | |||
| 60 | [profile.release.build-override] | ||
| 61 | codegen-units = 8 | ||
| 62 | debug = false | ||
| 63 | debug-assertions = false | ||
| 64 | opt-level = 0 | ||
| 65 | overflow-checks = false | ||
| 66 | |||
| 67 | [package.metadata.embassy] | ||
| 68 | build = [ | ||
| 69 | { target = "thumbv8m.main-none-eabihf", features = ["embassy-stm32/stm32wba65ri", "verify"] } | ||
| 70 | ] | ||
diff --git a/examples/boot/bootloader/stm32wba-dfu/README.md b/examples/boot/bootloader/stm32wba-dfu/README.md new file mode 100644 index 000000000..d50164255 --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/README.md | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | # Bootloader for STM32 | ||
| 2 | |||
| 3 | This bootloader implementation uses `embassy-boot` and `embassy-usb-dfu` to manage firmware updates and interact with the flash memory on STM32WB55 devices. | ||
| 4 | |||
| 5 | ## Prerequisites | ||
| 6 | |||
| 7 | - Rust toolchain with `cargo` installed | ||
| 8 | - `cargo-flash` for flashing the bootloader | ||
| 9 | - `dfu-util` for firmware updates | ||
| 10 | - `cargo-binutils` for binary generation | ||
| 11 | |||
| 12 | ## Usage | ||
| 13 | |||
| 14 | ### 1. Flash the Bootloader | ||
| 15 | |||
| 16 | First, flash the bootloader to your device: | ||
| 17 | |||
| 18 | ``` | ||
| 19 | cargo flash --features embassy-stm32/stm32wba65ri --release --chip STM32WBA65RI | ||
| 20 | ``` | ||
| 21 | |||
| 22 | ### 2. Build and Flash Application | ||
| 23 | |||
| 24 | Generate your application binary and flash it using DFU: | ||
| 25 | |||
| 26 | ``` | ||
| 27 | cargo objcopy --release -- -O binary fw.bin | ||
| 28 | dfu-util -d c0de:cafe -w -D fw.bin | ||
| 29 | ``` | ||
| 30 | |||
| 31 | ### 3. Sign Updates Before Flashing (Optional) | ||
| 32 | |||
| 33 | Currently, embassy-usb-dfu only supports a limited implementation of the generic support for ed25519-based update verfication in embassy-boot. This implementation assumes that a signature is simply concatenated to the end of an update binary. For more details, please see https://embassy.dev/book/#_verification and/or refer to the documentation for embassy-boot-dfu. | ||
| 34 | |||
| 35 | To sign (and then verify) application updates, you will first need to generate a key pair: | ||
| 36 | |||
| 37 | ``` | ||
| 38 | signify-openbsd -G -n -p secrets/key.pub -s secrets/key.sec | ||
| 39 | tail -n1 secrets/key.pub | base64 -d -i - | dd ibs=10 skip=1 > secrets/key.pub.short | ||
| 40 | ``` | ||
| 41 | |||
| 42 | Then you will need to sign all you binaries with the private key: | ||
| 43 | |||
| 44 | ``` | ||
| 45 | cargo objcopy --release -- -O binary fw.bin | ||
| 46 | shasum -a 512 -b fw.bin | head -c128 | xxd -p -r > target/fw-hash.txt | ||
| 47 | signify-openbsd -S -s secrets/key.sec -m target/fw-hash.txt -x target/fw-hash.sig | ||
| 48 | cp fw.bin fw-signed.bin | ||
| 49 | tail -n1 target/fw-hash.sig | base64 -d -i - | dd ibs=10 skip=1 >> fw-signed.bin | ||
| 50 | dfu-util -d c0de:cafe -w -D fw-signed.bin | ||
| 51 | ``` | ||
| 52 | |||
| 53 | Finally, as shown in this example with the `verify` feature flag enabled, you then need to embed the public key into your bootloader so that it can verify update signatures. | ||
| 54 | |||
| 55 | N.B. Please note that the exact steps above are NOT a good example of how to manage your keys securely. In a production environment, you should take great care to ensure that (at least the private key) is protected and not leaked into your version control system. | ||
| 56 | |||
| 57 | ## Troubleshooting | ||
| 58 | |||
| 59 | - Make sure your device is in DFU mode before flashing | ||
| 60 | - Verify the USB VID:PID matches your device (c0de:cafe) | ||
| 61 | - Check USB connections if the device is not detected | ||
| 62 | - Make sure the transfer size option of `dfu-util` matches the bootloader configuration. By default, `dfu-util` will use the transfer size reported by the device, but you can override it with the `-t` option if needed. | ||
| 63 | - Make sure `control_buf` size is larger than or equal to the `usb_dfu` `BLOCK_SIZE` parameter (in this example, both are set to 4096 bytes). | ||
diff --git a/examples/boot/bootloader/stm32wba-dfu/build.rs b/examples/boot/bootloader/stm32wba-dfu/build.rs new file mode 100644 index 000000000..fd605991f --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/build.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | use std::env; | ||
| 2 | use std::fs::File; | ||
| 3 | use std::io::Write; | ||
| 4 | use std::path::PathBuf; | ||
| 5 | |||
| 6 | fn main() { | ||
| 7 | // Put `memory.x` in our output directory and ensure it's | ||
| 8 | // on the linker search path. | ||
| 9 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 10 | File::create(out.join("memory.x")) | ||
| 11 | .unwrap() | ||
| 12 | .write_all(include_bytes!("memory.x")) | ||
| 13 | .unwrap(); | ||
| 14 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 15 | |||
| 16 | // By default, Cargo will re-run a build script whenever | ||
| 17 | // any file in the project changes. By specifying `memory.x` | ||
| 18 | // here, we ensure the build script is only re-run when | ||
| 19 | // `memory.x` is changed. | ||
| 20 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 21 | |||
| 22 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 23 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 24 | if env::var("CARGO_FEATURE_DEFMT").is_ok() { | ||
| 25 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/examples/boot/bootloader/stm32wba-dfu/memory.x b/examples/boot/bootloader/stm32wba-dfu/memory.x new file mode 100644 index 000000000..105c9e960 --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/memory.x | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 80K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08014000, LENGTH = 8K | ||
| 6 | ACTIVE : ORIGIN = 0x08016000, LENGTH = 120K | ||
| 7 | DFU : ORIGIN = 0x0803C000, LENGTH = 160K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 400K | ||
| 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); \ No newline at end of file | ||
diff --git a/examples/boot/bootloader/stm32wba-dfu/secrets/key.pub.short b/examples/boot/bootloader/stm32wba-dfu/secrets/key.pub.short new file mode 100644 index 000000000..7a4de8585 --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/secrets/key.pub.short | |||
| @@ -0,0 +1 @@ | |||
| gB��p�M�S��z��Kg��!�F���!4�r \ No newline at end of file | |||
diff --git a/examples/boot/bootloader/stm32wba-dfu/src/main.rs b/examples/boot/bootloader/stm32wba-dfu/src/main.rs new file mode 100644 index 000000000..b33a75d95 --- /dev/null +++ b/examples/boot/bootloader/stm32wba-dfu/src/main.rs | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 6 | use cortex_m_rt::{entry, exception}; | ||
| 7 | #[cfg(feature = "defmt")] | ||
| 8 | use defmt_rtt as _; | ||
| 9 | use embassy_boot_stm32::*; | ||
| 10 | use embassy_stm32::flash::{BANK1_REGION, Flash, WRITE_SIZE}; | ||
| 11 | use embassy_stm32::usb::Driver; | ||
| 12 | use embassy_stm32::{Config, bind_interrupts, peripherals, usb}; | ||
| 13 | use embassy_sync::blocking_mutex::Mutex; | ||
| 14 | use embassy_usb::{Builder, msos}; | ||
| 15 | use embassy_usb_dfu::consts::DfuAttributes; | ||
| 16 | use embassy_usb_dfu::{Control, ResetImmediate, usb_dfu}; | ||
| 17 | |||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | USB_OTG_HS => usb::InterruptHandler<peripherals::USB_OTG_HS>; | ||
| 20 | }); | ||
| 21 | |||
| 22 | // This is a randomly generated GUID to allow clients on Windows to find your device. | ||
| 23 | // | ||
| 24 | // N.B. update to a custom GUID for your own device! | ||
| 25 | const DEVICE_INTERFACE_GUIDS: &[&str] = &["{EAA9A5DC-30BA-44BC-9232-606CDC875321}"]; | ||
| 26 | |||
| 27 | // This is a randomly generated example key. | ||
| 28 | // | ||
| 29 | // N.B. Please replace with your own! | ||
| 30 | #[cfg(feature = "verify")] | ||
| 31 | static PUBLIC_SIGNING_KEY: &[u8; 32] = include_bytes!("../secrets/key.pub.short"); | ||
| 32 | |||
| 33 | #[entry] | ||
| 34 | fn main() -> ! { | ||
| 35 | let mut config = Config::default(); | ||
| 36 | |||
| 37 | { | ||
| 38 | use embassy_stm32::rcc::*; | ||
| 39 | config.rcc.pll1 = Some(Pll { | ||
| 40 | source: PllSource::HSI, | ||
| 41 | prediv: PllPreDiv::DIV1, // PLLM = 1 → HSI / 1 = 16 MHz | ||
| 42 | mul: PllMul::MUL30, // PLLN = 30 → 16 MHz * 30 = 480 MHz VCO | ||
| 43 | divr: Some(PllDiv::DIV5), // PLLR = 5 → 96 MHz (Sysclk) | ||
| 44 | divq: Some(PllDiv::DIV10), // PLLQ = 10 → 48 MHz | ||
| 45 | divp: Some(PllDiv::DIV30), // PLLP = 30 → 16 MHz (USB_OTG_HS) | ||
| 46 | frac: Some(0), // Fractional part (disabled) | ||
| 47 | }); | ||
| 48 | |||
| 49 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 50 | config.rcc.apb1_pre = APBPrescaler::DIV1; | ||
| 51 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 52 | config.rcc.apb7_pre = APBPrescaler::DIV1; | ||
| 53 | config.rcc.ahb5_pre = AHB5Prescaler::DIV4; | ||
| 54 | |||
| 55 | config.rcc.voltage_scale = VoltageScale::RANGE1; | ||
| 56 | config.rcc.mux.otghssel = mux::Otghssel::PLL1_P; | ||
| 57 | config.rcc.sys = Sysclk::PLL1_R; | ||
| 58 | } | ||
| 59 | |||
| 60 | let p = embassy_stm32::init(config); | ||
| 61 | |||
| 62 | // Prevent a hard fault when accessing flash 'too early' after boot. | ||
| 63 | #[cfg(feature = "defmt")] | ||
| 64 | for _ in 0..10000000 { | ||
| 65 | cortex_m::asm::nop(); | ||
| 66 | } | ||
| 67 | |||
| 68 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | ||
| 69 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); | ||
| 70 | |||
| 71 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); | ||
| 72 | let active_offset = config.active.offset(); | ||
| 73 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); | ||
| 74 | |||
| 75 | // Create the driver, from the HAL. | ||
| 76 | let mut ep_out_buffer = [0u8; 256]; | ||
| 77 | let mut config = embassy_stm32::usb::Config::default(); | ||
| 78 | |||
| 79 | config.vbus_detection = false; | ||
| 80 | |||
| 81 | if bl.state == State::DfuDetach { | ||
| 82 | let driver = Driver::new_hs(p.USB_OTG_HS, Irqs, p.PD6, p.PD7, &mut ep_out_buffer, config); | ||
| 83 | let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); | ||
| 84 | config.manufacturer = Some("Embassy"); | ||
| 85 | config.product = Some("USB-DFU Bootloader example"); | ||
| 86 | config.serial_number = Some("1235678"); | ||
| 87 | |||
| 88 | let fw_config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); | ||
| 89 | let mut buffer = AlignedBuffer([0; WRITE_SIZE]); | ||
| 90 | let updater = BlockingFirmwareUpdater::new(fw_config, &mut buffer.0[..]); | ||
| 91 | |||
| 92 | let mut config_descriptor = [0; 256]; | ||
| 93 | let mut bos_descriptor = [0; 256]; | ||
| 94 | let mut control_buf = [0; 4096]; | ||
| 95 | |||
| 96 | #[cfg(not(feature = "verify"))] | ||
| 97 | let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate); | ||
| 98 | |||
| 99 | #[cfg(feature = "verify")] | ||
| 100 | let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD, ResetImmediate, PUBLIC_SIGNING_KEY); | ||
| 101 | |||
| 102 | let mut builder = Builder::new( | ||
| 103 | driver, | ||
| 104 | config, | ||
| 105 | &mut config_descriptor, | ||
| 106 | &mut bos_descriptor, | ||
| 107 | &mut [], | ||
| 108 | &mut control_buf, | ||
| 109 | ); | ||
| 110 | |||
| 111 | // We add MSOS headers so that the device automatically gets assigned the WinUSB driver on Windows. | ||
| 112 | // Otherwise users need to do this manually using a tool like Zadig. | ||
| 113 | // | ||
| 114 | // It seems these always need to be at added at the device level for this to work and for | ||
| 115 | // composite devices they also need to be added on the function level (as shown later). | ||
| 116 | |||
| 117 | builder.msos_descriptor(msos::windows_version::WIN8_1, 2); | ||
| 118 | builder.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 119 | builder.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 120 | "DeviceInterfaceGUIDs", | ||
| 121 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 122 | )); | ||
| 123 | |||
| 124 | usb_dfu::<_, _, _, _, 4096>(&mut builder, &mut state, |func| { | ||
| 125 | // You likely don't have to add these function level headers if your USB device is not composite | ||
| 126 | // (i.e. if your device does not expose another interface in addition to DFU) | ||
| 127 | func.msos_feature(msos::CompatibleIdFeatureDescriptor::new("WINUSB", "")); | ||
| 128 | func.msos_feature(msos::RegistryPropertyFeatureDescriptor::new( | ||
| 129 | "DeviceInterfaceGUIDs", | ||
| 130 | msos::PropertyData::RegMultiSz(DEVICE_INTERFACE_GUIDS), | ||
| 131 | )); | ||
| 132 | }); | ||
| 133 | |||
| 134 | let mut dev = builder.build(); | ||
| 135 | embassy_futures::block_on(dev.run()); | ||
| 136 | } | ||
| 137 | |||
| 138 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | ||
| 139 | } | ||
| 140 | |||
| 141 | #[unsafe(no_mangle)] | ||
| 142 | #[cfg_attr(target_os = "none", unsafe(link_section = ".HardFault.user"))] | ||
| 143 | unsafe extern "C" fn HardFault() { | ||
| 144 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 145 | } | ||
| 146 | |||
| 147 | #[exception] | ||
| 148 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 149 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | ||
| 150 | let irqn = unsafe { core::ptr::read_volatile(SCB_ICSR) } as u8 as i16 - 16; | ||
| 151 | |||
| 152 | panic!("DefaultHandler #{:?}", irqn); | ||
| 153 | } | ||
| 154 | |||
| 155 | #[panic_handler] | ||
| 156 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 157 | cortex_m::asm::udf(); | ||
| 158 | } | ||
