SPI flash sleep if bootloader >= 1.0.0 (#322)

* Retrieve and display bootloader version
- Display bootloader version on System Info screen
- Enable SPI flash sleep mode if bootloader version >= 1.0.0
* Wait for SPI flash to wakeup before starting OTA DFU
This commit is contained in:
Neil O'Fix 2021-06-26 18:53:32 +00:00 committed by GitHub
parent 883700fca1
commit 0045fb16b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 19 deletions

View File

@ -1,26 +1,36 @@
#include <cstdint>
#include <cstdio>
#include "BootloaderVersion.h"
using namespace Pinetime;
// NOTE : current bootloader does not export its version to the application firmware.
// NOTE : version < 1.0.0 of bootloader does not export its version to the application firmware.
uint32_t BootloaderVersion::Major() {
return 0;
uint32_t BootloaderVersion::version = 0;
char BootloaderVersion::versionString[BootloaderVersion::VERSION_STR_LEN] = "0.0.0";
const uint32_t BootloaderVersion::Major() {
return (BootloaderVersion::version >> 16u) & 0xff;
}
uint32_t BootloaderVersion::Minor() {
return 0;
const uint32_t BootloaderVersion::Minor() {
return (BootloaderVersion::version >> 8u) & 0xff;
}
uint32_t BootloaderVersion::Patch() {
return 0;
const uint32_t BootloaderVersion::Patch() {
return BootloaderVersion::version & 0xff;
}
const char* BootloaderVersion::VersionString() {
return "0.0.0";
return BootloaderVersion::versionString;
}
bool BootloaderVersion::IsValid() {
return false;
const bool BootloaderVersion::IsValid() {
return BootloaderVersion::version >= 0x00010000;
}
void BootloaderVersion::SetVersion(uint32_t v) {
BootloaderVersion::version = v;
snprintf(BootloaderVersion::versionString, BootloaderVersion::VERSION_STR_LEN, "%ld.%ld.%ld",
BootloaderVersion::Major(), BootloaderVersion::Minor(), BootloaderVersion::Patch());
}

View File

@ -3,10 +3,15 @@
namespace Pinetime {
class BootloaderVersion {
public:
static uint32_t Major();
static uint32_t Minor();
static uint32_t Patch();
static const uint32_t Major();
static const uint32_t Minor();
static const uint32_t Patch();
static const char* VersionString();
static bool IsValid();
static const bool IsValid();
static void SetVersion(uint32_t v);
private:
static uint32_t version;
static constexpr size_t VERSION_STR_LEN = 12;
static char versionString[VERSION_STR_LEN];
};
}
}

View File

@ -121,6 +121,11 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) {
NRF_LOG_INFO(
"[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", softdeviceSize, bootloaderSize, applicationSize);
// wait until SystemTask has finished waking up all devices
while (systemTask.IsSleeping()) {
vTaskDelay(50); // 50ms
}
dfuImage.Erase();
uint8_t data[] {16, 1, 1};

View File

@ -3,6 +3,7 @@
#include "../DisplayApp.h"
#include "Label.h"
#include "Version.h"
#include "BootloaderVersion.h"
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/brightness/BrightnessController.h"
@ -83,17 +84,19 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen1() {
lv_label_set_recolor(label, true);
lv_label_set_text_fmt(label,
"#FFFF00 InfiniTime#\n\n"
"#444444 Version# %ld.%ld.%ld\n\n"
"#444444 Short Ref# %s\n\n"
"#444444 Version# %ld.%ld.%ld\n"
"#444444 Short Ref# %s\n"
"#444444 Build date#\n"
"%s\n"
"%s\n",
"%s\n\n"
"#444444 Bootloader# %s",
Version::Major(),
Version::Minor(),
Version::Patch(),
Version::GitCommitHash(),
__DATE__,
__TIME__);
__TIME__,
BootloaderVersion::VersionString());
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
return std::make_unique<Screens::Label>(0, 5, app, label);

View File

@ -28,6 +28,7 @@
#include <drivers/Hrs3300.h>
#include <drivers/Bma421.h>
#include "BootloaderVersion.h"
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
@ -306,6 +307,9 @@ int main(void) {
debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback);
debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback);
// retrieve version stored by bootloader
Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]);
lvgl.Init();
systemTask.Start();

View File

@ -73,6 +73,10 @@ namespace Pinetime {
return nimbleController;
};
bool IsSleeping() const {
return isSleeping;
}
private:
TaskHandle_t taskHandle;