2022-01-24 12:54:09 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
use cortex_m_rt::{entry, exception};
|
|
|
|
#[cfg(feature = "defmt")]
|
|
|
|
use defmt_rtt as _;
|
|
|
|
use embassy_boot_nrf::*;
|
|
|
|
use embassy_nrf::nvmc::Nvmc;
|
2023-01-04 00:19:39 +01:00
|
|
|
use embassy_nrf::wdt;
|
2022-01-24 12:54:09 +01:00
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
let p = embassy_nrf::init(Default::default());
|
2022-02-09 12:46:46 +01:00
|
|
|
|
|
|
|
// Uncomment this if you are debugging the bootloader with debugger/RTT attached,
|
|
|
|
// as it prevents a hard fault when accessing flash 'too early' after boot.
|
2022-01-24 12:54:09 +01:00
|
|
|
/*
|
|
|
|
for i in 0..10000000 {
|
|
|
|
cortex_m::asm::nop();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
let mut bl = BootLoader::default();
|
2023-01-04 00:19:39 +01:00
|
|
|
|
|
|
|
let mut wdt_config = wdt::Config::default();
|
|
|
|
wdt_config.timeout_ticks = 32768 * 5; // timeout seconds
|
|
|
|
wdt_config.run_during_sleep = true;
|
|
|
|
wdt_config.run_during_debug_halt = false;
|
|
|
|
|
2022-08-30 13:07:35 +02:00
|
|
|
let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::<_, 4096>::new(
|
2023-01-04 00:19:39 +01:00
|
|
|
WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config),
|
2022-04-19 14:42:38 +02:00
|
|
|
)));
|
2022-01-24 12:54:09 +01:00
|
|
|
unsafe { bl.load(start) }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
#[cfg_attr(target_os = "none", link_section = ".HardFault.user")]
|
|
|
|
unsafe extern "C" fn HardFault() {
|
|
|
|
cortex_m::peripheral::SCB::sys_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[exception]
|
|
|
|
unsafe fn DefaultHandler(_: i16) -> ! {
|
|
|
|
const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32;
|
|
|
|
let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16;
|
|
|
|
|
|
|
|
panic!("DefaultHandler #{:?}", irqn);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[panic_handler]
|
|
|
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
2022-04-26 18:33:09 +02:00
|
|
|
cortex_m::asm::udf();
|
2022-01-24 12:54:09 +01:00
|
|
|
}
|