diff options
| author | Ulf Lilleengen <[email protected]> | 2022-12-01 18:26:22 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-12-02 11:28:33 +0100 |
| commit | bb89a2341cca1aad79bc6d5f3532008541c9e428 (patch) | |
| tree | 63ff838ef0192f492ac2aae59b0b8a445b8200d6 /examples/boot/bootloader/rp/src/main.rs | |
| parent | eb010fbe33c2b99bdeaa68a2045b8a8e220cf0aa (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/bootloader/rp/src/main.rs')
| -rw-r--r-- | examples/boot/bootloader/rp/src/main.rs | 51 |
1 files changed, 51 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..5028ec688 --- /dev/null +++ b/examples/boot/bootloader/rp/src/main.rs | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use cortex_m_rt::{entry, exception}; | ||
| 5 | #[cfg(feature = "defmt")] | ||
| 6 | use defmt_rtt as _; | ||
| 7 | use embassy_boot_rp::*; | ||
| 8 | use embassy_rp::flash::{Flash, ERASE_SIZE}; | ||
| 9 | use embassy_rp::peripherals::FLASH; | ||
| 10 | |||
| 11 | const FLASH_SIZE: usize = 2 * 1024 * 1024; | ||
| 12 | |||
| 13 | #[entry] | ||
| 14 | fn main() -> ! { | ||
| 15 | let p = embassy_rp::init(Default::default()); | ||
| 16 | |||
| 17 | // Uncomment this if you are debugging the bootloader with debugger/RTT attached, | ||
| 18 | // as it prevents a hard fault when accessing flash 'too early' after boot. | ||
| 19 | /* | ||
| 20 | for i in 0..10000000 { | ||
| 21 | cortex_m::asm::nop(); | ||
| 22 | } | ||
| 23 | */ | ||
| 24 | |||
| 25 | let mut bl: BootLoader = BootLoader::default(); | ||
| 26 | let flash: Flash<'_, FLASH, FLASH_SIZE> = Flash::new(p.FLASH); | ||
| 27 | let mut flash = BootFlash::<_, ERASE_SIZE>::new(flash); | ||
| 28 | let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash)); | ||
| 29 | core::mem::drop(flash); | ||
| 30 | |||
| 31 | unsafe { bl.load(start) } | ||
| 32 | } | ||
| 33 | |||
| 34 | #[no_mangle] | ||
| 35 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | ||
| 36 | unsafe extern "C" fn HardFault() { | ||
| 37 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 38 | } | ||
| 39 | |||
| 40 | #[exception] | ||
| 41 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 42 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | ||
| 43 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | ||
| 44 | |||
| 45 | panic!("DefaultHandler #{:?}", irqn); | ||
| 46 | } | ||
| 47 | |||
| 48 | #[panic_handler] | ||
| 49 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 50 | cortex_m::asm::udf(); | ||
| 51 | } | ||
