2020-05-24 20:30:06 +02:00
|
|
|
#include "InternalFlash.h"
|
2020-11-15 05:04:22 +01:00
|
|
|
#include <mdk/nrf.h>
|
2020-05-24 20:30:06 +02:00
|
|
|
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
|
2021-04-18 19:28:14 +02:00
|
|
|
*(uint32_t*) address = value;
|
2020-05-24 20:30:06 +02:00
|
|
|
Wait();
|
|
|
|
|
|
|
|
// Disable write
|
|
|
|
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
|
|
|
__ISB();
|
|
|
|
__DSB();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InternalFlash::Wait() {
|
2021-04-18 19:28:14 +02:00
|
|
|
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {
|
|
|
|
;
|
|
|
|
}
|
2020-05-24 20:30:06 +02:00
|
|
|
}
|