This section describes the programming interfaces of the FLASH driver.
More...
This section describes the programming interfaces of the FLASH driver.
Terms and acronyms
The following provides descriptions to the terms commonly used in the FLASH driver and how to use its various functions.
Terms | Details |
XIP | eXecute In Place: A method of executing programs directly from long term storage rather than copying it into the RAM |
Supported features
The general purpose of FLASH is to save data into the embedded FLASH storage and read them back. The features supported by this module are listed below:
- FLASH erase
It has to be erased before data can be saved into the FLASH storage, function hal_flash_erase() implements that operation.
- FLASH write
Function hal_flash_write() is called to save data into the FLASH storage after it's erased.
- FLASH read
Function hal_flash_read() is called to read data from the FLASH storage.
How to use this driver
- FLASH read and Write
- step1: call hal_flash_init() to initialize the FLASH module.
- step2: call hal_flash_erase() to erase the target block of the FLASH storage
- step3: call hal_flash_write() to write data to the FLASH storage
- step4: call hal_flash_read() to read data from the FLASH storage
- Sample code:
}
start_address = 0xAC000;
}
#define MAX_DATA (16)
uint8_t data_to_write[MAX_DATA] = {0};
}
uint8_t data_read[MAX_DATA] = {0};
}
flash erase
- Parameters
-
[in] | start_address | is starting address to erase from |
[in] | block_type | is the size of block to be erased |
- Returns
- HAL_FLASH_STATUS_OK on success
- Note
- The start_address should be align with the block_type
hal_flash_status_t hal_flash_read |
( |
uint32_t |
start_address, |
|
|
uint8_t * |
buffer, |
|
|
uint32_t |
length |
|
) |
| |
flash read
- Parameters
-
[in] | start_address | is starting address to read the data from |
[out] | buffer | is place to hold the incoming data |
[in] | length | is the length of the data content |
- Returns
- HAL_FLASH_STATUS_OK on success
hal_flash_status_t hal_flash_write |
( |
uint32_t |
address, |
|
|
const uint8_t * |
data, |
|
|
uint32_t |
length |
|
) |
| |
flash write
- Parameters
-
[in] | address | is starting address to write from.Before the address can be written to for the first time, the address located sector or block must first be erased. |
[in] | length | is data length |
[in] | data | is source data to be written |
- Returns
- HAL_FLASH_STATUS_OK on success