I am trying to bring up a bare metal STM32 from scratch.
My code is super simple
#![no_main]
#![no_std]
use core::{
panic::PanicInfo,
};
#[link_section = ".vector_table.reset_vector"]
#[no_mangle]
pub static __RESET_VECTOR: fn() -> ! = reset_handler;
#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
pub fn reset_handler() -> ! {
loop {}
}
This works fine. And if I disassemble it, I see:
08000008 <_ZN3app13reset_handler17hd5651b8c92fda766E>:
8000008: e7fe b.n 8000008 <_ZN3app13reset_handler17hd5651b8c92fda766E>
800000a: d4d4 bmi.n 7ffffb6 <__RESET_VECTOR-0x4e>
All nice. Now if I modify it just a bit and add a "main" function. I.e.
pub fn reset_handler() -> ! {
main()
}
pub fn main() -> ! {
loop {
}
}
The MCU crashes. If I disassemble the code I see:
08000008 <_ZN3app13reset_handler17hd5651b8c92fda766E>:
8000008: defe udf #254 ; 0xfe
800000a: d4d4 bmi.n 7ffffb6 <__RESET_VECTOR-0x4e>
Notice the udf
.
Any idea what am I doing wrong?