aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/bootloader/stm32/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/boot/bootloader/stm32/src/main.rs')
-rw-r--r--examples/boot/bootloader/stm32/src/main.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs
new file mode 100644
index 000000000..45c511ced
--- /dev/null
+++ b/examples/boot/bootloader/stm32/src/main.rs
@@ -0,0 +1,46 @@
1#![no_std]
2#![no_main]
3
4use cortex_m_rt::{entry, exception};
5#[cfg(feature = "defmt")]
6use defmt_rtt as _;
7use embassy_boot_stm32::*;
8use embassy_stm32::flash::{Flash, ERASE_SIZE};
9
10#[entry]
11fn main() -> ! {
12 let p = embassy_stm32::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<ERASE_SIZE> = BootLoader::default();
23 let mut flash = Flash::unlock(p.FLASH);
24 let start = bl.prepare(&mut SingleFlashProvider::new(&mut flash));
25 core::mem::drop(flash);
26 unsafe { bl.load(start) }
27}
28
29#[no_mangle]
30#[cfg_attr(target_os = "none", link_section = ".HardFault.user")]
31unsafe extern "C" fn HardFault() {
32 cortex_m::peripheral::SCB::sys_reset();
33}
34
35#[exception]
36unsafe fn DefaultHandler(_: i16) -> ! {
37 const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32;
38 let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16;
39
40 panic!("DefaultHandler #{:?}", irqn);
41}
42
43#[panic_handler]
44fn panic(_info: &core::panic::PanicInfo) -> ! {
45 cortex_m::asm::udf();
46}