High level interface to the internal flash memory.
Flash memory provides non-volatile storage for user firmware, user configuration data, and bulk data storage.
This driver allows data to be read from and written to flash. It also provides the ability to obtain information about the address and characteristics of the flash block(s) contained on the device. During flash 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 flash. Also, the low-voltage detect circuits should be configured to generate an interrupt instead of a reset.
Following code snippet demonstrates how to discover flash characteristics. Refer cyhal_flash_info_t for more information.
Following code snippet demonstrates blocking flash write. It uses a constant array with a size equaling the size of one flash row. This array is placed at an address in flash such that it occupies one complete flash row. It uses blocking flash write operation which blocks the caller until the write is completed. It then verifies the flash data by comparing the flash data with the written data.
Following code snippet implements the non-blocking flash write using polling to complete the flash write operation. It uses a constant array with a size equaling the size of one flash row. This array is placed at an address in flash such that it occupies one complete flash row. It uses a polling method to complete the flash write operation. It then verifies the flash data by comparing the flash data with the written data.
API Reference | |
Flash HAL Results | |
Flash specific return codes. | |
Data Structures | |
struct | cyhal_flash_block_info_t |
Information about a single block of flash memory. More... | |
struct | cyhal_flash_info_t |
Information about all of the blocks of flash memory. More... | |
Functions | |
cy_rslt_t | cyhal_flash_init (cyhal_flash_t *obj) |
Initialize the cyhal_flash_t object for accessing flash through the HAL. More... | |
void | cyhal_flash_free (cyhal_flash_t *obj) |
Free resources associated with flash object through the HAL. More... | |
void | cyhal_flash_get_info (const cyhal_flash_t *obj, cyhal_flash_info_t *info) |
Gets flash characteristics like the start address, size, erase values etc. More... | |
cy_rslt_t | cyhal_flash_read (cyhal_flash_t *obj, uint32_t address, uint8_t *data, size_t size) |
Read data starting at a defined address. More... | |
cy_rslt_t | cyhal_flash_erase (cyhal_flash_t *obj, uint32_t address) |
Erase one page starting at a defined address. More... | |
cy_rslt_t | cyhal_flash_write (cyhal_flash_t *obj, uint32_t address, const uint32_t *data) |
This function erases the page and writes the new data into the page starting at a defined address. More... | |
cy_rslt_t | cyhal_flash_program (cyhal_flash_t *obj, uint32_t address, const uint32_t *data) |
Program one page with given data starting at defined address. More... | |
cy_rslt_t | cyhal_flash_start_erase (cyhal_flash_t *obj, uint32_t address) |
Starts an asynchronous erase of a single page of flash. More... | |
cy_rslt_t | cyhal_flash_start_write (cyhal_flash_t *obj, uint32_t address, const uint32_t *data) |
Starts an asynchronous write to a single page of flash. More... | |
cy_rslt_t | cyhal_flash_start_program (cyhal_flash_t *obj, uint32_t address, const uint32_t *data) |
Starts asynchronous programming of a single page of flash. More... | |
bool | cyhal_flash_is_operation_complete (cyhal_flash_t *obj) |
Reports status of the flash operation. More... | |
struct cyhal_flash_block_info_t |
struct cyhal_flash_info_t |
Data Fields | ||
---|---|---|
uint8_t | block_count | The number of distinct flash blocks. |
const cyhal_flash_block_info_t * | blocks | Array of the distinct flash blocks. |
cy_rslt_t cyhal_flash_init | ( | cyhal_flash_t * | obj | ) |
Initialize the cyhal_flash_t object for accessing flash through the HAL.
[out] | obj | Pointer to a flash object. The caller must allocate the memory for this object but the init function will initialize its contents. |
void cyhal_flash_free | ( | cyhal_flash_t * | obj | ) |
Free resources associated with flash object through the HAL.
[out] | obj | The flash object. |
void cyhal_flash_get_info | ( | const cyhal_flash_t * | obj, |
cyhal_flash_info_t * | info | ||
) |
Gets flash characteristics like the start address, size, erase values etc.
Refer cyhal_flash_info_t for more information.
[in] | obj | The flash object. |
[out] | info | The flash characteristic info. |
Refer Snippet 1: Discovering flash characteristics for more information.
cy_rslt_t cyhal_flash_read | ( | cyhal_flash_t * | obj, |
uint32_t | address, | ||
uint8_t * | data, | ||
size_t | size | ||
) |
Read data starting at a defined address.
[in] | obj | The flash 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 Flash Write Operation for more information.
cy_rslt_t cyhal_flash_erase | ( | cyhal_flash_t * | obj, |
uint32_t | address | ||
) |
Erase one page starting at a defined address.
The address must be at page boundary. This will block until the erase operation is complete.
[in] | obj | The flash object |
[in] | address | The page starting address |
Refer Snippet 2: Blocking Flash Write Operation for more information.
cy_rslt_t cyhal_flash_write | ( | cyhal_flash_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
This function erases the page and writes the new data into the page starting at a defined address.
The address must be at page boundary. This will block until the write operation is complete.
[in] | obj | The flash object |
[in] | address | The page starting address |
[in] | data | The data to write to the flash |
Refer Snippet 2: Blocking Flash Write Operation for more information.
cy_rslt_t cyhal_flash_program | ( | cyhal_flash_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
Program one page with given data starting at defined address.
The address must be at page boundary. This will block until the write operation is complete.
[in] | obj | The flash object |
[in] | address | The sector starting address |
[in] | data | The data buffer to be programmed |
cy_rslt_t cyhal_flash_start_erase | ( | cyhal_flash_t * | obj, |
uint32_t | address | ||
) |
Starts an asynchronous erase of a single page of flash.
Returns immediately and reports a successful start or reason for failure. The address must be aligned on a page boundary.
[in] | obj | The Flash object being operated on |
[in] | address | The address to start erasing from |
Refer Snippet 3: Non-blocking Flash Write Operation using polling for more information.
cy_rslt_t cyhal_flash_start_write | ( | cyhal_flash_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
Starts an asynchronous write to a single page of flash.
Returns immediately and reports a successful start or reason for failure. The address must be aligned on a page boundary.
[in] | obj | The Flash object being operated on |
[in] | address | The address to start writing to |
[in] | data | The data to write to flash |
Refer Snippet 3: Non-blocking Flash Write Operation using polling for more information.
cy_rslt_t cyhal_flash_start_program | ( | cyhal_flash_t * | obj, |
uint32_t | address, | ||
const uint32_t * | data | ||
) |
Starts asynchronous programming of a single page of flash.
Returns immediately and reports a successful start or reason for failure.
[in] | obj | The Flash object being operated on |
[in] | address | The address to start programming |
[in] | data | The data to write to flash |
bool cyhal_flash_is_operation_complete | ( | cyhal_flash_t * | obj | ) |
Reports status of the flash operation.
[in] | obj | The Flash object being operated on |