I'm using HalFlashWrite to write data into a buffer. The timing is such that a couple of words are written every millisecond. The loop looks something like:
while(sensorDataAvailable >= 8) { // See if at least 8 bytes are available
getSensorData8(&dataBuffer); // Get 8 bytes of sensor data
HalFlashWrite(flashAddr, (uint8 *)&dataBuffer,(uint16)2); // Write two 32-bit words to flash
sensorDataAvailable = sensorDataAvailable - 8;
flashAddr = flashAddr + 2;
flashCnt = flashCnt + 8;
}
I have noticed that often the data I read back is 0xffffffff, indicating that the writes might not be happening...
I put the function calls "hal_LED_On()" before the HalFlashWrite and "hal_LED_Off()" after HalFlashWrite and the data being read back is what I expect!
These calls simply turn an LED on and off, but add some delay.
I find it hard to believe that this is making the writes work... But when I take them back out, the inconsistencies return.
Is there something else that I need to do to use HalFlashWrite successfully?
I looked at the HalFlashWrite code and see that it uses DMA channel 0. Does anything else (BLE, etc.) use this channel?
Should interrupts be disabled around flash writes?
Thanks!