diff options
Diffstat (limited to 'examples/boot')
57 files changed, 646 insertions, 99 deletions
diff --git a/examples/boot/.cargo/config.toml b/examples/boot/.cargo/config.toml index de3a814f7..be1b73e45 100644 --- a/examples/boot/.cargo/config.toml +++ b/examples/boot/.cargo/config.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [unstable] | 1 | [unstable] |
| 2 | build-std = ["core"] | 2 | #build-std = ["core"] |
| 3 | build-std-features = ["panic_immediate_abort"] | 3 | #build-std-features = ["panic_immediate_abort"] |
| 4 | 4 | ||
| 5 | [build] | 5 | [build] |
| 6 | target = "thumbv7em-none-eabi" | 6 | target = "thumbv7em-none-eabi" |
diff --git a/examples/boot/application/nrf/Cargo.toml b/examples/boot/application/nrf/Cargo.toml index 5f11750b2..86f6676cb 100644 --- a/examples/boot/application/nrf/Cargo.toml +++ b/examples/boot/application/nrf/Cargo.toml | |||
| @@ -6,11 +6,11 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] } | 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-time = { version = "0.2", path = "../../../../embassy-time", features = [] } | 10 | embassy-time = { version = "0.3.0", path = "../../../../embassy-time", features = [] } |
| 11 | embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] } | 11 | embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", ] } |
| 12 | embassy-boot = { version = "0.1.0", path = "../../../../embassy-boot/boot", features = [] } | 12 | embassy-boot = { version = "0.2.0", path = "../../../../embassy-boot", features = [] } |
| 13 | embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf", features = [] } | 13 | embassy-boot-nrf = { version = "0.2.0", path = "../../../../embassy-boot-nrf", features = [] } |
| 14 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 14 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 15 | 15 | ||
| 16 | defmt = { version = "0.3", optional = true } | 16 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 8b510ed35..851a3d721 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![macro_use] | 3 | #![macro_use] |
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | 4 | ||
| 6 | use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig}; | 5 | use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig}; |
| 7 | use embassy_embedded_hal::adapter::BlockingAsync; | 6 | use embassy_embedded_hal::adapter::BlockingAsync; |
| @@ -51,7 +50,7 @@ async fn main(_spawner: Spawner) { | |||
| 51 | let nvmc = Nvmc::new(p.NVMC); | 50 | let nvmc = Nvmc::new(p.NVMC); |
| 52 | let nvmc = Mutex::new(BlockingAsync::new(nvmc)); | 51 | let nvmc = Mutex::new(BlockingAsync::new(nvmc)); |
| 53 | 52 | ||
| 54 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc); | 53 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc, &nvmc); |
| 55 | let mut magic = [0; 4]; | 54 | let mut magic = [0; 4]; |
| 56 | let mut updater = FirmwareUpdater::new(config, &mut magic); | 55 | let mut updater = FirmwareUpdater::new(config, &mut magic); |
| 57 | loop { | 56 | loop { |
diff --git a/examples/boot/application/nrf/src/bin/b.rs b/examples/boot/application/nrf/src/bin/b.rs index a88c3c56c..de97b6a22 100644 --- a/examples/boot/application/nrf/src/bin/b.rs +++ b/examples/boot/application/nrf/src/bin/b.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![macro_use] | 3 | #![macro_use] |
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | 4 | ||
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 6 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
diff --git a/examples/boot/application/rp/.cargo/config.toml b/examples/boot/application/rp/.cargo/config.toml index cd8d1ef02..22ab3a5c1 100644 --- a/examples/boot/application/rp/.cargo/config.toml +++ b/examples/boot/application/rp/.cargo/config.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [unstable] | 1 | [unstable] |
| 2 | build-std = ["core"] | 2 | #build-std = ["core"] |
| 3 | build-std-features = ["panic_immediate_abort"] | 3 | #build-std-features = ["panic_immediate_abort"] |
| 4 | 4 | ||
| 5 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 5 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 6 | runner = "probe-rs run --chip RP2040" | 6 | runner = "probe-rs run --chip RP2040" |
diff --git a/examples/boot/application/rp/Cargo.toml b/examples/boot/application/rp/Cargo.toml index 89ac5a8f6..70741a0ce 100644 --- a/examples/boot/application/rp/Cargo.toml +++ b/examples/boot/application/rp/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] } | 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-time = { version = "0.2", path = "../../../../embassy-time", features = [] } | 10 | embassy-time = { version = "0.3.0", path = "../../../../embassy-time", features = [] } |
| 11 | embassy-rp = { version = "0.1.0", path = "../../../../embassy-rp", features = ["time-driver", ] } | 11 | embassy-rp = { version = "0.1.0", path = "../../../../embassy-rp", features = ["time-driver", ] } |
| 12 | embassy-boot-rp = { version = "0.1.0", path = "../../../../embassy-boot/rp", features = [] } | 12 | embassy-boot-rp = { version = "0.2.0", path = "../../../../embassy-boot-rp", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = "0.3" | 15 | defmt = "0.3" |
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs index 6fd5d7f60..ede0c07da 100644 --- a/examples/boot/application/rp/src/bin/a.rs +++ b/examples/boot/application/rp/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use core::cell::RefCell; | 4 | use core::cell::RefCell; |
| 6 | 5 | ||
| @@ -37,7 +36,7 @@ async fn main(_s: Spawner) { | |||
| 37 | let flash = Flash::<_, _, FLASH_SIZE>::new_blocking(p.FLASH); | 36 | let flash = Flash::<_, _, FLASH_SIZE>::new_blocking(p.FLASH); |
| 38 | let flash = Mutex::new(RefCell::new(flash)); | 37 | let flash = Mutex::new(RefCell::new(flash)); |
| 39 | 38 | ||
| 40 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 39 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 41 | let mut aligned = AlignedBuffer([0; 1]); | 40 | let mut aligned = AlignedBuffer([0; 1]); |
| 42 | let mut updater = BlockingFirmwareUpdater::new(config, &mut aligned.0); | 41 | let mut updater = BlockingFirmwareUpdater::new(config, &mut aligned.0); |
| 43 | 42 | ||
diff --git a/examples/boot/application/rp/src/bin/b.rs b/examples/boot/application/rp/src/bin/b.rs index 1eca5b4a2..a46d095bf 100644 --- a/examples/boot/application/rp/src/bin/b.rs +++ b/examples/boot/application/rp/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 6 | use embassy_rp::gpio; | 5 | use embassy_rp::gpio; |
diff --git a/examples/boot/application/stm32f3/Cargo.toml b/examples/boot/application/stm32f3/Cargo.toml index 1a0f8cee5..1cb143820 100644 --- a/examples/boot/application/stm32f3/Cargo.toml +++ b/examples/boot/application/stm32f3/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.3.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"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f303re", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32" } | 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32" } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/stm32f3/memory.x b/examples/boot/application/stm32f3/memory.x index f51875766..02ebe3ecf 100644 --- a/examples/boot/application/stm32f3/memory.x +++ b/examples/boot/application/stm32f3/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 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 = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 66K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index 8be39bfb7..8858ae3da 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
| @@ -9,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 9 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 14 | use panic_reset as _; | 13 | use panic_reset as _; |
| 15 | 14 | ||
| @@ -24,13 +23,12 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let flash = Flash::new_blocking(p.FLASH); | 23 | let flash = Flash::new_blocking(p.FLASH); |
| 25 | let flash = Mutex::new(BlockingAsync::new(flash)); | 24 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 26 | 25 | ||
| 27 | let button = Input::new(p.PC13, Pull::Up); | 26 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 28 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 29 | 27 | ||
| 30 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); |
| 31 | led.set_high(); | 29 | led.set_high(); |
| 32 | 30 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 36 | button.wait_for_falling_edge().await; | 34 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32f3/src/bin/b.rs b/examples/boot/application/stm32f3/src/bin/b.rs index 8411f384c..22ba82d5e 100644 --- a/examples/boot/application/stm32f3/src/bin/b.rs +++ b/examples/boot/application/stm32f3/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
diff --git a/examples/boot/application/stm32f7/Cargo.toml b/examples/boot/application/stm32f7/Cargo.toml index e42d1d421..c4ae461a5 100644 --- a/examples/boot/application/stm32f7/Cargo.toml +++ b/examples/boot/application/stm32f7/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.3.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"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32f767zi", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } | 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index 0c3819bed..d3df11fe4 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use core::cell::RefCell; | 4 | use core::cell::RefCell; |
| 6 | 5 | ||
| @@ -10,7 +9,7 @@ use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdater | |||
| 10 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 11 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 12 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 13 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | 13 | use embassy_sync::blocking_mutex::Mutex; |
| 15 | use embedded_storage::nor_flash::NorFlash; | 14 | use embedded_storage::nor_flash::NorFlash; |
| 16 | use panic_reset as _; | 15 | use panic_reset as _; |
| @@ -26,13 +25,12 @@ async fn main(_spawner: Spawner) { | |||
| 26 | let flash = Flash::new_blocking(p.FLASH); | 25 | let flash = Flash::new_blocking(p.FLASH); |
| 27 | let flash = Mutex::new(RefCell::new(flash)); | 26 | let flash = Mutex::new(RefCell::new(flash)); |
| 28 | 27 | ||
| 29 | let button = Input::new(p.PC13, Pull::Down); | 28 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 30 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 31 | 29 | ||
| 32 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); | 30 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); |
| 33 | led.set_high(); | 31 | led.set_high(); |
| 34 | 32 | ||
| 35 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 36 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 37 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); |
| 38 | let writer = updater.prepare_update().unwrap(); | 36 | let writer = updater.prepare_update().unwrap(); |
diff --git a/examples/boot/application/stm32f7/src/bin/b.rs b/examples/boot/application/stm32f7/src/bin/b.rs index 4c2ad06a2..190477204 100644 --- a/examples/boot/application/stm32f7/src/bin/b.rs +++ b/examples/boot/application/stm32f7/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml index 8450d8639..995487cdd 100644 --- a/examples/boot/application/stm32h7/Cargo.toml +++ b/examples/boot/application/stm32h7/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.3.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"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32h743zi", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } | 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index f239e3732..f61ac1f71 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use core::cell::RefCell; | 4 | use core::cell::RefCell; |
| 6 | 5 | ||
| @@ -10,7 +9,7 @@ use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdater | |||
| 10 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 11 | use embassy_stm32::exti::ExtiInput; | 10 | use embassy_stm32::exti::ExtiInput; |
| 12 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 13 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 12 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 14 | use embassy_sync::blocking_mutex::Mutex; | 13 | use embassy_sync::blocking_mutex::Mutex; |
| 15 | use embedded_storage::nor_flash::NorFlash; | 14 | use embedded_storage::nor_flash::NorFlash; |
| 16 | use panic_reset as _; | 15 | use panic_reset as _; |
| @@ -26,13 +25,12 @@ async fn main(_spawner: Spawner) { | |||
| 26 | let flash = Flash::new_blocking(p.FLASH); | 25 | let flash = Flash::new_blocking(p.FLASH); |
| 27 | let flash = Mutex::new(RefCell::new(flash)); | 26 | let flash = Mutex::new(RefCell::new(flash)); |
| 28 | 27 | ||
| 29 | let button = Input::new(p.PC13, Pull::Down); | 28 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 30 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 31 | 29 | ||
| 32 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 30 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 33 | led.set_high(); | 31 | led.set_high(); |
| 34 | 32 | ||
| 35 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 36 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 37 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); |
| 38 | let writer = updater.prepare_update().unwrap(); | 36 | let writer = updater.prepare_update().unwrap(); |
diff --git a/examples/boot/application/stm32h7/src/bin/b.rs b/examples/boot/application/stm32h7/src/bin/b.rs index 5c03e2d0c..5f3f35207 100644 --- a/examples/boot/application/stm32h7/src/bin/b.rs +++ b/examples/boot/application/stm32h7/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
diff --git a/examples/boot/application/stm32l0/Cargo.toml b/examples/boot/application/stm32l0/Cargo.toml index d6684bedb..b2abc005c 100644 --- a/examples/boot/application/stm32l0/Cargo.toml +++ b/examples/boot/application/stm32l0/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.3.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"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l072cz", "time-driver-any", "exti", "memory-x"] } |
| 12 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } | 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/stm32l0/memory.x b/examples/boot/application/stm32l0/memory.x index a99330145..8866506a8 100644 --- a/examples/boot/application/stm32l0/memory.x +++ b/examples/boot/application/stm32l0/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 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 = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 66K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs index 42e1a71eb..f066c1139 100644 --- a/examples/boot/application/stm32l0/src/bin/a.rs +++ b/examples/boot/application/stm32l0/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
| @@ -9,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 9 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 14 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 15 | use panic_reset as _; | 14 | use panic_reset as _; |
| @@ -25,14 +24,13 @@ async fn main(_spawner: Spawner) { | |||
| 25 | let flash = Flash::new_blocking(p.FLASH); | 24 | let flash = Flash::new_blocking(p.FLASH); |
| 26 | let flash = Mutex::new(BlockingAsync::new(flash)); | 25 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 27 | 26 | ||
| 28 | let button = Input::new(p.PB2, Pull::Up); | 27 | let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up); |
| 29 | let mut button = ExtiInput::new(button, p.EXTI2); | ||
| 30 | 28 | ||
| 31 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); | 29 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); |
| 32 | 30 | ||
| 33 | led.set_high(); | 31 | led.set_high(); |
| 34 | 32 | ||
| 35 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 36 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 37 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 38 | button.wait_for_falling_edge().await; | 36 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32l0/src/bin/b.rs b/examples/boot/application/stm32l0/src/bin/b.rs index 52d42395f..6bf00f41a 100644 --- a/examples/boot/application/stm32l0/src/bin/b.rs +++ b/examples/boot/application/stm32l0/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
diff --git a/examples/boot/application/stm32l1/Cargo.toml b/examples/boot/application/stm32l1/Cargo.toml index cca8bf443..7203e6350 100644 --- a/examples/boot/application/stm32l1/Cargo.toml +++ b/examples/boot/application/stm32l1/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.3.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"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l151cb-a", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } | 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/stm32l1/memory.x b/examples/boot/application/stm32l1/memory.x index a99330145..caa525278 100644 --- a/examples/boot/application/stm32l1/memory.x +++ b/examples/boot/application/stm32l1/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 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 = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 46K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08013800, LENGTH = 54K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index 42e1a71eb..f066c1139 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
| @@ -9,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 9 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 14 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 15 | use panic_reset as _; | 14 | use panic_reset as _; |
| @@ -25,14 +24,13 @@ async fn main(_spawner: Spawner) { | |||
| 25 | let flash = Flash::new_blocking(p.FLASH); | 24 | let flash = Flash::new_blocking(p.FLASH); |
| 26 | let flash = Mutex::new(BlockingAsync::new(flash)); | 25 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 27 | 26 | ||
| 28 | let button = Input::new(p.PB2, Pull::Up); | 27 | let mut button = ExtiInput::new(p.PB2, p.EXTI2, Pull::Up); |
| 29 | let mut button = ExtiInput::new(button, p.EXTI2); | ||
| 30 | 28 | ||
| 31 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); | 29 | let mut led = Output::new(p.PB5, Level::Low, Speed::Low); |
| 32 | 30 | ||
| 33 | led.set_high(); | 31 | led.set_high(); |
| 34 | 32 | ||
| 35 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 36 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 37 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 38 | button.wait_for_falling_edge().await; | 36 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32l1/src/bin/b.rs b/examples/boot/application/stm32l1/src/bin/b.rs index 52d42395f..6bf00f41a 100644 --- a/examples/boot/application/stm32l1/src/bin/b.rs +++ b/examples/boot/application/stm32l1/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
diff --git a/examples/boot/application/stm32l4/Cargo.toml b/examples/boot/application/stm32l4/Cargo.toml index 30d61056c..ec134f394 100644 --- a/examples/boot/application/stm32l4/Cargo.toml +++ b/examples/boot/application/stm32l4/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.3.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"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } | 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/stm32l4/memory.x b/examples/boot/application/stm32l4/memory.x index f51875766..e1d4e7fa8 100644 --- a/examples/boot/application/stm32l4/memory.x +++ b/examples/boot/application/stm32l4/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 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 = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 68K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index eefa25f75..a0079ee33 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
| @@ -9,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 9 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 14 | use panic_reset as _; | 13 | use panic_reset as _; |
| 15 | 14 | ||
| @@ -24,13 +23,12 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let flash = Flash::new_blocking(p.FLASH); | 23 | let flash = Flash::new_blocking(p.FLASH); |
| 25 | let flash = Mutex::new(BlockingAsync::new(flash)); | 24 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 26 | 25 | ||
| 27 | let button = Input::new(p.PC13, Pull::Up); | 26 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); |
| 28 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 29 | 27 | ||
| 30 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 31 | led.set_high(); | 29 | led.set_high(); |
| 32 | 30 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 36 | button.wait_for_falling_edge().await; | 34 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32l4/src/bin/b.rs b/examples/boot/application/stm32l4/src/bin/b.rs index 8411f384c..22ba82d5e 100644 --- a/examples/boot/application/stm32l4/src/bin/b.rs +++ b/examples/boot/application/stm32l4/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
diff --git a/examples/boot/application/stm32wb-dfu/.cargo/config.toml b/examples/boot/application/stm32wb-dfu/.cargo/config.toml new file mode 100644 index 000000000..4f8094ff2 --- /dev/null +++ b/examples/boot/application/stm32wb-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 STM32WLE5JCIx" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabihf" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_LOG = "trace" | ||
diff --git a/examples/boot/application/stm32wb-dfu/Cargo.toml b/examples/boot/application/stm32wb-dfu/Cargo.toml new file mode 100644 index 000000000..0bdf94331 --- /dev/null +++ b/examples/boot/application/stm32wb-dfu/Cargo.toml | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-boot-stm32wb-dfu-examples" | ||
| 4 | version = "0.1.0" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | embassy-sync = { version = "0.5.0", 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-time = { version = "0.3.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-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } | ||
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | ||
| 14 | embassy-usb = { version = "0.1.0", path = "../../../../embassy-usb" } | ||
| 15 | embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["application", "cortex-m"] } | ||
| 16 | |||
| 17 | defmt = { version = "0.3", optional = true } | ||
| 18 | defmt-rtt = { version = "0.4", optional = true } | ||
| 19 | panic-reset = { version = "0.1.1" } | ||
| 20 | embedded-hal = { version = "0.2.6" } | ||
| 21 | |||
| 22 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | ||
| 23 | cortex-m-rt = "0.7.0" | ||
| 24 | |||
| 25 | [features] | ||
| 26 | defmt = [ | ||
| 27 | "dep:defmt", | ||
| 28 | "dep:defmt-rtt", | ||
| 29 | "embassy-stm32/defmt", | ||
| 30 | "embassy-boot-stm32/defmt", | ||
| 31 | "embassy-sync/defmt", | ||
| 32 | ] | ||
diff --git a/examples/boot/application/stm32wb-dfu/README.md b/examples/boot/application/stm32wb-dfu/README.md new file mode 100644 index 000000000..7f656cde6 --- /dev/null +++ b/examples/boot/application/stm32wb-dfu/README.md | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # Examples using bootloader | ||
| 2 | |||
| 3 | Example for STM32WB demonstrating the USB DFU application. | ||
| 4 | |||
| 5 | ## Usage | ||
| 6 | |||
| 7 | ``` | ||
| 8 | cargo flash --release --chip STM32WB55RGVx | ||
| 9 | ``` | ||
diff --git a/examples/boot/application/stm32wb-dfu/build.rs b/examples/boot/application/stm32wb-dfu/build.rs new file mode 100644 index 000000000..e1da69328 --- /dev/null +++ b/examples/boot/application/stm32wb-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/stm32wb-dfu/memory.x b/examples/boot/application/stm32wb-dfu/memory.x new file mode 100644 index 000000000..ff1b800d2 --- /dev/null +++ b/examples/boot/application/stm32wb-dfu/memory.x | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | ||
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 128K | ||
| 7 | DFU : ORIGIN = 0x08028000, LENGTH = 132K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(BOOTLOADER); | ||
| 13 | |||
| 14 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(BOOTLOADER); | ||
| 15 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(BOOTLOADER); | ||
diff --git a/examples/boot/application/stm32wb-dfu/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs new file mode 100644 index 000000000..929d6802c --- /dev/null +++ b/examples/boot/application/stm32wb-dfu/src/main.rs | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 6 | #[cfg(feature = "defmt-rtt")] | ||
| 7 | use defmt_rtt::*; | ||
| 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::rcc::WPAN_DEFAULT; | ||
| 12 | use embassy_stm32::usb::{self, Driver}; | ||
| 13 | use embassy_stm32::{bind_interrupts, peripherals}; | ||
| 14 | use embassy_sync::blocking_mutex::Mutex; | ||
| 15 | use embassy_time::Duration; | ||
| 16 | use embassy_usb::Builder; | ||
| 17 | use embassy_usb_dfu::consts::DfuAttributes; | ||
| 18 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; | ||
| 19 | use panic_reset as _; | ||
| 20 | |||
| 21 | bind_interrupts!(struct Irqs { | ||
| 22 | USB_LP => usb::InterruptHandler<peripherals::USB>; | ||
| 23 | }); | ||
| 24 | |||
| 25 | #[embassy_executor::main] | ||
| 26 | async fn main(_spawner: Spawner) { | ||
| 27 | let mut config = embassy_stm32::Config::default(); | ||
| 28 | config.rcc = WPAN_DEFAULT; | ||
| 29 | let p = embassy_stm32::init(config); | ||
| 30 | let flash = Flash::new_blocking(p.FLASH); | ||
| 31 | let flash = Mutex::new(RefCell::new(flash)); | ||
| 32 | |||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); | ||
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | ||
| 35 | let mut firmware_state = BlockingFirmwareState::from_config(config, &mut magic.0); | ||
| 36 | firmware_state.mark_booted().expect("Failed to mark booted"); | ||
| 37 | |||
| 38 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); | ||
| 39 | let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); | ||
| 40 | config.manufacturer = Some("Embassy"); | ||
| 41 | config.product = Some("USB-DFU Runtime example"); | ||
| 42 | config.serial_number = Some("1235678"); | ||
| 43 | |||
| 44 | let mut config_descriptor = [0; 256]; | ||
| 45 | let mut bos_descriptor = [0; 256]; | ||
| 46 | let mut control_buf = [0; 64]; | ||
| 47 | let mut state = Control::new(firmware_state, DfuAttributes::CAN_DOWNLOAD); | ||
| 48 | let mut builder = Builder::new( | ||
| 49 | driver, | ||
| 50 | config, | ||
| 51 | &mut config_descriptor, | ||
| 52 | &mut bos_descriptor, | ||
| 53 | &mut [], | ||
| 54 | &mut control_buf, | ||
| 55 | ); | ||
| 56 | |||
| 57 | usb_dfu::<_, _, ResetImmediate>(&mut builder, &mut state, Duration::from_millis(2500)); | ||
| 58 | |||
| 59 | let mut dev = builder.build(); | ||
| 60 | dev.run().await | ||
| 61 | } | ||
diff --git a/examples/boot/application/stm32wl/Cargo.toml b/examples/boot/application/stm32wl/Cargo.toml index 7489a2fe9..e38e9f3af 100644 --- a/examples/boot/application/stm32wl/Cargo.toml +++ b/examples/boot/application/stm32wl/Cargo.toml | |||
| @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" | |||
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 8 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 9 | embassy-executor = { version = "0.4.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] } | 9 | embassy-executor = { version = "0.5.0", path = "../../../../embassy-executor", features = ["task-arena-size-8192", "arch-cortex-m", "executor-thread", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.2", path = "../../../../embassy-time", features = [ "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.3.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"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["stm32wl55jc-cm4", "time-driver-any", "exti"] } |
| 12 | embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = [] } | 12 | embassy-boot-stm32 = { version = "0.2.0", path = "../../../../embassy-boot-stm32", features = [] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" } |
| 14 | 14 | ||
| 15 | defmt = { version = "0.3", optional = true } | 15 | defmt = { version = "0.3", optional = true } |
diff --git a/examples/boot/application/stm32wl/memory.x b/examples/boot/application/stm32wl/memory.x index f51875766..e1d4e7fa8 100644 --- a/examples/boot/application/stm32wl/memory.x +++ b/examples/boot/application/stm32wl/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 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 = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 68K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index c837e47b5..2fb16bdc4 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
| @@ -9,7 +8,7 @@ use embassy_embedded_hal::adapter::BlockingAsync; | |||
| 9 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::exti::ExtiInput; | 9 | use embassy_stm32::exti::ExtiInput; |
| 11 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; | 10 | use embassy_stm32::flash::{Flash, WRITE_SIZE}; |
| 12 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 11 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 13 | use embassy_sync::mutex::Mutex; | 12 | use embassy_sync::mutex::Mutex; |
| 14 | use panic_reset as _; | 13 | use panic_reset as _; |
| 15 | 14 | ||
| @@ -24,13 +23,12 @@ async fn main(_spawner: Spawner) { | |||
| 24 | let flash = Flash::new_blocking(p.FLASH); | 23 | let flash = Flash::new_blocking(p.FLASH); |
| 25 | let flash = Mutex::new(BlockingAsync::new(flash)); | 24 | let flash = Mutex::new(BlockingAsync::new(flash)); |
| 26 | 25 | ||
| 27 | let button = Input::new(p.PA0, Pull::Up); | 26 | let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Up); |
| 28 | let mut button = ExtiInput::new(button, p.EXTI0); | ||
| 29 | 27 | ||
| 30 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); |
| 31 | led.set_high(); | 29 | led.set_high(); |
| 32 | 30 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 36 | button.wait_for_falling_edge().await; | 34 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32wl/src/bin/b.rs b/examples/boot/application/stm32wl/src/bin/b.rs index 1ca3c6ea8..8dd15d8cd 100644 --- a/examples/boot/application/stm32wl/src/bin/b.rs +++ b/examples/boot/application/stm32wl/src/bin/b.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | #[cfg(feature = "defmt-rtt")] | 4 | #[cfg(feature = "defmt-rtt")] |
| 6 | use defmt_rtt::*; | 5 | use defmt_rtt::*; |
diff --git a/examples/boot/bootloader/nrf/.cargo/config.toml b/examples/boot/bootloader/nrf/.cargo/config.toml index c292846aa..58acd1a49 100644 --- a/examples/boot/bootloader/nrf/.cargo/config.toml +++ b/examples/boot/bootloader/nrf/.cargo/config.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [unstable] | 1 | [unstable] |
| 2 | build-std = ["core"] | 2 | #build-std = ["core"] |
| 3 | build-std-features = ["panic_immediate_abort"] | 3 | #build-std-features = ["panic_immediate_abort"] |
| 4 | 4 | ||
| 5 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 5 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 6 | #runner = "./fruitrunner" | 6 | #runner = "./fruitrunner" |
| @@ -8,7 +8,7 @@ runner = "probe-rs run --chip nrf52840_xxAA" | |||
| 8 | 8 | ||
| 9 | rustflags = [ | 9 | rustflags = [ |
| 10 | # Code-size optimizations. | 10 | # Code-size optimizations. |
| 11 | "-Z", "trap-unreachable=no", | 11 | #"-Z", "trap-unreachable=no", |
| 12 | #"-C", "no-vectorize-loops", | 12 | #"-C", "no-vectorize-loops", |
| 13 | "-C", "force-frame-pointers=yes", | 13 | "-C", "force-frame-pointers=yes", |
| 14 | ] | 14 | ] |
diff --git a/examples/boot/bootloader/nrf/Cargo.toml b/examples/boot/bootloader/nrf/Cargo.toml index a7273175f..3e41d1479 100644 --- a/examples/boot/bootloader/nrf/Cargo.toml +++ b/examples/boot/bootloader/nrf/Cargo.toml | |||
| @@ -10,7 +10,7 @@ defmt = { version = "0.3", optional = true } | |||
| 10 | defmt-rtt = { version = "0.4", optional = true } | 10 | defmt-rtt = { version = "0.4", optional = true } |
| 11 | 11 | ||
| 12 | embassy-nrf = { path = "../../../../embassy-nrf", features = [] } | 12 | embassy-nrf = { path = "../../../../embassy-nrf", features = [] } |
| 13 | embassy-boot-nrf = { path = "../../../../embassy-boot/nrf" } | 13 | embassy-boot-nrf = { path = "../../../../embassy-boot-nrf" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 15 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 16 | cortex-m-rt = { version = "0.7" } | 16 | cortex-m-rt = { version = "0.7" } |
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs index 74e2e293f..67c700437 100644 --- a/examples/boot/bootloader/nrf/src/main.rs +++ b/examples/boot/bootloader/nrf/src/main.rs | |||
| @@ -31,7 +31,7 @@ fn main() -> ! { | |||
| 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)); |
| 33 | 33 | ||
| 34 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | 34 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); |
| 35 | let active_offset = config.active.offset(); | 35 | let active_offset = config.active.offset(); |
| 36 | let bl: BootLoader = BootLoader::prepare(config); | 36 | let bl: BootLoader = BootLoader::prepare(config); |
| 37 | 37 | ||
diff --git a/examples/boot/bootloader/rp/Cargo.toml b/examples/boot/bootloader/rp/Cargo.toml index 5bc61e9ec..3cf61a002 100644 --- a/examples/boot/bootloader/rp/Cargo.toml +++ b/examples/boot/bootloader/rp/Cargo.toml | |||
| @@ -10,7 +10,7 @@ defmt = { version = "0.3", optional = true } | |||
| 10 | defmt-rtt = { version = "0.4", optional = true } | 10 | defmt-rtt = { version = "0.4", optional = true } |
| 11 | 11 | ||
| 12 | embassy-rp = { path = "../../../../embassy-rp", features = [] } | 12 | embassy-rp = { path = "../../../../embassy-rp", features = [] } |
| 13 | embassy-boot-rp = { path = "../../../../embassy-boot/rp" } | 13 | embassy-boot-rp = { path = "../../../../embassy-boot-rp" } |
| 14 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 14 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 15 | embassy-time = { path = "../../../../embassy-time", features = [] } | 15 | embassy-time = { path = "../../../../embassy-time", features = [] } |
| 16 | 16 | ||
diff --git a/examples/boot/bootloader/rp/src/main.rs b/examples/boot/bootloader/rp/src/main.rs index c0e75d1ea..25b1657b8 100644 --- a/examples/boot/bootloader/rp/src/main.rs +++ b/examples/boot/bootloader/rp/src/main.rs | |||
| @@ -27,7 +27,7 @@ fn main() -> ! { | |||
| 27 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); | 27 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); |
| 28 | let flash = Mutex::new(RefCell::new(flash)); | 28 | let flash = Mutex::new(RefCell::new(flash)); |
| 29 | 29 | ||
| 30 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | 30 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); |
| 31 | let active_offset = config.active.offset(); | 31 | let active_offset = config.active.offset(); |
| 32 | let bl: BootLoader = BootLoader::prepare(config); | 32 | let bl: BootLoader = BootLoader::prepare(config); |
| 33 | 33 | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/Cargo.toml b/examples/boot/bootloader/stm32-dual-bank/Cargo.toml new file mode 100644 index 000000000..313187adc --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/Cargo.toml | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "stm32-bootloader-dual-bank-flash-example" | ||
| 4 | version = "0.1.0" | ||
| 5 | description = "Example bootloader for dual-bank flash STM32 chips" | ||
| 6 | license = "MIT OR Apache-2.0" | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | defmt = { version = "0.3", optional = true } | ||
| 10 | defmt-rtt = { version = "0.4", optional = true } | ||
| 11 | |||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | ||
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | ||
| 14 | cortex-m = { version = "0.7.6", features = [ | ||
| 15 | "inline-asm", | ||
| 16 | "critical-section-single-core", | ||
| 17 | ] } | ||
| 18 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | ||
| 19 | cortex-m-rt = { version = "0.7" } | ||
| 20 | embedded-storage = "0.3.1" | ||
| 21 | embedded-storage-async = "0.4.0" | ||
| 22 | cfg-if = "1.0.0" | ||
| 23 | |||
| 24 | [features] | ||
| 25 | defmt = ["dep:defmt", "embassy-boot-stm32/defmt", "embassy-stm32/defmt"] | ||
| 26 | debug = ["defmt-rtt", "defmt"] | ||
| 27 | |||
| 28 | [profile.dev] | ||
| 29 | debug = 2 | ||
| 30 | debug-assertions = true | ||
| 31 | incremental = false | ||
| 32 | opt-level = 'z' | ||
| 33 | overflow-checks = true | ||
| 34 | |||
| 35 | [profile.release] | ||
| 36 | codegen-units = 1 | ||
| 37 | debug = 2 | ||
| 38 | debug-assertions = false | ||
| 39 | incremental = false | ||
| 40 | lto = 'fat' | ||
| 41 | opt-level = 'z' | ||
| 42 | overflow-checks = false | ||
| 43 | |||
| 44 | # do not optimize proc-macro crates = faster builds from scratch | ||
| 45 | [profile.dev.build-override] | ||
| 46 | codegen-units = 8 | ||
| 47 | debug = false | ||
| 48 | debug-assertions = false | ||
| 49 | opt-level = 0 | ||
| 50 | overflow-checks = false | ||
| 51 | |||
| 52 | [profile.release.build-override] | ||
| 53 | codegen-units = 8 | ||
| 54 | debug = false | ||
| 55 | debug-assertions = false | ||
| 56 | opt-level = 0 | ||
| 57 | overflow-checks = false | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/README.md b/examples/boot/bootloader/stm32-dual-bank/README.md new file mode 100644 index 000000000..3de3171cd --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/README.md | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | # STM32 dual-bank flash Bootloader | ||
| 2 | |||
| 3 | ## Overview | ||
| 4 | |||
| 5 | This bootloader leverages `embassy-boot` to interact with the flash. | ||
| 6 | This example targets STM32 devices with dual-bank flash memory, with a primary focus on the STM32H747XI series. | ||
| 7 | Users must modify the `memory.x` configuration file to match with the memory layout of their specific STM32 device. | ||
| 8 | |||
| 9 | Additionally, this example can be extended to utilize external flash memory, such as QSPI, for storing partitions. | ||
| 10 | |||
| 11 | ## Memory Configuration | ||
| 12 | |||
| 13 | In this example's `memory.x` file, various symbols are defined to assist in effective memory management within the bootloader environment. | ||
| 14 | For dual-bank STM32 devices, it's crucial to assign these symbols correctly to their respective memory banks. | ||
| 15 | |||
| 16 | ### Symbol Definitions | ||
| 17 | |||
| 18 | The bootloader's state and active symbols are anchored to the flash origin of **bank 1**: | ||
| 19 | |||
| 20 | - `__bootloader_state_start` and `__bootloader_state_end` | ||
| 21 | - `__bootloader_active_start` and `__bootloader_active_end` | ||
| 22 | |||
| 23 | In contrast, the Device Firmware Upgrade (DFU) symbols are aligned with the DFU flash origin in **bank 2**: | ||
| 24 | |||
| 25 | - `__bootloader_dfu_start` and `__bootloader_dfu_end` | ||
| 26 | |||
| 27 | ```rust | ||
| 28 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(**FLASH**); | ||
| 29 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(**FLASH**); | ||
| 30 | |||
| 31 | __bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(**FLASH**); | ||
| 32 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(**FLASH**); | ||
| 33 | |||
| 34 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(**DFU**); | ||
| 35 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(**DFU**); | ||
| 36 | ``` | ||
| 37 | |||
| 38 | ## Flashing the Bootloader | ||
| 39 | |||
| 40 | To flash the bootloader onto your STM32H747XI device, use the following command: | ||
| 41 | |||
| 42 | ```bash | ||
| 43 | cargo flash --features embassy-stm32/stm32h747xi-cm7 --release --chip STM32H747XIHx | ||
| 44 | ``` | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/build.rs b/examples/boot/bootloader/stm32-dual-bank/build.rs new file mode 100644 index 000000000..fd605991f --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/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/stm32-dual-bank/memory.x b/examples/boot/bootloader/stm32-dual-bank/memory.x new file mode 100644 index 000000000..665da7139 --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/memory.x | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 128K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K | ||
| 6 | ACTIVE : ORIGIN = 0x08040000, LENGTH = 512K | ||
| 7 | DFU : ORIGIN = 0x08100000, LENGTH = 640K | ||
| 8 | RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 512K | ||
| 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(DFU); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(DFU); | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/src/main.rs b/examples/boot/bootloader/stm32-dual-bank/src/main.rs new file mode 100644 index 000000000..4d2e82d26 --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/src/main.rs | |||
| @@ -0,0 +1,53 @@ | |||
| 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::{Flash, BANK1_REGION}; | ||
| 11 | use embassy_sync::blocking_mutex::Mutex; | ||
| 12 | |||
| 13 | #[entry] | ||
| 14 | fn main() -> ! { | ||
| 15 | let p = embassy_stm32::init(Default::default()); | ||
| 16 | |||
| 17 | // Uncomment this if you are debugging the bootloader with debugger/RTT attached, | ||
| 18 | // as it prevents a hard fault when accessing flash 'too early' after boot. | ||
| 19 | /* | ||
| 20 | for i in 0..10000000 { | ||
| 21 | cortex_m::asm::nop(); | ||
| 22 | } | ||
| 23 | */ | ||
| 24 | |||
| 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | ||
| 26 | let flash_bank1 = Mutex::new(RefCell::new(layout.bank1_region)); | ||
| 27 | let flash_bank2 = Mutex::new(RefCell::new(layout.bank2_region)); | ||
| 28 | |||
| 29 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash_bank1, &flash_bank2, &flash_bank1); | ||
| 30 | let active_offset = config.active.offset(); | ||
| 31 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); | ||
| 32 | |||
| 33 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | ||
| 34 | } | ||
| 35 | |||
| 36 | #[no_mangle] | ||
| 37 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | ||
| 38 | unsafe extern "C" fn HardFault() { | ||
| 39 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 40 | } | ||
| 41 | |||
| 42 | #[exception] | ||
| 43 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 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; | ||
| 46 | |||
| 47 | panic!("DefaultHandler #{:?}", irqn); | ||
| 48 | } | ||
| 49 | |||
| 50 | #[panic_handler] | ||
| 51 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 52 | cortex_m::asm::udf(); | ||
| 53 | } | ||
diff --git a/examples/boot/bootloader/stm32/Cargo.toml b/examples/boot/bootloader/stm32/Cargo.toml index 2d88b0f78..74c01b0f4 100644 --- a/examples/boot/bootloader/stm32/Cargo.toml +++ b/examples/boot/bootloader/stm32/Cargo.toml | |||
| @@ -10,7 +10,7 @@ defmt = { version = "0.3", optional = true } | |||
| 10 | defmt-rtt = { version = "0.4", optional = true } | 10 | defmt-rtt = { version = "0.4", optional = true } |
| 11 | 11 | ||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } |
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" } | 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 15 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
| 16 | cortex-m-rt = { version = "0.7" } | 16 | cortex-m-rt = { version = "0.7" } |
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs index 5fd9ea588..99a7a6a6b 100644 --- a/examples/boot/bootloader/stm32/src/main.rs +++ b/examples/boot/bootloader/stm32/src/main.rs | |||
| @@ -25,7 +25,7 @@ fn main() -> ! { | |||
| 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); |
| 26 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); | 26 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); |
| 27 | 27 | ||
| 28 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | 28 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); |
| 29 | let active_offset = config.active.offset(); | 29 | let active_offset = config.active.offset(); |
| 30 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); | 30 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); |
| 31 | 31 | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml new file mode 100644 index 000000000..854f94d85 --- /dev/null +++ b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "stm32wb-dfu-bootloader-example" | ||
| 4 | version = "0.1.0" | ||
| 5 | description = "Example USB DFUbootloader for the STM32WB series of chips" | ||
| 6 | license = "MIT OR Apache-2.0" | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | defmt = { version = "0.3", optional = true } | ||
| 10 | defmt-rtt = { version = "0.4", optional = true } | ||
| 11 | |||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | ||
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | ||
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | ||
| 15 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | ||
| 16 | cortex-m-rt = { version = "0.7" } | ||
| 17 | embedded-storage = "0.3.1" | ||
| 18 | embedded-storage-async = "0.4.0" | ||
| 19 | cfg-if = "1.0.0" | ||
| 20 | embassy-usb-dfu = { version = "0.1.0", path = "../../../../embassy-usb-dfu", features = ["dfu", "cortex-m"] } | ||
| 21 | embassy-usb = { version = "0.1.0", path = "../../../../embassy-usb", default-features = false } | ||
| 22 | embassy-futures = { version = "0.1.1", path = "../../../../embassy-futures" } | ||
| 23 | |||
| 24 | [features] | ||
| 25 | defmt = [ | ||
| 26 | "dep:defmt", | ||
| 27 | "embassy-boot-stm32/defmt", | ||
| 28 | "embassy-stm32/defmt", | ||
| 29 | "embassy-usb/defmt", | ||
| 30 | "embassy-usb-dfu/defmt" | ||
| 31 | ] | ||
| 32 | debug = ["defmt-rtt", "defmt"] | ||
| 33 | |||
| 34 | [profile.dev] | ||
| 35 | debug = 2 | ||
| 36 | debug-assertions = true | ||
| 37 | incremental = false | ||
| 38 | opt-level = 'z' | ||
| 39 | overflow-checks = true | ||
| 40 | |||
| 41 | [profile.release] | ||
| 42 | codegen-units = 1 | ||
| 43 | debug = 2 | ||
| 44 | debug-assertions = false | ||
| 45 | incremental = false | ||
| 46 | lto = 'fat' | ||
| 47 | opt-level = 'z' | ||
| 48 | overflow-checks = false | ||
| 49 | |||
| 50 | # do not optimize proc-macro crates = faster builds from scratch | ||
| 51 | [profile.dev.build-override] | ||
| 52 | codegen-units = 8 | ||
| 53 | debug = false | ||
| 54 | debug-assertions = false | ||
| 55 | opt-level = 0 | ||
| 56 | overflow-checks = false | ||
| 57 | |||
| 58 | [profile.release.build-override] | ||
| 59 | codegen-units = 8 | ||
| 60 | debug = false | ||
| 61 | debug-assertions = false | ||
| 62 | opt-level = 0 | ||
| 63 | overflow-checks = false | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/README.md b/examples/boot/bootloader/stm32wb-dfu/README.md new file mode 100644 index 000000000..d5c6ea57c --- /dev/null +++ b/examples/boot/bootloader/stm32wb-dfu/README.md | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | # Bootloader for STM32 | ||
| 2 | |||
| 3 | The bootloader uses `embassy-boot` to interact with the flash. | ||
| 4 | |||
| 5 | # Usage | ||
| 6 | |||
| 7 | Flash the bootloader | ||
| 8 | |||
| 9 | ``` | ||
| 10 | cargo flash --features embassy-stm32/stm32wb55rg --release --chip STM32WB55RGVx | ||
| 11 | ``` | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/build.rs b/examples/boot/bootloader/stm32wb-dfu/build.rs new file mode 100644 index 000000000..fd605991f --- /dev/null +++ b/examples/boot/bootloader/stm32wb-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/stm32wb-dfu/memory.x b/examples/boot/bootloader/stm32wb-dfu/memory.x new file mode 100644 index 000000000..858062631 --- /dev/null +++ b/examples/boot/bootloader/stm32wb-dfu/memory.x | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 24K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | ||
| 6 | ACTIVE : ORIGIN = 0x08008000, LENGTH = 128K | ||
| 7 | DFU : ORIGIN = 0x08028000, LENGTH = 132K | ||
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 13 | |||
| 14 | __bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); | ||
| 15 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); | ||
| 16 | |||
| 17 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(FLASH); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(FLASH); | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs new file mode 100644 index 000000000..093b39f9d --- /dev/null +++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs | |||
| @@ -0,0 +1,91 @@ | |||
| 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::{Flash, BANK1_REGION, WRITE_SIZE}; | ||
| 11 | use embassy_stm32::rcc::WPAN_DEFAULT; | ||
| 12 | use embassy_stm32::usb::Driver; | ||
| 13 | use embassy_stm32::{bind_interrupts, peripherals, usb}; | ||
| 14 | use embassy_sync::blocking_mutex::Mutex; | ||
| 15 | use embassy_usb::Builder; | ||
| 16 | use embassy_usb_dfu::consts::DfuAttributes; | ||
| 17 | use embassy_usb_dfu::{usb_dfu, Control, ResetImmediate}; | ||
| 18 | |||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | USB_LP => usb::InterruptHandler<peripherals::USB>; | ||
| 21 | }); | ||
| 22 | |||
| 23 | #[entry] | ||
| 24 | fn main() -> ! { | ||
| 25 | let mut config = embassy_stm32::Config::default(); | ||
| 26 | config.rcc = WPAN_DEFAULT; | ||
| 27 | let p = embassy_stm32::init(config); | ||
| 28 | |||
| 29 | // Prevent a hard fault when accessing flash 'too early' after boot. | ||
| 30 | #[cfg(feature = "defmt")] | ||
| 31 | for _ in 0..10000000 { | ||
| 32 | cortex_m::asm::nop(); | ||
| 33 | } | ||
| 34 | |||
| 35 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | ||
| 36 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); | ||
| 37 | |||
| 38 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); | ||
| 39 | let active_offset = config.active.offset(); | ||
| 40 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); | ||
| 41 | if bl.state == State::DfuDetach { | ||
| 42 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); | ||
| 43 | let mut config = embassy_usb::Config::new(0xc0de, 0xcafe); | ||
| 44 | config.manufacturer = Some("Embassy"); | ||
| 45 | config.product = Some("USB-DFU Bootloader example"); | ||
| 46 | config.serial_number = Some("1235678"); | ||
| 47 | |||
| 48 | let fw_config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); | ||
| 49 | let mut buffer = AlignedBuffer([0; WRITE_SIZE]); | ||
| 50 | let updater = BlockingFirmwareUpdater::new(fw_config, &mut buffer.0[..]); | ||
| 51 | |||
| 52 | let mut config_descriptor = [0; 256]; | ||
| 53 | let mut bos_descriptor = [0; 256]; | ||
| 54 | let mut control_buf = [0; 4096]; | ||
| 55 | let mut state = Control::new(updater, DfuAttributes::CAN_DOWNLOAD); | ||
| 56 | let mut builder = Builder::new( | ||
| 57 | driver, | ||
| 58 | config, | ||
| 59 | &mut config_descriptor, | ||
| 60 | &mut bos_descriptor, | ||
| 61 | &mut [], | ||
| 62 | &mut control_buf, | ||
| 63 | ); | ||
| 64 | |||
| 65 | usb_dfu::<_, _, _, ResetImmediate, 4096>(&mut builder, &mut state); | ||
| 66 | |||
| 67 | let mut dev = builder.build(); | ||
| 68 | embassy_futures::block_on(dev.run()); | ||
| 69 | } | ||
| 70 | |||
| 71 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | ||
| 72 | } | ||
| 73 | |||
| 74 | #[no_mangle] | ||
| 75 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | ||
| 76 | unsafe extern "C" fn HardFault() { | ||
| 77 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 78 | } | ||
| 79 | |||
| 80 | #[exception] | ||
| 81 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 82 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | ||
| 83 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | ||
| 84 | |||
| 85 | panic!("DefaultHandler #{:?}", irqn); | ||
| 86 | } | ||
| 87 | |||
| 88 | #[panic_handler] | ||
| 89 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 90 | cortex_m::asm::udf(); | ||
| 91 | } | ||
