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 mtb_hal_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 demonstrates non-blocking NVM write. It uses a constant array with a size equaling the size of one NVM row/block. It uses non-blocking NVM write operation which to not block the caller. It then verifies the NVM data by comparing the NVM data with the written data.

API Reference | |
| NVM HAL Results | |
| NVM specific return codes. | |
Macros | |
| #define | MTB_HAL_API_AVAILABLE_NVM_IS_SECTOR_CORRUPT |
| Indicates that mtb_hal_nvm_is_sector_corrupt is available in this version of HAL. | |
Enumerations | |
| enum | mtb_hal_nvm_type_t { MTB_HAL_NVM_TYPE_INVALID = 0U , MTB_HAL_NVM_TYPE_FLASH = 1U , MTB_HAL_NVM_TYPE_RRAM = 2U , MTB_HAL_NVM_TYPE_OTP = 3U } |
| Enum of Non-volatile memory (NVM) types. More... | |
Functions | |
| cy_rslt_t | mtb_hal_nvm_read (mtb_hal_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 | mtb_hal_nvm_erase (mtb_hal_nvm_t *obj, uint32_t address) |
| Erase one block of NVM starting at the given address. More... | |
| cy_rslt_t | mtb_hal_nvm_write (mtb_hal_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 | mtb_hal_nvm_program (mtb_hal_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 | mtb_hal_nvm_erase_nb (mtb_hal_nvm_t *obj, uint32_t address) |
| Erase one block of NVM starting at the given address (non-blocking). More... | |
| cy_rslt_t | mtb_hal_nvm_write_nb (mtb_hal_nvm_t *obj, uint32_t address, const uint32_t *data) |
| Write new data into the block starting at the given address (non-blocking). More... | |
| cy_rslt_t | mtb_hal_nvm_program_nb (mtb_hal_nvm_t *obj, uint32_t address, const uint32_t *data) |
| Program one block with the provided data starting at the given address (non-blocking). More... | |
| bool | mtb_hal_nvm_is_operation_complete (mtb_hal_nvm_t *obj) |
| Check if a non-blocking NVM operation is complete. More... | |
| const mtb_hal_nvm_region_info_t * | mtb_hal_nvm_get_region_for_address (mtb_hal_nvm_t *obj, uint32_t addr, uint32_t length) |
| Find the nvm region based on given address and length. More... | |
| bool | mtb_hal_nvm_is_blank (mtb_hal_nvm_t *obj, uint32_t addr, uint32_t size) |
| Checks whether the NVM region [addr, addr + size] is fully in the erased state. More... | |
| bool | mtb_hal_nvm_is_sector_corrupt (mtb_hal_nvm_t *obj, uint32_t addr, uint32_t size) |
| Checks whether the NVM region [addr, addr + size] contains detectable corruption. More... | |
| enum mtb_hal_nvm_type_t |
| cy_rslt_t mtb_hal_nvm_read | ( | mtb_hal_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 mtb_hal_nvm_erase | ( | mtb_hal_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 mtb_hal_nvm_write | ( | mtb_hal_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 mtb_hal_nvm_program | ( | mtb_hal_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 mtb_hal_nvm_erase_nb | ( | mtb_hal_nvm_t * | obj, |
| uint32_t | address | ||
| ) |
Erase one block of NVM starting at the given address (non-blocking).
The address must be at block boundary. This function starts the erase operation and returns immediately. Use mtb_hal_nvm_is_operation_complete() to check completion.
| [in] | obj | The NVM object |
| [in] | address | The block address to be erased |
| cy_rslt_t mtb_hal_nvm_write_nb | ( | mtb_hal_nvm_t * | obj, |
| uint32_t | address, | ||
| const uint32_t * | data | ||
| ) |
Write new data into the block starting at the given address (non-blocking).
The address must be at block boundary. This function starts the write operation and returns immediately. Use mtb_hal_nvm_is_operation_complete() to check completion.
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 |
| cy_rslt_t mtb_hal_nvm_program_nb | ( | mtb_hal_nvm_t * | obj, |
| uint32_t | address, | ||
| const uint32_t * | data | ||
| ) |
Program one block with the provided data starting at the given address (non-blocking).
The address must be at block boundary. This function starts the program operation and returns immediately. Use mtb_hal_nvm_is_operation_complete() to check completion.
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 mtb_hal_nvm_is_operation_complete | ( | mtb_hal_nvm_t * | obj | ) |
Check if a non-blocking NVM operation is complete.
| [in] | obj | The NVM object |
| const mtb_hal_nvm_region_info_t* mtb_hal_nvm_get_region_for_address | ( | mtb_hal_nvm_t * | obj, |
| uint32_t | addr, | ||
| uint32_t | length | ||
| ) |
Find the nvm region based on given address and length.
If "length is zero and address is not in any nvm region" or if "length is not zero and address is not in any nvm region" or if "length is not zero and address is one nvm region but address + length goes into another nvm region", the function will return Null.
| [in] | obj | The NVM object |
| [in] | addr | The start address of the block |
| [in] | length | The legnth to block |
| bool mtb_hal_nvm_is_blank | ( | mtb_hal_nvm_t * | obj, |
| uint32_t | addr, | ||
| uint32_t | size | ||
| ) |
Checks whether the NVM region [addr, addr + size] is fully in the erased state.
The erased state is only defined for regions that require an erase before programming. For a region whose mtb_hal_nvm_region_info_t::is_erase_required is false, this function always returns false. The value that represents "erased" for a region is reported by mtb_hal_nvm_region_info_t::erase_value. Query the region via mtb_hal_nvm_get_info() / mtb_hal_nvm_get_region_for_address() to distinguish "not erased" from "no erased state".
| [in] | obj | The NVM object. |
| [in] | addr | Start address of the region to check. Must be word aligned. |
| [in] | size | Size of the region to check, in bytes. Must be a multiple of the word size. |
| bool mtb_hal_nvm_is_sector_corrupt | ( | mtb_hal_nvm_t * | obj, |
| uint32_t | addr, | ||
| uint32_t | size | ||
| ) |
Checks whether the NVM region [addr, addr + size] contains detectable corruption.
All device-specific handling required to probe the region safely is performed internally; the function never accesses the memory in a way that would escalate a detected error into a fault.
Disabling interrupts around the call is the simplest way to satisfy both constraints and is the recommended approach. It is not strictly required: any other means of enforcing the two constraints above is equally valid. The function does not disable interrupts itself.
| [in] | obj | The NVM object. |
| [in] | addr | Start address of the region to check. Must be word aligned. |
| [in] | size | Size of the region to check, in bytes. Must be a multiple of the word size. |