RA Flexible Software Package Documentation
Release v5.6.0
|
|
Functions | |
fsp_err_t | R_FLASH_LP_Open (flash_ctrl_t *const p_api_ctrl, flash_cfg_t const *const p_cfg) |
fsp_err_t | R_FLASH_LP_Write (flash_ctrl_t *const p_api_ctrl, uint32_t const src_address, uint32_t flash_address, uint32_t const num_bytes) |
fsp_err_t | R_FLASH_LP_Erase (flash_ctrl_t *const p_api_ctrl, uint32_t const address, uint32_t const num_blocks) |
fsp_err_t | R_FLASH_LP_BlankCheck (flash_ctrl_t *const p_api_ctrl, uint32_t const address, uint32_t num_bytes, flash_result_t *p_blank_check_result) |
fsp_err_t | R_FLASH_LP_StatusGet (flash_ctrl_t *const p_api_ctrl, flash_status_t *const p_status) |
fsp_err_t | R_FLASH_LP_AccessWindowSet (flash_ctrl_t *const p_api_ctrl, uint32_t const start_addr, uint32_t const end_addr) |
fsp_err_t | R_FLASH_LP_AccessWindowClear (flash_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_FLASH_LP_IdCodeSet (flash_ctrl_t *const p_api_ctrl, uint8_t const *const p_id_code, flash_id_code_mode_t mode) |
fsp_err_t | R_FLASH_LP_Reset (flash_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_FLASH_LP_StartUpAreaSelect (flash_ctrl_t *const p_api_ctrl, flash_startup_area_swap_t swap_type, bool is_temporary) |
fsp_err_t | R_FLASH_LP_BankSwap (flash_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_FLASH_LP_UpdateFlashClockFreq (flash_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_FLASH_LP_InfoGet (flash_ctrl_t *const p_api_ctrl, flash_info_t *const p_info) |
fsp_err_t | R_FLASH_LP_Close (flash_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_FLASH_LP_CallbackSet (flash_ctrl_t *const p_api_ctrl, void(*p_callback)(flash_callback_args_t *), void const *const p_context, flash_callback_args_t *const p_callback_memory) |
fsp_err_t | R_FLASH_LP_AntiRollbackCounterIncrement (flash_ctrl_t *const p_api_ctrl, flash_arc_t counter) |
fsp_err_t | R_FLASH_LP_AntiRollbackCounterRefresh (flash_ctrl_t *const p_api_ctrl, flash_arc_t counter) |
fsp_err_t | R_FLASH_LP_AntiRollbackCounterRead (flash_ctrl_t *const p_api_ctrl, flash_arc_t counter, uint32_t *const p_count) |
fsp_err_t | R_FLASH_LP_UserLockableAreaWrite (flash_ctrl_t *const p_api_ctrl, uint32_t const src_address, uint32_t flash_address, uint32_t const num_bytes) |
Driver for the flash memory on RA low-power MCUs. This module implements the Flash Interface.
The Flash HAL module APIs allow an application to write, erase and blank check both the data and code flash areas that reside within the MCU. The amount of flash memory available varies across MCU parts.
The Low-Power Flash HAL module has the following key features:
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Code Flash Programming |
| Disabled | Controls whether or not code-flash programming is enabled. Disabling reduces the amount of ROM and RAM used by the API. |
Data Flash Programming |
| Enabled | Controls whether or not data-flash programming is enabled. Disabling reduces the amount of ROM used by the API. |
Data Flash Background Operation Support |
| Enabled | Controls whether or not Data Flash Background Operation support is included in the build. Disabling reduces the amount of ROM used by the API. |
Configuration | Options | Default | Description |
---|---|---|---|
Name | Name must be a valid C symbol | g_flash0 | Module name. |
Data Flash Background Operation |
| Enabled | Enabling allows Flash API calls that reference data-flash to return immediately, with the operation continuing in the background. |
Callback | Name must be a valid C symbol | NULL | A user callback function can be specified. Callback function called when a Data Flash Background Operation completes or errors. |
Flash Ready Interrupt Priority | MCU Specific Options | Select the flash ready interrupt priority. |
Flash either uses FCLK or ICLK as the clock source depending on the MCU. When writing and erasing the clock source must be at least 4 MHz.
This module does not use I/O pins.
When using the data flash BGO, the code flash, RAM and external memory can still be accessed. You must ensure that the data flash is not accessed during a data flash operation. This includes interrupts that may access the data flash.
Code flash cannot be accessed while writing, erasing or blank checking code flash. Code flash cannot be accessed while modifying the access window, selecting the startup area or setting the ID code. In order to support modifying code flash all supporting code must reside in RAM. This is only done when code flash programming is enabled. BGO mode is not supported for code flash, so a code flash operation will not return before the operation has completed. By default, the vector table resides in the code flash. If an interrupt occurs during the code flash operation, then code flash will be accessed to fetch the interrupt's starting address and an error will occur. The simplest work-around is to disable interrupts during code flash operations. Another option is to copy the vector table to RAM, update the VTOR (Vector Table Offset Register) accordingly and ensure that any interrupt service routines execute out of RAM. Similarly, you must insure that if in a multi-threaded environment, threads running from code flash cannot become active while a code flash operation is in progress.
The flash clock source is the clock used by the Flash peripheral in performing all Flash operations. As part of the flash_api_t::open function the Flash clock source is checked will return FSP_ERR_FCLK if it is invalid. Once the Flash API has been opened, if the flash clock source frequency is changed, the flash_api_t::updateFlashClockFreq API function must be called to inform the API of the change. Failure to do so could result in flash operation failures and possibly damage the part.
Enable the flash ready interrupt only if you plan to use the data flash BGO. In this mode, the application can initiate a data flash operation and then be asynchronously notified of its completion, or an error, using a user supplied-callback function. The callback function is passed a structure containing event information that indicates the source of the callback event (for example, flash_api_t::FLASH_EVENT_ERASE_COMPLETE) When the FLASH FRDYI interrupt is enabled, the corresponding ISR will be defined in the flash driver. The ISR will call a user-callback function if one was registered with the flash_api_t::open API.
By default, the contents of data flash and code flash are cached by e2 studio. This means that during a debug session, modifications to these memory regions will not be observed by e2 studio. When debugging applications using e2 studio, disable the "Allow caching of flash contents" option in the debug configuration in order to view modified flash contents (Debug Configuration > Debugger > Debug Tool Settings > Allow caching of flash contents).
This is a basic example of erasing and writing to data flash and code flash.
This example demonstrates using BGO to do non-blocking operations on the data flash.
This example demonstrates swapping which flash bank is located at address 0. This feature is only on select MCUs.
Data Structures | |
struct | flash_lp_instance_ctrl_t |
struct flash_lp_instance_ctrl_t |
Flash instance control block. DO NOT INITIALIZE. Initialization occurs when R_FLASH_LP_Open() is called.
fsp_err_t R_FLASH_LP_Open | ( | flash_ctrl_t *const | p_api_ctrl, |
flash_cfg_t const *const | p_cfg | ||
) |
Initialize the Low Power flash peripheral. Implements flash_api_t::open.
The Open function initializes the Flash.
This function must be called once prior to calling any other FLASH API functions. If a user supplied callback function is supplied, then the Flash Ready interrupt will be configured to call the users callback routine with an Event type describing the source of the interrupt for Data Flash operations.
Example:
FSP_SUCCESS | Initialization was successful and timer has started. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl, p_cfg or p_callback if BGO is enabled. |
FSP_ERR_IRQ_BSP_DISABLED | Caller is requesting BGO but the Flash interrupts are not enabled. |
FSP_ERR_FCLK | FCLK must be a minimum of 4 MHz for Flash operations. |
FSP_ERR_ALREADY_OPEN | Flash Open() has already been called. |
FSP_ERR_TIMEOUT | Failed to exit P/E mode after configuring flash. |
FSP_ERR_INVALID_STATE | The system is not running from the required clock. |
fsp_err_t R_FLASH_LP_Write | ( | flash_ctrl_t *const | p_api_ctrl, |
uint32_t const | src_address, | ||
uint32_t | flash_address, | ||
uint32_t const | num_bytes | ||
) |
Write to the specified Code or Data Flash memory area. Implements flash_api_t::write.
Example:
FSP_SUCCESS | Operation successful. If BGO is enabled this means the operation was started successfully. |
FSP_ERR_IN_USE | The Flash peripheral is busy with a prior on-going transaction. |
FSP_ERR_NOT_OPEN | The Flash API is not Open. |
FSP_ERR_WRITE_FAILED | Status is indicating a Programming error for the requested operation. This may be returned if the requested Flash area is not blank. |
FSP_ERR_TIMEOUT | Timed out waiting for FCU operation to complete. |
FSP_ERR_INVALID_SIZE | Number of bytes provided was not a multiple of the programming size or exceeded the maximum range. |
FSP_ERR_INVALID_ADDRESS | Invalid address was input or address not on programming boundary. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl. |
fsp_err_t R_FLASH_LP_Erase | ( | flash_ctrl_t *const | p_api_ctrl, |
uint32_t const | address, | ||
uint32_t const | num_blocks | ||
) |
Erase the specified Code or Data Flash blocks. Implements flash_api_t::erase.
Example:
FSP_SUCCESS | Successful open. |
FSP_ERR_INVALID_BLOCKS | Invalid number of blocks specified |
FSP_ERR_INVALID_ADDRESS | Invalid address specified |
FSP_ERR_IN_USE | Other flash operation in progress, or API not initialized |
FSP_ERR_ASSERTION | NULL provided for p_ctrl |
FSP_ERR_NOT_OPEN | The Flash API is not Open. |
FSP_ERR_TIMEOUT | Timed out waiting for FCU to be ready. |
FSP_ERR_ERASE_FAILED | Status is indicating a Erase error. |
fsp_err_t R_FLASH_LP_BlankCheck | ( | flash_ctrl_t *const | p_api_ctrl, |
uint32_t const | address, | ||
uint32_t | num_bytes, | ||
flash_result_t * | p_blank_check_result | ||
) |
Perform a blank check on the specified address area. Implements flash_api_t::blankCheck.
Example:
FSP_SUCCESS | Blankcheck operation completed with result in p_blank_check_result, or blankcheck started and in-progess (BGO mode). |
FSP_ERR_INVALID_ADDRESS | Invalid data flash address was input |
FSP_ERR_INVALID_SIZE | 'num_bytes' was either too large or not aligned for the CF/DF boundary size. |
FSP_ERR_IN_USE | Flash is busy with an on-going operation. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
FSP_ERR_TIMEOUT | Timed out waiting for the FCU to become ready. |
FSP_ERR_BLANK_CHECK_FAILED | An error occurred during blank checking. |
fsp_err_t R_FLASH_LP_StatusGet | ( | flash_ctrl_t *const | p_api_ctrl, |
flash_status_t *const | p_status | ||
) |
Query the FLASH for its status. Implements flash_api_t::statusGet.
Example:
FSP_SUCCESS | Flash is ready and available to accept commands. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
fsp_err_t R_FLASH_LP_AccessWindowSet | ( | flash_ctrl_t *const | p_api_ctrl, |
uint32_t const | start_addr, | ||
uint32_t const | end_addr | ||
) |
Configure an access window for the Code Flash memory. Implements flash_api_t::accessWindowSet.
An access window defines a contiguous area in Code Flash for which programming/erase is enabled. This area is on block boundaries. The block containing start_addr is the first block. The block containing end_addr is the last block. The access window then becomes first block (inclusive) –> last block (exclusive). Anything outside this range of Code Flash is then write protected. As an example, if you wanted to place an accesswindow on Code Flash Blocks 0 and 1, such that only those two blocks were writable, you would need to specify (address in block 0, address in block 2) as the respective start and end address.
The invalid address and programming boundaries supported and enforced by this function are dependent on the MCU in use as well as the part package size. Please see the User manual and/or requirements document for additional information.
p_api_ctrl | The p api control | |
[in] | start_addr | The start address |
[in] | end_addr | The end address |
FSP_SUCCESS | Access window successfully configured. |
FSP_ERR_INVALID_ADDRESS | Invalid settings for start_addr and/or end_addr. |
FSP_ERR_IN_USE | FLASH peripheral is busy with a prior operation. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl. |
FSP_ERR_UNSUPPORTED | Code Flash Programming is not enabled. |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
FSP_ERR_TIMEOUT | Timed out waiting for the FCU to become ready. |
FSP_ERR_WRITE_FAILED | Status is indicating a Programming error for the requested operation. |
fsp_err_t R_FLASH_LP_AccessWindowClear | ( | flash_ctrl_t *const | p_api_ctrl | ) |
Remove any access window that is configured in the Code Flash. Implements flash_api_t::accessWindowClear. On successful return from this call all Code Flash is writable.
FSP_SUCCESS | Access window successfully removed. |
FSP_ERR_IN_USE | FLASH peripheral is busy with a prior operation. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl. |
FSP_ERR_UNSUPPORTED | Code Flash Programming is not enabled. |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
FSP_ERR_TIMEOUT | Timed out waiting for the FCU to become ready. |
FSP_ERR_WRITE_FAILED | Status is indicating a Programming error for the requested operation. |
fsp_err_t R_FLASH_LP_IdCodeSet | ( | flash_ctrl_t *const | p_api_ctrl, |
uint8_t const *const | p_id_code, | ||
flash_id_code_mode_t | mode | ||
) |
Write the ID code provided to the id code registers. Implements flash_api_t::idCodeSet.
FSP_SUCCESS | ID code successfully configured. |
FSP_ERR_IN_USE | FLASH peripheral is busy with a prior operation. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl. |
FSP_ERR_UNSUPPORTED | Code Flash Programming is not enabled. |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
FSP_ERR_TIMEOUT | Timed out waiting for completion of extra command. |
FSP_ERR_WRITE_FAILED | Status is indicating a Programming error for the requested operation. |
fsp_err_t R_FLASH_LP_Reset | ( | flash_ctrl_t *const | p_api_ctrl | ) |
Reset the FLASH peripheral. Implements flash_api_t::reset.
No attempt is made to check if the flash is busy before executing the reset since the assumption is that a reset will terminate any existing operation.
FSP_SUCCESS | Flash circuit successfully reset. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
fsp_err_t R_FLASH_LP_StartUpAreaSelect | ( | flash_ctrl_t *const | p_api_ctrl, |
flash_startup_area_swap_t | swap_type, | ||
bool | is_temporary | ||
) |
Select which block is used as the startup area block. Implements flash_api_t::startupAreaSelect.
Selects which block - Default (Block 0) or Alternate (Block 1) is used as the startup area block. The provided parameters determine which block will become the active startup block and whether that action will be immediate (but temporary), or permanent subsequent to the next reset. Doing a temporary switch might appear to have limited usefulness. If there is an access window in place such that Block 0 is write protected, then one could do a temporary switch, update the block and switch them back without having to touch the access window.
FSP_SUCCESS | Start-up area successfully toggled. |
FSP_ERR_IN_USE | Flash is busy with an on-going operation. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
FSP_ERR_WRITE_FAILED | Status is indicating a Programming error for the requested operation. |
FSP_ERR_TIMEOUT | Timed out waiting for the FCU to become ready. |
FSP_ERR_UNSUPPORTED | Code Flash Programming is not enabled. Cannot set FLASH_STARTUP_AREA_BTFLG when the temporary flag is false. |
fsp_err_t R_FLASH_LP_BankSwap | ( | flash_ctrl_t *const | p_api_ctrl | ) |
Swap the Code Flash bank to update new program. Implement flash_api_t::bankSwap.
Swap the flash bank located at address 0x00000000 and address 0x00040000. After a bank swap is done the MCU will need to be reset for the changes to take place.
To use this API, Code Flash Programming in the FSP Configuration Tool under Stack Properties must be enabled.
[in] | p_api_ctrl | The api control instance. |
FSP_SUCCESS | Banks were swapped. |
FSP_ERR_UNSUPPORTED | Module does not support Bank Swap. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl. |
FSP_ERR_NOT_OPEN | The control block is not open. |
FSP_ERR_IN_USE | Extra area is being used by other command. |
fsp_err_t R_FLASH_LP_UpdateFlashClockFreq | ( | flash_ctrl_t *const | p_api_ctrl | ) |
Indicate to the already open Flash API that the FCLK has changed. Implements flash_api_t::updateFlashClockFreq.
This could be the case if the application has changed the system clock, and therefore the FCLK. Failure to call this function subsequent to changing the FCLK could result in damage to the flash macro.
FSP_SUCCESS | Start-up area successfully toggled. |
FSP_ERR_IN_USE | Flash is busy with an on-going operation. |
FSP_ERR_FCLK | Invalid flash clock source frequency. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
FSP_ERR_TIMEOUT | Timed out waiting for the FCU to become ready. |
fsp_err_t R_FLASH_LP_InfoGet | ( | flash_ctrl_t *const | p_api_ctrl, |
flash_info_t *const | p_info | ||
) |
Returns the information about the flash regions. Implements flash_api_t::infoGet.
FSP_SUCCESS | Successful retrieved the request information. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl or p_info. |
FSP_ERR_NOT_OPEN | The flash is not open. |
fsp_err_t R_FLASH_LP_Close | ( | flash_ctrl_t *const | p_api_ctrl | ) |
Release any resources that were allocated by the Flash API. Implements flash_api_t::close.
FSP_SUCCESS | Successful close. |
FSP_ERR_ASSERTION | NULL provided for p_ctrl or p_cfg. |
FSP_ERR_NOT_OPEN | Flash API has not yet been opened. |
FSP_ERR_IN_USE | The flash is currently in P/E mode. |
fsp_err_t R_FLASH_LP_CallbackSet | ( | flash_ctrl_t *const | p_api_ctrl, |
void(*)(flash_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
flash_callback_args_t *const | p_callback_memory | ||
) |
Stub function Implements flash_api_t::callbackSet.
FSP_ERR_UNSUPPORTED | Function has not been implemented. |
fsp_err_t R_FLASH_LP_AntiRollbackCounterIncrement | ( | flash_ctrl_t *const | p_api_ctrl, |
flash_arc_t | counter | ||
) |
Stub function Implements flash_api_t::antiRollbackCounterIncrement.
FSP_ERR_UNSUPPORTED | Function has not been implemented. |
fsp_err_t R_FLASH_LP_AntiRollbackCounterRefresh | ( | flash_ctrl_t *const | p_api_ctrl, |
flash_arc_t | counter | ||
) |
Stub function Implements flash_api_t::antiRollbackCounterRefresh.
FSP_ERR_UNSUPPORTED | Function has not been implemented. |
fsp_err_t R_FLASH_LP_AntiRollbackCounterRead | ( | flash_ctrl_t *const | p_api_ctrl, |
flash_arc_t | counter, | ||
uint32_t *const | p_count | ||
) |
Stub function Implements flash_api_t::antiRollbackCounterRead.
FSP_ERR_UNSUPPORTED | Function has not been implemented. |
fsp_err_t R_FLASH_LP_UserLockableAreaWrite | ( | flash_ctrl_t *const | p_api_ctrl, |
uint32_t const | src_address, | ||
uint32_t | flash_address, | ||
uint32_t const | num_bytes | ||
) |
Stub function Implements flash_api_t::userLockableAreaWrite.
FSP_ERR_UNSUPPORTED | Function has not been implemented. |