Skip to content

Commit

Permalink
Using constant instead of magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-summers committed Dec 1, 2023
1 parent b975570 commit 4bf47de
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hardware/platform.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// Flag used to indicate that a reboot to DFU is requested.
const DFU_REBOOT_FLAG: u32 = 0xDEAD_BEEF;

/// Indicate a reboot to DFU is requested.
pub fn start_dfu_reboot() {
extern "C" {
Expand All @@ -6,7 +9,7 @@ pub fn start_dfu_reboot() {

unsafe {
let start_ptr = &mut _bootflag as *mut u8;
core::ptr::write_unaligned(start_ptr.cast::<u32>(), 0xDEAD_BEEF);
core::ptr::write_unaligned(start_ptr.cast::<u32>(), DFU_REBOOT_FLAG);
}

cortex_m::peripheral::SCB::sys_reset();
Expand All @@ -21,8 +24,8 @@ pub fn dfu_bootflag() -> bool {

unsafe {
let start_ptr = &mut _bootflag as *mut u8;
let set =
0xDEAD_BEEF == core::ptr::read_unaligned(start_ptr.cast::<u32>());
let set = DFU_REBOOT_FLAG
== core::ptr::read_unaligned(start_ptr.cast::<u32>());

// Clear the boot flag after checking it to ensure it doesn't stick between reboots.
core::ptr::write_unaligned(start_ptr.cast::<u32>(), 0);
Expand Down

0 comments on commit 4bf47de

Please sign in to comment.