From 1bb2eb9dcd59fbb198be157e34b7ff25367adea0 Mon Sep 17 00:00:00 2001 From: JF Date: Tue, 27 Oct 2020 19:38:45 +0100 Subject: [PATCH] Disable sleep mode on the SPI NOR Flash when the version is unknown. This is because the current bootloader (which does not exposes its version) cannot initialize the chip when it's in sleep mode. This feature will be re-enabled when the bootloader expses it's version. --- src/BootloaderVersion.cpp | 26 ++++++++++++++++++++++++++ src/BootloaderVersion.h | 12 ++++++++++++ src/CMakeLists.txt | 2 ++ src/drivers/SpiNorFlash.cpp | 6 +++--- src/systemtask/SystemTask.cpp | 7 ++++++- 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/BootloaderVersion.cpp create mode 100644 src/BootloaderVersion.h diff --git a/src/BootloaderVersion.cpp b/src/BootloaderVersion.cpp new file mode 100644 index 00000000..8555593f --- /dev/null +++ b/src/BootloaderVersion.cpp @@ -0,0 +1,26 @@ +#include +#include "BootloaderVersion.h" + +using namespace Pinetime; + +// NOTE : current bootloader does not export its version to the application firmware. + +uint32_t BootloaderVersion::Major() { + return 0; +} + +uint32_t BootloaderVersion::Minor() { + return 0; +} + +uint32_t BootloaderVersion::Patch() { + return 0; +} + +const char *BootloaderVersion::VersionString() { + return "0.0.0"; +} + +bool BootloaderVersion::IsValid() { + return false; +} diff --git a/src/BootloaderVersion.h b/src/BootloaderVersion.h new file mode 100644 index 00000000..c7fcbd98 --- /dev/null +++ b/src/BootloaderVersion.h @@ -0,0 +1,12 @@ +#pragma once + +namespace Pinetime { + class BootloaderVersion { + public: + static uint32_t Major(); + static uint32_t Minor(); + static uint32_t Patch(); + static const char* VersionString(); + static bool IsValid(); + }; +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd37810f..af0b110e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -322,6 +322,7 @@ list(APPEND IMAGE_FILES ) list(APPEND SOURCE_FILES + BootloaderVersion.cpp logging/NrfLogger.cpp displayapp/DisplayApp.cpp displayapp/screens/Screen.cpp @@ -397,6 +398,7 @@ list(APPEND GRAPHICS_SOURCE_FILES ) set(INCLUDE_FILES + BootloaderVersion.h logging/Logger.h logging/NrfLogger.h displayapp/DisplayApp.h diff --git a/src/drivers/SpiNorFlash.cpp b/src/drivers/SpiNorFlash.cpp index 351a9dfc..bd24834e 100644 --- a/src/drivers/SpiNorFlash.cpp +++ b/src/drivers/SpiNorFlash.cpp @@ -12,7 +12,7 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi{spi} { void SpiNorFlash::Init() { device_id = ReadIdentificaion(); - NRF_LOG_INFO("[SPI FLASH] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density); + NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density); } void SpiNorFlash::Uninit() { @@ -22,7 +22,7 @@ void SpiNorFlash::Uninit() { void SpiNorFlash::Sleep() { auto cmd = static_cast(Commands::DeepPowerDown); spi.Write(&cmd, sizeof(uint8_t)); - NRF_LOG_INFO("[FLASH] Sleep") + NRF_LOG_INFO("[SpiNorFlash] Sleep") } void SpiNorFlash::Wakeup() { @@ -38,7 +38,7 @@ void SpiNorFlash::Wakeup() { else { NRF_LOG_INFO("[SpiNorFlash] ID on Wakeup: %d", id); } - NRF_LOG_INFO("[FLASH] Wakeup") + NRF_LOG_INFO("[SpiNorFlash] Wakeup") } SpiNorFlash::Identification SpiNorFlash::ReadIdentificaion() { diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 3efe21b8..dac4ce29 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -13,6 +13,7 @@ #include #include "main.h" #include "components/ble/NimbleController.h" +#include "../BootloaderVersion.h" using namespace Pinetime::System; @@ -161,7 +162,11 @@ void SystemTask::Work() { ReloadIdleTimer(); break; case Messages::OnDisplayTaskSleeping: - spiNorFlash.Sleep(); + if(BootloaderVersion::IsValid()) { + // First versions of the bootloader do not expose their version and cannot initialize the SPI NOR FLASH + // if it's in sleep mode. Avoid bricked device by disabling sleep mode on these versions. + spiNorFlash.Sleep(); + } lcd.Sleep(); touchPanel.Sleep();