Add driver for writing into the internal flash.
Write the OK flag for mcuboot using this driver.
This commit is contained in:
39
src/drivers/InternalFlash.cpp
Normal file
39
src/drivers/InternalFlash.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <sdk/modules/nrfx/mdk/nrf.h>
|
||||
#include "InternalFlash.h"
|
||||
using namespace Pinetime::Drivers;
|
||||
|
||||
void InternalFlash::ErasePage(uint32_t address) {
|
||||
// Enable erase.
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
|
||||
__ISB();
|
||||
__DSB();
|
||||
|
||||
// Erase the page
|
||||
NRF_NVMC->ERASEPAGE = address;
|
||||
Wait();
|
||||
|
||||
// Disable erase
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
|
||||
void InternalFlash::WriteWord(uint32_t address, uint32_t value) {
|
||||
// Enable write.
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
|
||||
__ISB();
|
||||
__DSB();
|
||||
|
||||
// Write word
|
||||
*(uint32_t*)address = value;
|
||||
Wait();
|
||||
|
||||
// Disable write
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
|
||||
void InternalFlash::Wait() {
|
||||
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {;}
|
||||
}
|
15
src/drivers/InternalFlash.h
Normal file
15
src/drivers/InternalFlash.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
class InternalFlash {
|
||||
public:
|
||||
static void ErasePage(uint32_t address);
|
||||
static void WriteWord(uint32_t address, uint32_t value);
|
||||
private:
|
||||
static inline void Wait();
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user