3.10.3 NVMCTRL with True Read-While-Write Support
Nonvolatile Memory Controller with True Read-While-Write Support
3.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.
3.10.3.2 Supported Device Families
ATmega32xx | AVR® EA |
3.10.3.3 Required header files:
#include "mcc_generated_files/nvm/nvm.h"
3.10.3.4 Module Documentation
3.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 sigrow_data_t
Data type for the Signature Row data.
typedef uint16_t sigrow_address_t
Datatype for Signature Row address.
typedef uint32_t device_id_data_t
Data type for the Device ID data.
typedef uint8_t fuse_data_t
Data type for the Fuse data.
typedef uint16_t fuse_address_t
Data type for the Fuse address.
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.
Definitions
#define SERIAL_NUMBER_SIZE (16U)
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).
void Flash_ReadyInterruptEnable (void)
Enables the FLREADY interrupt.
void Flash_ReadyInterruptDisable (void)
Disables the FLREADY interrupt.
void Flash_CallbackRegister (void(*CallbackHandler)(void))
Setter function for the Flash Ready interrupt callback.
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.
void EEPROM_ReadyInterruptEnable (void)
Enables the EEREADY interrupt.
void EEPROM_ReadyInterruptDisable (void)
Disables the EEREADY interrupt.
void EEPROM_CallbackRegister (void(*CallbackHandler)(void))
Setter function for the EEPROM Ready interrupt callback.
sigrow_data_t SIGROW_Read (sigrow_address_t address)
Reads one Signature Row byte.
device_id_data_t SIGROW_DeviceIDRead (sigrow_address_t address)
Reads the Device ID.
void SIGROW_SerialNumberRead (sigrow_address_t address, sigrow_data_t *serialNumber)
Reads the serial number. The size of the buffer must be equal to the size of the serial number.
fuse_data_t FUSE_Read (fuse_address_t address)
Reads a fuse.
Definition Documentation
SERIAL_NUMBER_SIZE
#define SERIAL_NUMBER_SIZE (16U)
Contains the serial number length in bytes.
Typedef Documentation
device_id_data_t
typedef uint32_t device_id_data_t
Data type for the Device ID data.
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.
fuse_address_t
typedef uint16_t fuse_address_t
Data type for the Fuse address.
fuse_data_t
typedef uint8_t fuse_data_t
Data type for the Fuse data.
sigrow_address_t
typedef uint16_t sigrow_address_t
Datatype for Signature Row address.
sigrow_data_t
typedef uint8_t sigrow_data_t
Data type for the Signature Row data.
Function Documentation
EEPROM_CallbackRegister()
void EEPROM_CallbackRegister (void(*)(void) CallbackHandler)
Setter function for the EEPROM Ready interrupt callback.
in | CallbackHandler |
- Pointer to a custom callback. |
None. |
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_ReadyInterruptDisable()
void EEPROM_ReadyInterruptDisable (void )
Disables the EEREADY interrupt.
The interrupt can be disabled in the interrupt handler. |
None. |
None. |
EEPROM_ReadyInterruptEnable()
void EEPROM_ReadyInterruptEnable (void )
Enables the EEREADY interrupt.
The interrupt must be enabled only after triggering a NVM command. Global interrupt must be enabled for the EERADY interrupt to work. |
None. |
None. |
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_CallbackRegister()
void Flash_CallbackRegister (void(*)(void) CallbackHandler)
Setter function for the Flash Ready interrupt callback.
in | CallbackHandler |
- Pointer to a custom callback. |
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_ReadyInterruptDisable()
void Flash_ReadyInterruptDisable (void )
Disables the FLREADY interrupt.
The interrupt can be disabled in the interrupt handler. |
None. |
None. |
Flash_ReadyInterruptEnable()
void Flash_ReadyInterruptEnable (void )
Enables the FLREADY interrupt.
The interrupt must be enabled only after triggering a NVM command. Global interrupt must be enabled for the FLREADY interrupt to work. |
None. |
None. |
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. |
FUSE_Read()
fuse_data_t FUSE_Read (fuse_address_t address)
Reads a fuse.
in | address |
- Fuse address to be read. |
Fuse data. |
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 |
SIGROW_DeviceIDRead()
device_id_data_t SIGROW_DeviceIDRead (sigrow_address_t address)
Reads the Device ID.
in | address |
- Starting address of the Device ID. |
Device ID. |
SIGROW_Read()
sigrow_data_t SIGROW_Read (sigrow_address_t address)
Reads one Signature Row byte.
in | address |
- Address of the Signature Row byte to be read. |
Signature Row data. |
SIGROW_SerialNumberRead()
void SIGROW_SerialNumberRead (sigrow_address_t address, sigrow_data_t * serialNumber)
Reads the serial number. The size of the buffer must be equal to the size of the serial number.
in | address |
- Starting address of the serial number. |
out | *serialNumber |
- Buffer to hold the serial number. |
None. |
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 |
3.10.3.5 File Documentation
3.10.3.5.1 source/source-files/nvm.c File Reference
This file contains the implementation for the NVM driver.
#include <avr/pgmspace.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.
ISR (NVMCTRL_NVMREADY_vect)
void Flash_CallbackRegister (void(*CallbackHandler)(void))
Setter function for the Flash Ready interrupt callback.
void Flash_ReadyInterruptEnable (void)
Enables the FLREADY interrupt.
void Flash_ReadyInterruptDisable (void)
Disables the FLREADY interrupt.
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.
void EEPROM_CallbackRegister (void(*CallbackHandler)(void))
Setter function for the EEPROM Ready interrupt callback.
void EEPROM_ReadyInterruptEnable (void)
Enables the EEREADY interrupt.
void EEPROM_ReadyInterruptDisable (void)
Disables the EEREADY interrupt.
sigrow_data_t SIGROW_Read (sigrow_address_t address)
Reads one Signature Row byte.
device_id_data_t SIGROW_DeviceIDRead (sigrow_address_t address)
Reads the Device ID.
void SIGROW_SerialNumberRead (sigrow_address_t address, sigrow_data_t *serialNumber)
Reads the serial number. The size of the buffer must be equal to the size of the serial number.
fuse_data_t FUSE_Read (fuse_address_t address)
Reads a fuse.
Variables
static void(* EEPROM_Callback )(void) = NULL
static void(* Flash_Callback )(void) = NULL
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)
ISR()
ISR (NVMCTRL_NVMREADY_vect )
NVM_NoOperation_Command()
inline static void NVM_NoOperation_Command (void )
Variable Documentation
EEPROM_Callback
void(* EEPROM_Callback) (void) = NULL[static]
Flash_Callback
void(* Flash_Callback) (void) = NULL[static]
3.10.3.5.2 source/source-files/nvm.h File Reference
#include <string.h> #include "../system/utils/compiler.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).
void Flash_ReadyInterruptEnable (void)
Enables the FLREADY interrupt.
void Flash_ReadyInterruptDisable (void)
Disables the FLREADY interrupt.
void Flash_CallbackRegister (void(*CallbackHandler)(void))
Setter function for the Flash Ready interrupt callback.
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.
void EEPROM_ReadyInterruptEnable (void)
Enables the EEREADY interrupt.
void EEPROM_ReadyInterruptDisable (void)
Disables the EEREADY interrupt.
void EEPROM_CallbackRegister (void(*CallbackHandler)(void))
Setter function for the EEPROM Ready interrupt callback.
sigrow_data_t SIGROW_Read (sigrow_address_t address)
Reads one Signature Row byte.
device_id_data_t SIGROW_DeviceIDRead (sigrow_address_t address)
Reads the Device ID.
void SIGROW_SerialNumberRead (sigrow_address_t address, sigrow_data_t *serialNumber)
Reads the serial number. The size of the buffer must be equal to the size of the serial number.
fuse_data_t FUSE_Read (fuse_address_t address)
Reads a fuse.
Macros
#define SERIAL_NUMBER_SIZE (16U)
Typedefs
typedef uint8_t sigrow_data_t
Data type for the Signature Row data.
typedef uint16_t sigrow_address_t
Datatype for Signature Row address.
typedef uint32_t device_id_data_t
Data type for the Device ID data.
typedef uint8_t fuse_data_t
Data type for the Fuse data.
typedef uint16_t fuse_address_t
Data type for the Fuse address.
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.
Macro Definition Documentation
FLASH_ErasePageAddressGet
#define FLASH_ErasePageAddressGet FLASH_PageAddressGet
FLASH_ErasePageOffsetGet
#define FLASH_ErasePageOffsetGet FLASH_PageOffsetGet