dfu-flashing #2
2 changed files with 7 additions and 27 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
16
memory.x
16
memory.x
|
|
@ -1,23 +1,9 @@
|
|||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
|
||||
UNINIT : ORIGIN = 0x20000000, LENGTH = 0x10
|
||||
RAM : ORIGIN = 0x20000010, LENGTH = 64K - LENGTH(UNINIT)
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
.uninit_flags (NOLOAD) : ALIGN(4)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__suninit_flags = .;
|
||||
_dfu_magic = .; . += 4;
|
||||
*(.uninit_flags .uninit_flags.*)
|
||||
. = ALIGN(4);
|
||||
__euninit_flags = .;
|
||||
} > UNINIT
|
||||
}
|
||||
|
||||
|
||||
/* This is where the call stack will be allocated. */
|
||||
/* The stack is of the full descending type. */
|
||||
/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue