software_dfu #46
5
memory.x
5
memory.x
|
@ -3,12 +3,13 @@ MEMORY
|
|||
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
|
||||
/* reserved for config data */
|
||||
CONFIG (rx) : ORIGIN = 0x8100000, LENGTH = 16K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 111K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112K - 4
|
||||
/* reserved for DFU trigger message */
|
||||
DFU_MSG (wrx) : ORIGIN = 0x2001BC00, LENGTH = 1K
|
||||
DFU_MSG (wrx) : ORIGIN = 0x2001BFFC, LENGTH = 4
|
||||
RAM2 (xrw) : ORIGIN = 0x2001C000, LENGTH = 16K
|
||||
RAM3 (xrw) : ORIGIN = 0x20020000, LENGTH = 64K
|
||||
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
_stack_start = ORIGIN(CCMRAM) + LENGTH(CCMRAM);
|
||||
_dfu_msg = ORIGIN(DFU_MSG);
|
||||
|
|
43
src/dfu.rs
43
src/dfu.rs
|
@ -1,28 +1,25 @@
|
|||
use cortex_m_rt::{pre_init};
|
||||
|
||||
/// RAM location used to store DFU trigger message
|
||||
const DFU_MSG_ADDR: usize = 0x2001BC00;
|
||||
const DFU_TRIG_MSG: u32 = 0xDECAFBAD;
|
||||
|
||||
/// DFU trigger message
|
||||
const DFU_TRIG_MSG: usize = 0xDECAFBAD;
|
||||
|
||||
/// Set DFU trigger
|
||||
pub unsafe fn trig_dfu() {
|
||||
let dfu_msg_addr = DFU_MSG_ADDR as *mut usize;
|
||||
*dfu_msg_addr = DFU_TRIG_MSG;
|
||||
pub unsafe fn set_dfu_trigger() {
|
||||
extern "C" {
|
||||
static mut _dfu_msg: u32;
|
||||
}
|
||||
_dfu_msg = DFU_TRIG_MSG;
|
||||
}
|
||||
|
||||
/// Called by reset handler in lib.rs immediately after reset, checks if booting into dfu is needed
|
||||
/// Called by reset handler in lib.rs immediately after reset.
|
||||
/// This function should not be called outside of reset handler as
|
||||
/// bootloader expects MCU to be in reset state when called.
|
||||
#[pre_init]
|
||||
unsafe fn __pre_init() {
|
||||
extern "C" {
|
||||
static mut _dfu_msg: u32;
|
||||
}
|
||||
|
||||
let dfu_msg_addr = DFU_MSG_ADDR as *mut usize;
|
||||
|
||||
// Check DFU trigger message
|
||||
if *dfu_msg_addr == DFU_TRIG_MSG{
|
||||
|
||||
// Reset message
|
||||
*dfu_msg_addr = 0x00000000;
|
||||
if _dfu_msg == DFU_TRIG_MSG {
|
||||
_dfu_msg = 0x00000000;
|
||||
|
||||
|
||||
// Enable system config controller clock
|
||||
const RCC_APB2ENR: *mut u32 = 0xE000_ED88 as *mut u32;
|
||||
|
@ -42,13 +39,13 @@ unsafe fn __pre_init() {
|
|||
*SYSCFG_MEMRMP | SYSCFG_MEMRMP_MAP_ROM,
|
||||
);
|
||||
|
||||
asm!(
|
||||
// Set stack pointer to bootloader location
|
||||
asm!("LDR R0, =0x1FFF0000");
|
||||
asm!("LDR SP,[R0, #0]");
|
||||
|
||||
"LDR R0, =0x1FFF0000",
|
||||
"LDR SP,[R0, #0]",
|
||||
// Jump to bootloader
|
||||
asm!("LDR R0,[R0, #4]");
|
||||
asm!("BX R0");
|
||||
"LDR R0,[R0, #4]",
|
||||
"BX R0",
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -429,8 +429,9 @@ fn main() -> ! {
|
|||
channels.power_down(i);
|
||||
}
|
||||
unsafe {
|
||||
dfu::trig_dfu();
|
||||
dfu::set_dfu_trigger();
|
||||
}
|
||||
socket.close();
|
||||
SCB::sys_reset();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
remove blank line