10.8.1.2.2 Workflow
- Set up a buffer, one NVM page in size, to hold data to read or write into NVM memory.
uint8_t page_buffer[NVMCTRL_PAGE_SIZE];
- Fill the buffer with a pattern of data.
for
(uint32_t i = 0; i < NVMCTRL_PAGE_SIZE; i++) {
page_buffer[i] = i;
}
- Create a variable to hold the error status from the called NVM functions.
enum
status_code error_code;
- Erase a page of NVM data. As the NVM could be busy initializing or completing a previous operation, a loop is used to retry the command while the NVM controller is busy.
do
{
error_code = nvm_erase_row(
100 * NVMCTRL_ROW_PAGES * NVMCTRL_PAGE_SIZE);
}
while
(error_code == STATUS_BUSY);
Note: This must be performed before writing new data into an NVM page. - Write the databuffer to the previously erased page of the NVM.
do
{
error_code = nvm_write_buffer(
100 * NVMCTRL_ROW_PAGES * NVMCTRL_PAGE_SIZE,
page_buffer, NVMCTRL_PAGE_SIZE);
}
while
(error_code == STATUS_BUSY);
Note: The new data will be written to NVM memory automatically, as the NVM controller is configured in automatic page write mode. - Read back the written page of page from the NVM into the buffer.
do
{
error_code = nvm_read_buffer(
100 * NVMCTRL_ROW_PAGES * NVMCTRL_PAGE_SIZE,
page_buffer, NVMCTRL_PAGE_SIZE);
}
while
(error_code == STATUS_BUSY);