I'm developing for the NRF52 DK (nRF52832) using VisualGDB (which uses SDK v11.0.0).
When completed my program is supposed to read data from sensor (via I2C), store it in the internal flash and if enough data is accumulated send it to a phone via BLE.
I've searched through all the datasheets and documentation but could not find clear statements to my questions.
While developing 3 questions came up:
-
Is it possible to write less than 4 Bytes to the flash at one time?
I'd like to write only 1 Byte at a time (right now I'm writing 4 Bytes, see code below). -
If not, is it possible to add data to places where there is already data stored?
If there is a limit to how small a writing operation is wouldn't it be possible to write the same data to the flash storage with new data attached to it?
To my knowledge when erasing all bits are set to 1 and when writing the 0's are set. So writing the same data to the same address shouldn't change anything.
One thing that does worry me about this is wear. According to the Absolute Maximum Ratings 10000 write /erase cycles are possible; would writing the same data over and over again wear down the flash? -
What is to be considered when using BLE and Flash-operations?
While searching through forums and other questions I found out that using both apparently can cause problems. Again I could not find a official statement to that. Is it only while advertising, while sending data? Do I have to take into consideration that the SoftDevice has the highest priority?
Function used to write to flash:
bool flash_byte_write(uint32_t* pAddress, uint8_t uiValue) { // Turn on flash write enable and wait until the NVMC is ready: NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos); while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {//waiting } *pAddress = uiValue; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {//waiting } // Turn off flash write enable and wait until the NVMC is ready: NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos); while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {//waiting } }
Function used to read from flash:
uint8_t flash_byte_read(uint32_t* pAddress) { uint8_t data = (uint8_t)*(pAddress); return data; }