From 4bf47de457fb65e08106aa681581387083af9df8 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Fri, 1 Dec 2023 12:32:33 +0100 Subject: [PATCH] Using constant instead of magic number --- src/hardware/platform.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hardware/platform.rs b/src/hardware/platform.rs index 8a6580b61..2fee79df5 100644 --- a/src/hardware/platform.rs +++ b/src/hardware/platform.rs @@ -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" { @@ -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::(), 0xDEAD_BEEF); + core::ptr::write_unaligned(start_ptr.cast::(), DFU_REBOOT_FLAG); } cortex_m::peripheral::SCB::sys_reset(); @@ -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::()); + let set = DFU_REBOOT_FLAG + == core::ptr::read_unaligned(start_ptr.cast::()); // Clear the boot flag after checking it to ensure it doesn't stick between reboots. core::ptr::write_unaligned(start_ptr.cast::(), 0);