Atmel Software Framework

Quick Start quide for common NVM driver

This is the quick start quide for the Common NVM driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic use case

In this basic use case, NVM driver is configured for Internal Flash

Setup steps

Example code

Add to you application C-file:

do_something();

Workflow

  1. Ensure that board_init() has configured selected I/Os for TWI function when using external AT45DBX dataflash
  2. Ensure that conf_nvm.h is present for the driver.
    • Note
      This file is only for the driver and should not be included by the user.
  3. Call nvm_init and optionally check its return code

Usage steps

Example code: Writing to

non volatile memory Use in the application C-file:

uint8_t buffer[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE};
if(nvm_write(INT_FLASH, test_address, (void *)buffer, sizeof(buffer)) ==
do_something();

Workflow

  1. Prepare the data you want to send to the non volatile memory
    uint8_t buffer[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE};
  2. Call nvm_write
    nvm_write(INT_FLASH, test_address, (void *)buffer,
    sizeof(buffer))
    and optionally check its return value for STATUS_OK.

Example code: Reading from

non volatile memory Use in application C-file:

uint8_t data_read[8];
if(nvm_read(INT_FLASH, test_address, (void *)data_read, sizeof(data_read))
== STATUS_OK) {
//Check read content
if(data_read[0] == 0xAA)
do_something();
}

Workflow

  1. Prepare a data buffer that will read data from non volatile memory
    uint8_t data_read[8];
  2. Call nvm_read
    nvm_read(INT_FLASH, test_address, (void *)data_read,
    sizeof(data_read));
    and optionally check its return value for STATUS_OK. The data read from the non volatile memory are in data_read.

Example code: Erasing a

page of non volatile memory Use in the application C-file:

do_something();

Workflow

  1. Call nvm_page_erase and optionally check its return value for STATUS_OK.

Example code: Reading

configuration of non volatile memory Use in application C-file:

uint8_t mem_size, page_size, page_num;
nvm_get_size(INT_FLASH, &mem_size);
nvm_get_pagenumber(INT_FLASH, test_address, &page_num);

Workflow

  1. Prepare a buffer to store configuration of non volatile memory
    uint8_t mem_size, page_size, page_num;
  2. Call nvm_get_size
    nvm_get_size(INT_FLASH, &mem_size);
    and optionally check its return value for STATUS_OK. The memory size of the non volatile memory is in mem_size.
  3. Call nvm_get_page_size and optionally check its return value for STATUS_OK. The page size of the non volatile memory is in page_size.
  4. Call nvm_get_pagenumber
    nvm_get_page_number(INT_FLASH, test_address,
    &page_num);
    and optionally check its return value for STATUS_OK. The page number of given address in the non volatile memory is in page_num.

Example code: Enabling

security bit Use in the application C-file:

do_something();

Workflow

  1. Call nvm_set_security_bit and optionally check its return value for STATUS_OK.