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:
Workflow
- Ensure that board_init() has configured selected I/Os for TWI function when using external AT45DBX dataflash
- 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.
- 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};
*
*==
* do_something();
*
Workflow
- Prepare the data you want to send to the non volatile memory
uint8_t buffer[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE};
- Call nvm_write 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];
*
* sizeof(data_read))
*
* if(data_read[0] == 0xAA)
* do_something();
* }
*
Workflow
- Prepare a data buffer that will read data from non volatile memory
- Call nvm_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:
Workflow
- 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;
*
*
Workflow
- Prepare a buffer to store configuration of non volatile memory
uint8_t mem_size, page_size, page_num;
- Call nvm_get_size and optionally check its return value for STATUS_OK. The memory size of the non volatile memory is in mem_size.
- 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.
- Call nvm_get_pagenumber 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:
Workflow
- Call nvm_set_security_bit and optionally check its return value for STATUS_OK.