aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/application/rp/src
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-12-01 18:26:22 +0100
committerUlf Lilleengen <[email protected]>2022-12-02 11:28:33 +0100
commitbb89a2341cca1aad79bc6d5f3532008541c9e428 (patch)
tree63ff838ef0192f492ac2aae59b0b8a445b8200d6 /examples/boot/application/rp/src
parenteb010fbe33c2b99bdeaa68a2045b8a8e220cf0aa (diff)
feat: embassy-boot for rp2040
Add embassy-boot support for RP2040, with examples for the Raspberry Pi Pico. Co-authored-by: Mathias Koch <[email protected]>
Diffstat (limited to 'examples/boot/application/rp/src')
-rw-r--r--examples/boot/application/rp/src/bin/a.rs52
-rw-r--r--examples/boot/application/rp/src/bin/b.rs23
2 files changed, 75 insertions, 0 deletions
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs
new file mode 100644
index 000000000..3736c9141
--- /dev/null
+++ b/examples/boot/application/rp/src/bin/a.rs
@@ -0,0 +1,52 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt_rtt as _;
6use embassy_boot_rp::*;
7use embassy_executor::Spawner;
8use embassy_rp::flash::Flash;
9use embassy_rp::gpio::{Level, Output};
10use embassy_time::{Duration, Timer};
11#[cfg(feature = "panic-probe")]
12use panic_probe as _;
13#[cfg(feature = "panic-reset")]
14use panic_reset as _;
15
16static APP_B: &[u8] = include_bytes!("../../b.bin");
17const FLASH_SIZE: usize = 2 * 1024 * 1024;
18
19#[embassy_executor::main]
20async fn main(_s: Spawner) {
21 let p = embassy_rp::init(Default::default());
22 let mut led = Output::new(p.PIN_25, Level::Low);
23
24 let mut flash: Flash<_, FLASH_SIZE> = Flash::new(p.FLASH);
25
26 let mut updater = FirmwareUpdater::default();
27
28 Timer::after(Duration::from_secs(5)).await;
29 led.set_high();
30 let mut offset = 0;
31 let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]);
32 defmt::info!("preparing update");
33 let mut writer = updater
34 .prepare_update_blocking(&mut flash)
35 .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e)))
36 .unwrap();
37 defmt::info!("writer created, starting write");
38 for chunk in APP_B.chunks(4096) {
39 buf.0[..chunk.len()].copy_from_slice(chunk);
40 defmt::info!("writing block at offset {}", offset);
41 writer
42 .write_block_blocking(offset, &buf.0[..], &mut flash, 256)
43 .unwrap();
44 offset += chunk.len();
45 }
46 defmt::info!("firmware written, marking update");
47 updater.mark_updated_blocking(&mut flash, &mut buf.0[..1]).unwrap();
48 Timer::after(Duration::from_secs(2)).await;
49 led.set_low();
50 defmt::info!("update marked, resetting");
51 cortex_m::peripheral::SCB::sys_reset();
52}
diff --git a/examples/boot/application/rp/src/bin/b.rs b/examples/boot/application/rp/src/bin/b.rs
new file mode 100644
index 000000000..47dec329c
--- /dev/null
+++ b/examples/boot/application/rp/src/bin/b.rs
@@ -0,0 +1,23 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use embassy_executor::Spawner;
6use embassy_rp::gpio;
7use embassy_time::{Duration, Timer};
8use gpio::{Level, Output};
9use {defmt_rtt as _, panic_reset as _};
10
11#[embassy_executor::main]
12async fn main(_s: Spawner) {
13 let p = embassy_rp::init(Default::default());
14 let mut led = Output::new(p.PIN_25, Level::Low);
15
16 loop {
17 led.set_high();
18 Timer::after(Duration::from_millis(100)).await;
19
20 led.set_low();
21 Timer::after(Duration::from_millis(100)).await;
22 }
23}