diff --git a/src/main.cpp b/src/main.cpp index d5da4283..5d304bc4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -160,9 +160,12 @@ Pinetime::System::SystemTask systemTask(spi, heartRateApp, fs); +/* Variable Declarations for variables in noinit SRAM + Increment NoInit_MagicValue upon adding variables to this area +*/ extern uint32_t __start_noinit_data; extern uint32_t __stop_noinit_data; -static constexpr uint32_t NoInit_MagicValue = 0xDEADBEEF; +static constexpr uint32_t NoInit_MagicValue = 0xDEAD0000; uint32_t NoInit_MagicWord __attribute__((section(".noinit"))); std::chrono::time_point NoInit_BackUpTime __attribute__((section(".noinit"))); @@ -327,10 +330,11 @@ int main(void) { // retrieve version stored by bootloader Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]); - // Check Magic Ram and reset lost variables + if (NoInit_MagicWord == NoInit_MagicValue) { dateTimeController.SetCurrentTime(NoInit_BackUpTime); } else { + //Clear Memory to known state memset(&__start_noinit_data,0,(uintptr_t)&__stop_noinit_data-(uintptr_t)&__start_noinit_data); NoInit_MagicWord = NoInit_MagicValue; }