4.10.3 NVMCTRL with True Read-While-Write Support
Nonvolatile Memory Controller with True Read-While-Write Support
4.10.3.1 Introduction
This NVM Controller (NVMCTRL)Module is the interface between the CPU and Nonvolatile Memories (Flash, EEPROM, Signature Row, User Row, and fuses). These are reprogrammable memory blocks that retain their values when they are not powered. The Flash is mainly used for program storage and can also be used for data storage, while the EEPROM, Signature Row, User Row, and fuses are used for data storage. The “Read-While-Write section” refers to which section is being programmed (erased or written) and not the one read. Only the code located inside the NRWW Flash can be accessed by either executing a CPU instruction or reading data while the RWW Flash is being written or erased.
4.10.3.2 Supported Device Families
ATmega32xx | AVR® EA |
4.10.3.3 Required header files:
#include "mcc_generated_files/nvm/nvm.h"
4.10.3.4 Module Documentation
4.10.3.4.1 Non-Volatile Memory
This file contains API prototypes and other data types for the Non-Volatile Memory (NVM) driver.
Module description
This file contains API prototypes and other data types for the Non-Volatile Memory (NVM) driver.
Typedefs
typedef uint8_t flash_data_t
Data types for the NVM address and data.
typedef uint16_t flash_address_t
Data type for the Flash address.
typedef uint8_t eeprom_data_t
Data type for the EEPROM data.
typedef uint16_t eeprom_address_t
Data type for the EEPROM address.
Enumerations
enum nvm_status_t { NVM_OK, NVM_ERROR, NVM_BUSY }
Contains the return codes for the NVM driver APIs.
Functions
void NVM_Initialize (void)
Initializes the NVM driver.
nvm_status_t NVM_StatusGet (void)
Returns the status of the last NVM operation.
void NVM_StatusClear (void)
Clears the status of the last NVM operation.
flash_data_t FLASH_Read (flash_address_t address)
Reads a byte from the given Flash address.
nvm_status_t FLASH_RowWrite (flash_address_t address, flash_data_t *dataBuffer)
Writes one entire Flash row/page from the given starting address of the row (the first byte location). The size of the input buffer must be one Flash row and the address must be aligned with the row boundary. Use FLASH_PageAddressGet() to obtain the starting address of the row.
nvm_status_t FLASH_PageErase (flash_address_t address)
Erases one Flash page containing the given address.
bool FLASH_IsBusy (void)
Checks if the Flash is busy.
flash_address_t FLASH_PageAddressGet (flash_address_t address)
Returns the starting address of the page (the first byte location) containing the given Flash address.
flash_address_t FLASH_PageOffsetGet (flash_address_t address)
Returns the offset from the starting address of the page (the first byte location).
eeprom_data_t EEPROM_Read (eeprom_address_t address)
Reads one byte from the given EEPROM address.
nvm_status_t EEPROM_Write (eeprom_address_t address, eeprom_data_t data)
Writes one byte to the given EEPROM address. The EEPROM busy status must be checked using the EEPROM_IsBusy() API to know if the Write operation is completed. Use the NVM_StatusGet() API to see the result of the Write operation.
bool EEPROM_IsBusy (void)
Checks if the EEPROM is busy.
Typedef Documentation
eeprom_address_t
typedef uint16_t eeprom_address_t
Data type for the EEPROM address.
eeprom_data_t
typedef uint8_t eeprom_data_t
Data type for the EEPROM data.
flash_address_t
typedef uint16_t flash_address_t
Data type for the Flash address.
flash_data_t
typedef uint8_t flash_data_t
Data types for the NVM address and data.
Data type for the Flash data.
Function Documentation
EEPROM_IsBusy()
bool EEPROM_IsBusy (void )
Checks if the EEPROM is busy.
NVM must be initialized with NVM_Initialize() before calling this API. |
None. |
True |
- The EEPROM operation is being performed. |
False |
- The EEPROM operation is not being performed. |
EEPROM_Read()
eeprom_data_t EEPROM_Read (eeprom_address_t address)
Reads one byte from the given EEPROM address.
NVM must be initialized with NVM_Initialize() before calling this API. |
in | address |
- Address of the EEPROM location to be read. |
Byte read from the given EEPROM address. |
EEPROM_Write()
nvm_status_t EEPROM_Write (eeprom_address_t address, eeprom_data_t data)
Writes one byte to the given EEPROM address. The EEPROM busy status must be checked using the EEPROM_IsBusy() API to know if the Write operation is completed. Use the NVM_StatusGet() API to see the result of the Write operation.
in | address |
- Address of the EEPROM location to be written. |
in | data |
- Byte to be written to the given EEPROM location. |
None. |
FLASH_IsBusy()
bool FLASH_IsBusy (void )
Checks if the Flash is busy.
NVM must be initialized with NVM_Initialize() before calling this API. |
None. |
True |
- The Flash operation is being performed. |
False |
- The Flash operation is not being performed. |
FLASH_PageAddressGet()
flash_address_t FLASH_PageAddressGet (flash_address_t address)
Returns the starting address of the page (the first byte location) containing the given Flash address.
in | address |
- Flash address for which the page starting address will be obtained. |
Starting address of the page containing the given Flash address. |
FLASH_PageErase()
nvm_status_t FLASH_PageErase (flash_address_t address)
Erases one Flash page containing the given address.
NVM must be initialized with NVM_Initialize() before calling this API. |
in | address |
- Starting address of the Flash page to be erased. |
Status of the Flash Page Erase operation as described in the nvm_status_t. |
FLASH_PageOffsetGet()
flash_address_t FLASH_PageOffsetGet (flash_address_t address)
Returns the offset from the starting address of the page (the first byte location).
in | address |
- Flash address for which the offset from the starting address of the page will be obtained. |
Offset of the given address from the starting address of the page. |
FLASH_Read()
flash_data_t FLASH_Read (flash_address_t address)
Reads a byte from the given Flash address.
NVM must be initialized with NVM_Initialize() before calling this API. |
in | address |
- Address of the Flash location where data read from. |
Byte read from the given Flash address. |
FLASH_RowWrite()
nvm_status_t FLASH_RowWrite (flash_address_t address, flash_data_t * dataBuffer)
Writes one entire Flash row/page from the given starting address of the row (the first byte location). The size of the input buffer must be one Flash row and the address must be aligned with the row boundary. Use FLASH_PageAddressGet() to obtain the starting address of the row.
Erase Flash row before calling this function. |
in | address |
- Starting address of the Flash row to be written. |
in | *dataBuffer |
- Pointer to a buffer which holds the data to be written. |
Status of the Flash row Write operation as described in nvm_status_t. |
NVM_Initialize()
void NVM_Initialize (void )
Initializes the NVM driver.
None. |
None. |
NVM_StatusClear()
void NVM_StatusClear (void )
Clears the status of the last NVM operation.
None. |
None. |
NVM_StatusGet()
nvm_status_t NVM_StatusGet (void )
Returns the status of the last NVM operation.
None. |
NVM_OK |
- The NVM operation succeeded |
NVM_ERROR |
- The NVM operation failed |
Enumeration Type Documentation
nvm_status_t
enum nvm_status_t
Contains the return codes for the NVM driver APIs.
NVM_OK |
0 - The NVM operation succeeded |
NVM_ERROR |
1 - The NVM operation failed |
NVM_BUSY |
2 - The NVM Write operation is ongoing |
4.10.3.5 File Documentation
4.10.3.5.1 source/nvm.c File Reference
This file contains the implementation for the NVM driver.
#include <avr/pgmspace.h> #include "../../system/utils/compiler.h" #include "../../system/ccp.h" #include "../nvm.h"
Functions
static void NVM_NoOperation_Command (void)
static void FLASH_SpmWriteWord (flash_address_t address, uint16_t data)
void NVM_Initialize (void)
Initializes the NVM driver.
nvm_status_t NVM_StatusGet (void)
Returns the status of the last NVM operation.
void NVM_StatusClear (void)
Clears the status of the last NVM operation.
flash_data_t FLASH_Read (flash_address_t address)
Reads a byte from the given Flash address.
nvm_status_t FLASH_RowWrite (flash_address_t address, flash_data_t *dataBuffer)
Writes one entire Flash row/page from the given starting address of the row (the first byte location). The size of the input buffer must be one Flash row and the address must be aligned with the row boundary. Use FLASH_PageAddressGet() to obtain the starting address of the row.
nvm_status_t FLASH_PageErase (flash_address_t address)
Erases one Flash page containing the given address.
bool FLASH_IsBusy (void)
Checks if the Flash is busy.
flash_address_t FLASH_PageAddressGet (flash_address_t address)
Returns the starting address of the page (the first byte location) containing the given Flash address.
flash_address_t FLASH_PageOffsetGet (flash_address_t address)
Returns the offset from the starting address of the page (the first byte location).
eeprom_data_t EEPROM_Read (eeprom_address_t address)
Reads one byte from the given EEPROM address.
nvm_status_t EEPROM_Write (eeprom_address_t address, eeprom_data_t data)
Writes one byte to the given EEPROM address. The EEPROM busy status must be checked using the EEPROM_IsBusy() API to know if the Write operation is completed. Use the NVM_StatusGet() API to see the result of the Write operation.
bool EEPROM_IsBusy (void)
Checks if the EEPROM is busy.
Detailed Description
This file contains the implementation for the NVM driver.
Function Documentation
FLASH_SpmWriteWord()
inline static void FLASH_SpmWriteWord (flash_address_t address, uint16_t data)
NVM_NoOperation_Command()
inline static void NVM_NoOperation_Command (void )
4.10.3.5.2 source/nvm.h File Reference
#include <string.h>
Functions
void NVM_Initialize (void)
Initializes the NVM driver.
nvm_status_t NVM_StatusGet (void)
Returns the status of the last NVM operation.
void NVM_StatusClear (void)
Clears the status of the last NVM operation.
flash_data_t FLASH_Read (flash_address_t address)
Reads a byte from the given Flash address.
nvm_status_t FLASH_RowWrite (flash_address_t address, flash_data_t *dataBuffer)
Writes one entire Flash row/page from the given starting address of the row (the first byte location). The size of the input buffer must be one Flash row and the address must be aligned with the row boundary. Use FLASH_PageAddressGet() to obtain the starting address of the row.
nvm_status_t FLASH_PageErase (flash_address_t address)
Erases one Flash page containing the given address.
bool FLASH_IsBusy (void)
Checks if the Flash is busy.
flash_address_t FLASH_PageAddressGet (flash_address_t address)
Returns the starting address of the page (the first byte location) containing the given Flash address.
flash_address_t FLASH_PageOffsetGet (flash_address_t address)
Returns the offset from the starting address of the page (the first byte location).
eeprom_data_t EEPROM_Read (eeprom_address_t address)
Reads one byte from the given EEPROM address.
nvm_status_t EEPROM_Write (eeprom_address_t address, eeprom_data_t data)
Writes one byte to the given EEPROM address. The EEPROM busy status must be checked using the EEPROM_IsBusy() API to know if the Write operation is completed. Use the NVM_StatusGet() API to see the result of the Write operation.
bool EEPROM_IsBusy (void)
Checks if the EEPROM is busy.
Typedefs
typedef uint8_t flash_data_t
Data types for the NVM address and data.
typedef uint16_t flash_address_t
Data type for the Flash address.
typedef uint8_t eeprom_data_t
Data type for the EEPROM data.
typedef uint16_t eeprom_address_t
Data type for the EEPROM address.
Enumerations
enum nvm_status_t { NVM_OK, NVM_ERROR, NVM_BUSY }
Contains the return codes for the NVM driver APIs.