10.8.1.2.2 Workflow

  1. 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];
    
  2. Fill the buffer with a pattern of data.
    for (uint32_t i = 0; i < NVMCTRL_PAGE_SIZE; i++) {
        page_buffer[i] = i;
    }
    
  3. Create a variable to hold the error status from the called NVM functions.
    enum status_code error_code;
    
  4. 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.
  5. 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.
  6. 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);