High level interface to the onboard Non-Volatile memory (Internal Flash, RRAM, OTP region).
Onboard NVM provides non-volatile storage for factory settings, secure data, user firmware, configuration, and bulk data.
This driver allows data to be read from and written to NVM. It also provides the ability to obtain information about the address and characteristics of the NVM block(s) contained on the device. During NVM write time, the device should not be reset (including XRES pin, software reset, and watchdog) or unexpected changes may be made to portions of the NVM. Also, the low-voltage detect circuits should be configured to generate an interrupt instead of a reset.
Following code snippet demonstrates how to fetch NVM characteristics. Refer cyhal_nvm_info_t for more information.
Following code snippet demonstrates blocking NVM write. It uses a constant array with a size equaling the size of one NVM row/block. It uses blocking NVM write operation which blocks the caller until the write is completed. It then verifies the NVM data by comparing the NVM data with the written data.
Following code snippet implements the non-blocking NVM write using polling to complete the NVM write operation. It uses a constant array with a size equaling the size of one NVM row/block. It uses a polling method to complete the NVM write operation. It then verifies the NVM data by comparing the NVM data with the written data.
API Reference | |
NVM HAL Results | |
NVM specific return codes. | |
Data Structures | |
struct | cyhal_nvm_region_info_t |
Information about a single region of NVM memory. More... | |
struct | cyhal_nvm_info_t |
Information about all of the regions of NVM memory. More... | |
Enumerations | |
enum | cyhal_nvm_type_t { CYHAL_NVM_TYPE_INVALID = 0U , CYHAL_NVM_TYPE_FLASH = 1U , CYHAL_NVM_TYPE_RRAM = 2U , CYHAL_NVM_TYPE_OTP = 3U } |
Enum of Non-volatile memory (NVM) types. More... | |
Functions | |
cy_rslt_t | cyhal_nvm_init (cyhal_nvm_t *obj) |
Initialize the cyhal_nvm_t object for accessing NVM through the HAL. More... | |
void | cyhal_nvm_free (cyhal_nvm_t *obj) |
Free resources associated with the NVM HAL driver. More... | |
void | cyhal_nvm_get_info (cyhal_nvm_t *obj, cyhal_nvm_info_t *info) |
Get details about the NVM memory regions such as NVM type, start address, size, is_erase_required, and erase values etc. More... | |
cy_rslt_t | cyhal_nvm_read (cyhal_nvm_t *obj, uint32_t address, uint8_t *data, size_t size) |
Read size amount of data starting from the given address of NVM. More... | |
cy_rslt_t | cyhal_nvm_erase (cyhal_nvm_t *obj, uint32_t address) |
Erase one block of NVM starting at the given address. More... | |
cy_rslt_t | cyhal_nvm_write (cyhal_nvm_t *obj, uint32_t address, const uint32_t *data) |
This function erases the block, if required, and writes the new data into the block starting at the given address. More... | |
cy_rslt_t | cyhal_nvm_otp_write (cyhal_nvm_t *obj, uint32_t address, uint8_t data) |
Write one-time data to the given byte location in the provided block of NVM OTP region. More... | |
cy_rslt_t | cyhal_nvm_program (cyhal_nvm_t *obj, uint32_t address, const uint32_t *data) |
Program one block with the provided data starting at the given address. More... | |
cy_rslt_t | cyhal_nvm_start_erase (cyhal_nvm_t *obj, uint32_t address) |
Start an asynchronous erase of a single block of NVM starting at the given address. More... | |
cy_rslt_t | cyhal_nvm_start_write (cyhal_nvm_t *obj, uint32_t address, const uint32_t *data) |
Start an asynchronous write (Erase if required + Program) on single block of NVM starting at the given address. More... | |
cy_rslt_t | cyhal_nvm_start_program (cyhal_nvm_t *obj, uint32_t address, const uint32_t *data) |
Start asynchronous programming of a single block of NVM starting at the given address. More... | |
bool | cyhal_nvm_is_operation_complete (cyhal_nvm_t *obj) |
Reports status of the last NVM operation. More... | |
struct cyhal_nvm_region_info_t |
Data Fields | ||
---|---|---|
cyhal_nvm_type_t | nvm_type | NVM type. |
uint32_t | start_address | Base address of the distinct NVM region. |
uint32_t | offset | Offset to the address in the distinct NVM region. |
uint32_t | size | Size of the distinct NVM region. |
uint32_t | sector_size | Sector size of the distinct NVM region. |
uint32_t | block_size | Block size (programming granularity) of the distinct NVM region. |
bool | is_erase_required | true = erase required before program, false = erase not required before program. |
uint8_t | erase_value | NVM erase value (if applicable). |
struct cyhal_nvm_info_t |
Data Fields | ||
---|---|---|
uint8_t | region_count | The number of distinct NVM regions. |
const cyhal_nvm_region_info_t * | regions | Array of the distinct NVM regions. |
enum cyhal_nvm_type_t |
cy_rslt_t cyhal_nvm_init | ( | cyhal_nvm_t * | obj | ) |
Initialize the cyhal_nvm_t object for accessing NVM through the HAL.
[in] | obj | Pointer to a NVM object. The caller must allocate the memory for this object but the init function will initialize its contents. |
void cyhal_nvm_free | ( | cyhal_nvm_t * | obj | ) |
Free resources associated with the NVM HAL driver.
[out] | obj | The NVM object. |
void cyhal_nvm_get_info | ( | cyhal_nvm_t * | obj, |
cyhal_nvm_info_t * | info | ||
) |
Get details about the NVM memory regions such as NVM type, start address, size, is_erase_required, and erase values etc.
Refer cyhal_nvm_info_t, cyhal_nvm_region_info_t for more information.
[in] | obj | The NVM object. |
[out] | info | The NVM characteristic info. |
Refer Snippet 1: Get NVM Characteristics for more information.
cy_rslt_t cyhal_nvm_read | ( | cyhal_nvm_t * | obj, |
uint32_t | address, | ||
uint8_t * | data, | ||
size_t | size | ||
) |
Read size amount of data starting from the given address of NVM.
[in] | obj | The NVM object. |
[in] | address | Address to begin reading from. |
[out] | data | The buffer to read data into. |
[in] | size | The number of bytes to read. |
Refer Snippet 2: Blocking NVM Erase-Write and Read for more information.
cy_rslt_t cyhal_nvm_erase | ( | cyhal_nvm_t * | obj, |
uint32_t | address | ||
) |
Erase one block of NVM starting at the given address.
The address must be at block boundary. This will block until the erase operation is complete.
[in] | obj | The NVM object |
[in] | address | The block address to be erased |
Refer Snippet 2: Blocking NVM Erase-Write and Read for more information.
cy_rslt_t cyhal_nvm_write | ( | cyhal_nvm_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
This function erases the block, if required, and writes the new data into the block starting at the given address.
The address must be at block boundary. This will block until the write operation is complete.
data
to be written must be located in the SRAM memory region.[in] | obj | The NVM object |
[in] | address | The address of the block to be written |
[in] | data | The data buffer to be written to the NVM block |
Refer Snippet 2: Blocking NVM Erase-Write and Read for more information.
cy_rslt_t cyhal_nvm_otp_write | ( | cyhal_nvm_t * | obj, |
uint32_t | address, | ||
uint8_t | data | ||
) |
Write one-time data to the given byte location in the provided block of NVM OTP region.
The block must be within the defined block range of the OTP (refer the device datasheet for more information).
[in] | obj | The NVM object |
[in] | address | The address of the block to be written |
[in] | data | The data to be written to the OTP memory |
cy_rslt_t cyhal_nvm_program | ( | cyhal_nvm_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
Program one block with the provided data starting at the given address.
The address must be at block boundary. This will block until the write operation is complete.
data
to be programmed must be located in the SRAM memory region.[in] | obj | The NVM object |
[in] | address | The address of the block to be programmed |
[in] | data | The data buffer to be programmed to the NVM block |
cy_rslt_t cyhal_nvm_start_erase | ( | cyhal_nvm_t * | obj, |
uint32_t | address | ||
) |
Start an asynchronous erase of a single block of NVM starting at the given address.
Returns immediately and reports a successful start or reason for failure. The address must be aligned on a block boundary.
[in] | obj | The NVM object |
[in] | address | The block address to be erased |
Refer Snippet 3: Non-blocking NVM Erase-Write and Read for more information.
cy_rslt_t cyhal_nvm_start_write | ( | cyhal_nvm_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
Start an asynchronous write (Erase if required + Program) on single block of NVM starting at the given address.
Returns immediately and reports a successful start or reason for failure. The address must be aligned on a block boundary.
data
to be written must be located in the SRAM memory region.[in] | obj | The NVM object |
[in] | address | The address of the block to be written |
[in] | data | The data buffer to be written to the NVM block |
Refer Snippet 3: Non-blocking NVM Erase-Write and Read for more information.
cy_rslt_t cyhal_nvm_start_program | ( | cyhal_nvm_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
Start asynchronous programming of a single block of NVM starting at the given address.
Returns immediately and reports a successful start or reason for failure.
data
to be programmed must be located in the SRAM memory region.[in] | obj | The NVM object |
[in] | address | The address of the block to be programmed |
[in] | data | The data buffer to be programmed to the NVM block |
bool cyhal_nvm_is_operation_complete | ( | cyhal_nvm_t * | obj | ) |
Reports status of the last NVM operation.
[in] | obj | The NVM object |