summaryrefslogtreecommitdiff
path: root/src/SystemTask
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-05-24 09:15:59 +0200
committerJF <jf@codingfield.com>2020-05-24 09:15:59 +0200
commit3cc76d7673f6a3b8b5253d04b358b440e550fdb4 (patch)
treed21c4e3b54e13bdc9fdeaa28a2a5b8c8081f9f18 /src/SystemTask
parentce328636935dbc580aad1245fdaff54d6ba947a3 (diff)
Working demo of OTA using MCUBoot https://github.com/lupyuen/pinetime-rust-mynewt/releases/tag/v4.1.4
Diffstat (limited to 'src/SystemTask')
-rw-r--r--src/SystemTask/SystemTask.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp
index 022cade4..021bac3d 100644
--- a/src/SystemTask/SystemTask.cpp
+++ b/src/SystemTask/SystemTask.cpp
@@ -38,6 +38,27 @@ void SystemTask::Process(void *instance) {
app->Work();
}
+static inline void nrf52_wait_for_flash_ready(void)
+{
+ while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {;}
+}
+
+void nrf52_nvmc_write_word(uint32_t address, uint32_t value) {
+ // Enable write.
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
+ __ISB();
+ __DSB();
+
+ // Write word
+ *(uint32_t*)address = value;
+ nrf52_wait_for_flash_ready();
+
+ // Disable write
+ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
+ __ISB();
+ __DSB();
+}
+
void SystemTask::Work() {
// watchdog.Setup(7);
// watchdog.Start();
@@ -46,6 +67,14 @@ void SystemTask::Work() {
spi.Init();
spiNorFlash.Init();
+
+ // TODO write magic only if it's not already 1
+ nrf52_nvmc_write_word(0x7BFE8, 1);
+
+ uint32_t* magicptr = reinterpret_cast<uint32_t *>(0x7BFE8);
+ uint32_t magic = *magicptr;
+ NRF_LOG_INFO("MAGIC : %d", magic);
+
nimbleController.Init();
nimbleController.StartAdvertising();
lcd.Init();