Skip to content

Commit 5480888

Browse files
committed
Add example for using the pre_init macro
Signed-off-by: Gabriel Smith <[email protected]>
1 parent f3fa545 commit 5480888

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

cortex-m-rt/examples/pre_init.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! `cortex-m-rt` based program with a function run before RAM is initialized.
2+
3+
#![deny(warnings)]
4+
#![no_main]
5+
#![no_std]
6+
7+
#[macro_use(entry, exception, pre_init)]
8+
extern crate cortex_m_rt as rt;
9+
extern crate panic_semihosting;
10+
11+
use rt::ExceptionFrame;
12+
13+
pre_init!(disable_watchdog);
14+
15+
unsafe fn disable_watchdog() {
16+
// Do what you need to disable the watchdog.
17+
}
18+
19+
// the program entry point
20+
entry!(main);
21+
22+
fn main() -> ! {
23+
loop {}
24+
}
25+
26+
// the hard fault handler
27+
exception!(HardFault, hard_fault);
28+
29+
fn hard_fault(_ef: &ExceptionFrame) -> ! {
30+
loop {}
31+
}
32+
33+
// the default exception handler
34+
exception!(*, default_handler);
35+
36+
fn default_handler(_irqn: i16) {}

0 commit comments

Comments
 (0)