diff options
Diffstat (limited to 'examples/boot/bootloader/rp/src')
| -rw-r--r-- | examples/boot/bootloader/rp/src/main.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/examples/boot/bootloader/rp/src/main.rs b/examples/boot/bootloader/rp/src/main.rs new file mode 100644 index 000000000..6a81db804 --- /dev/null +++ b/examples/boot/bootloader/rp/src/main.rs | |||
| @@ -0,0 +1,56 @@ | |||
| 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_rp::*; | ||
| 10 | use embassy_sync::blocking_mutex::Mutex; | ||
| 11 | use embassy_time::Duration; | ||
| 12 | |||
| 13 | const FLASH_SIZE: usize = 2 * 1024 * 1024; | ||
| 14 | |||
| 15 | #[entry] | ||
| 16 | fn main() -> ! { | ||
| 17 | let p = embassy_rp::init(Default::default()); | ||
| 18 | |||
| 19 | // Uncomment this if you are debugging the bootloader with debugger/RTT attached, | ||
| 20 | // as it prevents a hard fault when accessing flash 'too early' after boot. | ||
| 21 | /* | ||
| 22 | for i in 0..10000000 { | ||
| 23 | cortex_m::asm::nop(); | ||
| 24 | } | ||
| 25 | */ | ||
| 26 | |||
| 27 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); | ||
| 28 | let flash = Mutex::new(RefCell::new(flash)); | ||
| 29 | |||
| 30 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | ||
| 31 | let active_offset = config.active.offset(); | ||
| 32 | let mut bl: BootLoader<_, _, _> = BootLoader::new(config); | ||
| 33 | |||
| 34 | bl.prepare(); | ||
| 35 | |||
| 36 | unsafe { bl.load(embassy_rp::flash::FLASH_BASE as u32 + active_offset) } | ||
| 37 | } | ||
| 38 | |||
| 39 | #[no_mangle] | ||
| 40 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | ||
| 41 | unsafe extern "C" fn HardFault() { | ||
| 42 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 43 | } | ||
| 44 | |||
| 45 | #[exception] | ||
| 46 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 47 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | ||
| 48 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | ||
| 49 | |||
| 50 | panic!("DefaultHandler #{:?}", irqn); | ||
| 51 | } | ||
| 52 | |||
| 53 | #[panic_handler] | ||
| 54 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 55 | cortex_m::asm::udf(); | ||
| 56 | } | ||
