1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#![no_std]
#![no_main]
#![macro_use]
#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]
use embassy_boot_nrf::updater;
use embassy_nrf::{
gpio::{Input, Pull},
gpio::{Level, Output, OutputDrive},
nvmc::Nvmc,
Peripherals,
};
use embassy_traits::adapter::BlockingAsync;
use embedded_hal::digital::v2::InputPin;
use panic_reset as _;
static APP_B: &[u8] = include_bytes!("../../b.bin");
#[embassy::main]
async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
let mut button = Input::new(p.P0_11, Pull::Up);
let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
//let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
//let mut button = Input::new(p.P1_02, Pull::Up);
let nvmc = Nvmc::new(p.NVMC);
let mut nvmc = BlockingAsync::new(nvmc);
loop {
button.wait_for_any_edge().await;
if button.is_low().unwrap() {
let mut updater = updater::new();
let mut offset = 0;
for chunk in APP_B.chunks(4096) {
let mut buf: [u8; 4096] = [0; 4096];
buf[..chunk.len()].copy_from_slice(chunk);
updater
.write_firmware(offset, &buf, &mut nvmc)
.await
.unwrap();
offset += chunk.len();
}
updater.mark_update(&mut nvmc).await.unwrap();
led.set_high();
cortex_m::peripheral::SCB::sys_reset();
}
}
}
|