aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/bootloader/nrf/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/boot/bootloader/nrf/src/main.rs')
-rw-r--r--examples/boot/bootloader/nrf/src/main.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs
new file mode 100644
index 000000000..bc7e0755f
--- /dev/null
+++ b/examples/boot/bootloader/nrf/src/main.rs
@@ -0,0 +1,48 @@
1#![no_std]
2#![no_main]
3
4use cortex_m_rt::{entry, exception};
5#[cfg(feature = "defmt")]
6use defmt_rtt as _;
7use embassy_boot_nrf::*;
8use embassy_nrf::nvmc::Nvmc;
9
10#[entry]
11fn main() -> ! {
12 let p = embassy_nrf::init(Default::default());
13
14 // Uncomment this if you are debugging the bootloader with debugger/RTT attached,
15 // as it prevents a hard fault when accessing flash 'too early' after boot.
16 /*
17 for i in 0..10000000 {
18 cortex_m::asm::nop();
19 }
20 */
21
22 let mut bl = BootLoader::default();
23 let start = bl.prepare(&mut SingleFlashProvider::new(&mut WatchdogFlash::start(
24 Nvmc::new(p.NVMC),
25 p.WDT,
26 5,
27 )));
28 unsafe { bl.load(start) }
29}
30
31#[no_mangle]
32#[cfg_attr(target_os = "none", link_section = ".HardFault.user")]
33unsafe extern "C" fn HardFault() {
34 cortex_m::peripheral::SCB::sys_reset();
35}
36
37#[exception]
38unsafe fn DefaultHandler(_: i16) -> ! {
39 const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32;
40 let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16;
41
42 panic!("DefaultHandler #{:?}", irqn);
43}
44
45#[panic_handler]
46fn panic(_info: &core::panic::PanicInfo) -> ! {
47 cortex_m::asm::udf();
48}