Fixed memory layout to avoid running into segfaults

This commit is contained in:
Sebastian 2025-12-28 13:07:42 +01:00
parent 524ed8f2c6
commit 24b46a5fff
2 changed files with 7 additions and 27 deletions

View file

@ -1,5 +1,5 @@
use core::mem::MaybeUninit;
use core::ptr::addr_of_mut;
use stm32f4xx_hal::pac;
fn jump_to_bootloader() {
@ -23,25 +23,19 @@ fn jump_to_bootloader() {
const BOOTLOADER_REQUESTED: u32 = 0xdecafbad;
fn magic_mut_ptr() -> *mut u32 {
extern "C" {
#[link_name = "_dfu_magic"]
static mut magic: u32;
}
unsafe { addr_of_mut!(magic) }
}
#[link_section = ".uninit.DFU_FLAG"]
static mut DFU_FLAG: MaybeUninit<u32> = MaybeUninit::uninit();
fn get_bootloader_flag() -> u32 {
unsafe { magic_mut_ptr().read_volatile() }
unsafe { DFU_FLAG.assume_init() }
}
fn set_bootloader_flag() {
unsafe { magic_mut_ptr().write_volatile(BOOTLOADER_REQUESTED) };
unsafe { DFU_FLAG.write(BOOTLOADER_REQUESTED) };
}
fn clear_bootloader_flag() {
unsafe { magic_mut_ptr().write_volatile(BOOTLOADER_REQUESTED) };
unsafe { DFU_FLAG.write(0) };
}
pub fn init() {