Renesas R7FA8D1BH (Cortex®-M85) Flash的功能介绍
目录
概述
1 Flash的功能介绍
1.1 功能特征
1.2 时钟配置
1.3 注意点
2 使用方法介绍
2.1 BGO 操作注意事项
2.2 代码Flash注意事项
2.3 Flash时钟(FCLK)
2.4 中断
2.5 注意点
2.6 Flash应用的限制
3 应用函数接口
3.1 R_FLASH_HP_Open()
3.2 R_FLASH_HP_Write()
3.3 R_FLASH_HP_Erase()
3.4 R_FLASH_HP_BlankCheck()
3.5 R_FLASH_HP_StatusGet()
3.6 R_FLASH_HP_IdCodeSet()
3.7 R_FLASH_HP_AccessWindowSet()
3.8 R_FLASH_HP_AccessWindowClear()
3.9 R_FLASH_HP_Reset()
3.10 R_FLASH_HP_StartUpAreaSelect()
3.11 R_FLASH_HP_BankSwap()
3.12 R_FLASH_HP_UpdateFlashClockFreq()
3.13 R_FLASH_HP_InfoGet()
3.14 R_FLASH_HP_Close()
3.15 R_FLASH_HP_CallbackSet()
概述
本文主要介绍Renesas R7FA8D1BH内部Flash的功能和使用方法,还介绍了操作Flash的应用函数的接口。
1 Flash的功能介绍
Flash HAL模块api允许应用程序写入,擦除和空白检查驻留在MCU内的数据和ROM闪存区域。可用的闪存数量因MCU部件而异。
1.1 功能特征
R_FLASH_HP模块具有以下主要特性:
数据闪存的阻塞和非阻塞擦除、写入和空白检查。
-
代码flash的阻塞擦除、写入和空白检查。-
用于完成非阻塞数据闪存操作的回调函数。-
ROM闪存的访问窗口(写保护),只允许指定区域的代码闪存被擦除或写入。-
block-swapping引导。-
支持ID码编程。
1.2 时钟配置
Flash根据MCU使用FCLK作为时钟源。写入和擦除时,时钟源必须至少为4mhz。
1.3 注意点
建议开发人员在使用r_flash_hp模块之前查看目标mcu硬件用户手册的Flash Memory部分的第5节和第6节。特别是,理解ID码和访问窗口功能可以帮助避免不可恢复的flash场景。
2 使用方法介绍
2.1 BGO 操作注意事项
当使用数据闪存BGO(Data Flash Background Operation)(后台操作)模式时,您仍然可以访问用户ROM, RAM和外部存储器。在进行数据刷新操作时,必须保证数据刷新未被访问。这包括可能访问数据闪存的中断。
2.2 代码Flash注意事项
代码flash在写入、擦除或空白检查代码flash时无法访问。修改访问窗口、选择启动区域或设置ID码时,无法访问代码flash。为了支持修改代码flash,所有支持代码必须驻留在RAM中。只有在启用代码flash编程时才会这样做。代码flash不支持BGO模式,因此代码flash操作在操作完成之前不会返回。
默认情况下,向量表驻留在代码flash中。如果在代码闪存操作期间发生中断,则将访问代码闪存以获取中断的起始地址,并将发生错误。最简单的解决方法是在代码flash操作期间禁用中断。另一种选择是将向量表复制到RAM,相应地更新VTOR(向量表偏移寄存器),并确保任何中断服务例程在RAM外执行。类似地,您必须确保在多线程环境中,当代码flash操作正在进行时,从代码flash运行的线程不能变为活动状态。
2.3 Flash时钟(FCLK)
flash时钟源是flash外设在执行所有flash操作时所使用的时钟。作为flash_api_t::open函数的一部分,检查Flash时钟源将返回FSP_ERR_FCLK,如果它无效。一旦打开了Flash API,如果Flash时钟源频率发生了变化,必须调用flash_api_t::updateFlashClockFreq API函数来通知API这个变化。如果不这样做,可能会导致闪光操作失败,并可能损坏部件。
2.4 中断
只有当您计划使用数据flash BGO时,才启用flash就绪中断。在这种模式下,应用程序可以启动数据闪存操作,然后使用用户提供的回调函数异步地通知其完成或错误。回调函数被传递给一个包含事件信息的结构,该事件信息表明回调事件的来源。
例如,flash_api_t::FLASH_EVENT_ERASE_COMPLETE。当FLASH FRDYI中断被启用时,相应的ISR将在FLASH驱动中定义。如果在flash_api_t::open API中注册了一个用户回调函数,ISR将调用它。
2.5 注意点
Flash HP支持额外的Flash错误中断,如果为Flash HP启用了BGO模式,则必须启用Flash就绪中断和Flash错误中断(分配优先级)。
2.6 Flash应用的限制
1) 写操作必须在页边界上对齐,并且必须是页边界大小的倍数。
2) 擦除操作将擦除所提供地址所在的整个块。
3) 数据闪存更适合于存储数据,因为它可以在代码仍然从代码闪存执行时被擦除和写入。数据闪4) 存还保证比代码闪存具有更多的重编程/擦除周期。
5) 擦除数据的flash块的读值不保证为0xFF。应使用空白检查来确定内存是否已被擦除但尚未编程。
3 应用函数接口
3.1 R_FLASH_HP_Open()
函数原型:
fsp_err_t R_FLASH_HP_Open ( flash_ctrl_t *const p_api_ctrl,
flash_cfg_t const *const p_cfg
)
功能介绍:
初始化高性能闪存外设。实现flash_api_t::开放。Open函数初始化Flash。
Example:
/* Open the flash hp instance. */
fsp_err_t err = R_FLASH_HP_Open(&g_flash_ctrl, &g_flash_cfg);
参数介绍
Return values
FSP_SUCCESS Initialization was successful and timer has started. FSP_ERR_ALREADY_OPEN The flash control block is already open. FSP_ERR_ASSERTION NULL provided for p_ctrl or p_cfg. 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.
3.2 R_FLASH_HP_Write()
函数原型
fsp_err_t R_FLASH_HP_Write ( flash_ctrl_t *const p_api_ctrl,
uint32_t const src_address,
uint32_t flash_address,
uint32_t const num_bytes
)
功能介绍
写入指定的代码或数据闪存区域。实现flash_api_t:写作。
Example:
/* Write 32 bytes to the first block of data flash. */
err = R_FLASH_HP_Write(&g_flash_ctrl, (uint32_t) g_src, FLASH_DF_BLOCK_0, FLASH_HP_EXAMPLE_WRITE_SIZE);
参数介绍
Return values
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_CMD_LOCKED FCU is in locked state, typically as a result of attempting to Write an area that is protected by an Access Window. 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_PE_FAILURE Failed to enter or exit P/E mode.
3.3 R_FLASH_HP_Erase()
函数原型
fsp_err_t R_FLASH_HP_Erase ( flash_ctrl_t *const p_api_ctrl,
uint32_t const address,
uint32_t const num_blocks
)
功能介绍
擦除指定的Code或Data Flash块。通过block_erase_address实现flash_api_t::erase。
-
请注意
-
flash代码可能包含不同大小的块。在擦除代码闪存时,重要的是要考虑到这一点,以防止擦除比期望的更大的地址空间。
Example:
/* Erase 1 block of data flash starting at block 0. */
err = R_FLASH_HP_Erase(&g_flash_ctrl, FLASH_DF_BLOCK_0, 1);
参数介绍
Return values
FSP_SUCCESS Successful open. FSP_ERR_INVALID_BLOCKS Invalid number of blocks specified FSP_ERR_INVALID_ADDRESS Invalid address specified. If the address is in code flash then code flash programming must be enabled. FSP_ERR_IN_USE Other flash operation in progress, or API not initialized FSP_ERR_CMD_LOCKED FCU is in locked state, typically as a result of attempting to Erase an area that is protected by an Access Window. FSP_ERR_ASSERTION NULL provided for p_ctrl FSP_ERR_NOT_OPEN The Flash API is not Open. FSP_ERR_ERASE_FAILED Status is indicating a Erase error. FSP_ERR_TIMEOUT Timed out waiting for the FCU to become ready. FSP_ERR_PE_FAILURE Failed to enter or exit P/E mode.
3.4 R_FLASH_HP_BlankCheck()
函数原型
fsp_err_t R_FLASH_HP_BlankCheck ( flash_ctrl_t *const p_api_ctrl,
uint32_t const address,
uint32_t num_bytes,
flash_result_t * p_blank_check_result
)
功能介绍
对指定的地址区域进行空白检查。实现flash_api_t:: blankCheck。
Example:
/* Check if block 0 is erased. */
err = R_FLASH_HP_BlankCheck(&g_flash_ctrl, FLASH_DF_BLOCK_0, FLASH_DATA_BLOCK_SIZE, &blank_check_result);
assert(FSP_SUCCESS == err);
参数介绍
Return values
FSP_SUCCESS Blank check operation completed with result in p_blank_check_result, or blank check 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 Other flash operation in progress or API not initialized. FSP_ERR_ASSERTION NULL provided for p_ctrl. FSP_ERR_CMD_LOCKED FCU is in locked state, typically as a result of attempting to Erase an area that is protected by an Access Window. FSP_ERR_NOT_OPEN The Flash API is not Open. FSP_ERR_TIMEOUT Timed out waiting for the FCU to become ready. FSP_ERR_PE_FAILURE Failed to enter or exit P/E mode. FSP_ERR_BLANK_CHECK_FAILED Blank check operation failed.
3.5 R_FLASH_HP_StatusGet()
函数原型
fsp_err_t R_FLASH_HP_StatusGet ( flash_ctrl_t *const p_api_ctrl,
flash_status_t *const p_status
)
功能介绍
使用实例查询FLASH外设状态。实现flash_api_t:: statusGet。
Example:
flash_status_t status;
/* Wait until the current flash operation completes. */
do
{
err = R_FLASH_HP_StatusGet(&g_flash_ctrl, &status);
} while ((FSP_SUCCESS == err) && (FLASH_STATUS_BUSY == status));
参数介绍
Return values
FSP_SUCCESS FLASH peripheral is ready to use. FSP_ERR_ASSERTION NULL provided for p_ctrl. FSP_ERR_NOT_OPEN The Flash API is not Open.
3.6 R_FLASH_HP_IdCodeSet()
函数原型
fsp_err_t R_FLASH_HP_IdCodeSet ( flash_ctrl_t *const p_api_ctrl,
uint8_t const *const p_id_code,
flash_id_code_mode_t mode
)
功能介绍
实现flash_api_t:: idCodeSet。
参数介绍
Return values
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_PE_FAILURE Failed to enter or exit Code Flash P/E mode. 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_CMD_LOCKED FCU is in locked state, typically as a result of having received an illegal command.
3.7 R_FLASH_HP_AccessWindowSet()
函数原型
fsp_err_t R_FLASH_HP_AccessWindowSet ( flash_ctrl_t *const p_api_ctrl,
uint32_t const start_addr,
uint32_t const end_addr
)
功能介绍
使用提供的起始和结束地址为代码闪存配置访问窗口。访问窗口在Code Flash中定义了一个连续区域,对该区域启用了编程/擦除。这个区域在街区边界上。包含start_addr的块是第一个块。包含end_addr的块是最后一个块。然后,访问窗口变为第一个块- >最后一个块。代码Flash范围之外的任何内容都是写保护的。
-
请注意
-
如果起始地址和结束地址设置为相同的值,则有效地删除访问窗口。这实现了与R_FLASH_HP_AccessWindowClear()相同的功能。
实现flash_api_t:: accessWindowSet。
参数介绍
Return values
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_PE_FAILURE Failed to enter or exit Code Flash P/E mode. 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_CMD_LOCKED FCU is in locked state, typically as a result of having received an illegal command.
3.8 R_FLASH_HP_AccessWindowClear()
函数原型
fsp_err_t R_FLASH_HP_AccessWindowClear ( flash_ctrl_t *const p_api_ctrl )
功能介绍
删除当前在Code Flash中配置的任何访问窗口。在此调用之后,所有Code Flash都是可写的。实现flash_api_t:: accessWindowClear。
参数介绍
Return values
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_PE_FAILURE Failed to enter or exit Code Flash P/E mode. 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_CMD_LOCKED FCU is in locked state, typically as a result of having received an illegal command.
3.9 R_FLASH_HP_Reset()
函数原型
fsp_err_t R_FLASH_HP_Reset ( flash_ctrl_t *const p_api_ctrl )
功能介绍
重置FLASH外设。实现flash_api_t::重置。
在执行复位之前,没有尝试检查闪存是否忙,因为假设复位将终止任何现有的操作。
参数介绍
Return values
FSP_SUCCESS Flash circuit successfully reset. FSP_ERR_ASSERTION NULL provided for p_ctrl. FSP_ERR_NOT_OPEN The control block is not open. FSP_ERR_PE_FAILURE Failed to enter or exit P/E mode. FSP_ERR_TIMEOUT Timed out waiting for the FCU to become ready. FSP_ERR_CMD_LOCKED FCU is in locked state, typically as a result of having received an illegal command.
3.10 R_FLASH_HP_StartUpAreaSelect()
函数原型
fsp_err_t R_FLASH_HP_StartUpAreaSelect ( flash_ctrl_t *const p_api_ctrl,
flash_startup_area_swap_t swap_type,
bool is_temporary
)
功能介绍
选择哪个块,默认(块0)或备用(块1),被用作启动区域块。
-
所提供的参数决定哪个块将成为活动的启动块,以及该动作是立即的(但暂时的),还是在下一次重置之后永久的。做一个临时的转换可能看起来用处有限。
-
如果有一个访问窗口,使得Block 0受到写保护,那么可以做一个临时切换,更新块并将它们切换回来,而不必触摸访问窗口。
-
实现flash_api_t:: startupAreaSelect。
参数介绍
Return values
FSP_SUCCESS Start-up area successfully toggled. FSP_ERR_IN_USE FLASH peripheral is busy with a prior operation. FSP_ERR_ASSERTION NULL provided for p_ctrl. FSP_ERR_NOT_OPEN The control block is not open. FSP_ERR_UNSUPPORTED Code Flash Programming is not enabled. FSP_ERR_PE_FAILURE Failed to enter or exit Code Flash P/E mode. 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_CMD_LOCKED FCU is in locked state, typically as a result of having received an illegal command.
3.11 R_FLASH_HP_BankSwap()
函数原型
fsp_err_t R_FLASH_HP_BankSwap ( flash_ctrl_t *const p_api_ctrl )
功能介绍
交换位于地址0x00000000和地址0x00200000的闪存库。
-
这只能在双bank模式下完成。双银行模式可以在BSP属性下的FSP配置工具中启用。
-
在bank交换完成后,MCU将需要重置以进行更改。flash_api_t:: bankSwap。
参数介绍
Return values
FSP_SUCCESS Start-up area successfully toggled. FSP_ERR_IN_USE FLASH peripheral is busy with a prior operation. FSP_ERR_ASSERTION NULL provided for p_ctrl. FSP_ERR_NOT_OPEN The control block is not open. FSP_ERR_UNSUPPORTED Code Flash Programming is not enabled. FSP_ERR_PE_FAILURE Failed to enter or exit Code Flash P/E mode. FSP_ERR_TIMEOUT Timed out waiting for the FCU to become ready. FSP_ERR_INVALID_MODE Cannot switch banks while flash is in Linear mode. FSP_ERR_WRITE_FAILED Flash write operation failed. FSP_ERR_CMD_LOCKED FCU is in locked state, typically as a result of having received an illegal command.
3.12 R_FLASH_HP_UpdateFlashClockFreq()
函数原型
fsp_err_t R_FLASH_HP_UpdateFlashClockFreq ( flash_ctrl_t *const p_api_ctrl )
功能介绍
向已经打开的Flash API表明FCLK已经更改。
-
实现flash_api_t:: updateFlashClockFreq。
-
如果应用程序改变了系统时钟,也就改变了FCLK,就可能出现这种情况。
-
更改FCLK后未能调用此函数可能会导致损坏闪光灯宏。
参数介绍
Return values
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_FCLK FCLK is not within the acceptable range.
3.13 R_FLASH_HP_InfoGet()
函数原型
fsp_err_t R_FLASH_HP_InfoGet ( flash_ctrl_t *const p_api_ctrl,
flash_info_t *const p_info
)
功能介绍
返回有关flash区域的信息。实现flash_api_t:: infoGet。
参数介绍
Return values
FSP_SUCCESS Successful retrieved the request information. FSP_ERR_NOT_OPEN The control block is not open. FSP_ERR_ASSERTION NULL provided for p_ctrl or p_info.
3.14 R_FLASH_HP_Close()
函数原型
fsp_err_t R_FLASH_HP_Close ( flash_ctrl_t *const p_api_ctrl )
功能介绍
释放Open()或任何后续Flash操作分配的任何资源。实现flash_api_t:关闭。
参数介绍
Return values
FSP_SUCCESS Successful close. FSP_ERR_NOT_OPEN The control block is not open. FSP_ERR_ASSERTION NULL provided for p_ctrl or p_cfg.
3.15 R_FLASH_HP_CallbackSet()
函数原型
fsp_err_t R_FLASH_HP_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
)
功能介绍
使用为回调参数结构提供内存的选项更新用户回调。实现flash_api_t:: callbackSet。
参数介绍
Return values
FSP_SUCCESS Callback updated successfully. FSP_ERR_ASSERTION A required pointer is NULL. FSP_ERR_NOT_OPEN The control block has not been opened. FSP_ERR_NO_CALLBACK_MEMORY p_callback is non-secure and p_callback_memory is either secure or NULL.