Renesas R7FA8D1BH (Cortex®-M85) Flash的功能介绍

devtools/2024/11/7 8:24:05/

目录

概述

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_SUCCESSInitialization was successful and timer has started.
FSP_ERR_ALREADY_OPENThe flash control block is already open.
FSP_ERR_ASSERTIONNULL provided for p_ctrl or p_cfg.
FSP_ERR_IRQ_BSP_DISABLEDCaller is requesting BGO but the Flash interrupts are not enabled.
FSP_ERR_FCLKFCLK 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_SUCCESSOperation successful. If BGO is enabled this means the operation was started successfully.
FSP_ERR_IN_USEThe Flash peripheral is busy with a prior on-going transaction.
FSP_ERR_NOT_OPENThe Flash API is not Open.
FSP_ERR_CMD_LOCKEDFCU is in locked state, typically as a result of attempting to Write an area that is protected by an Access Window.
FSP_ERR_WRITE_FAILEDStatus is indicating a Programming error for the requested operation. This may be returned if the requested Flash area is not blank.
FSP_ERR_TIMEOUTTimed out waiting for FCU operation to complete.
FSP_ERR_INVALID_SIZENumber of bytes provided was not a multiple of the programming size or exceeded the maximum range.
FSP_ERR_INVALID_ADDRESSInvalid address was input or address not on programming boundary.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_PE_FAILUREFailed 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_SUCCESSSuccessful open.
FSP_ERR_INVALID_BLOCKSInvalid number of blocks specified
FSP_ERR_INVALID_ADDRESSInvalid address specified. If the address is in code flash then code flash programming must be enabled.
FSP_ERR_IN_USEOther flash operation in progress, or API not initialized
FSP_ERR_CMD_LOCKEDFCU is in locked state, typically as a result of attempting to Erase an area that is protected by an Access Window.
FSP_ERR_ASSERTIONNULL provided for p_ctrl
FSP_ERR_NOT_OPENThe Flash API is not Open.
FSP_ERR_ERASE_FAILEDStatus is indicating a Erase error.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_PE_FAILUREFailed 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_SUCCESSBlank check operation completed with result in p_blank_check_result, or blank check started and in-progess (BGO mode).
FSP_ERR_INVALID_ADDRESSInvalid 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_USEOther flash operation in progress or API not initialized.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_CMD_LOCKEDFCU is in locked state, typically as a result of attempting to Erase an area that is protected by an Access Window.
FSP_ERR_NOT_OPENThe Flash API is not Open.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_PE_FAILUREFailed to enter or exit P/E mode.
FSP_ERR_BLANK_CHECK_FAILEDBlank 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_SUCCESSFLASH peripheral is ready to use.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_NOT_OPENThe 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_SUCCESSID Code successfully configured.
FSP_ERR_IN_USEFLASH peripheral is busy with a prior operation.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_UNSUPPORTEDCode Flash Programming is not enabled.
FSP_ERR_NOT_OPENFlash API has not yet been opened.
FSP_ERR_PE_FAILUREFailed to enter or exit Code Flash P/E mode.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_WRITE_FAILEDStatus is indicating a Programming error for the requested operation.
FSP_ERR_CMD_LOCKEDFCU 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_SUCCESSAccess window successfully configured.
FSP_ERR_INVALID_ADDRESSInvalid settings for start_addr and/or end_addr.
FSP_ERR_IN_USEFLASH peripheral is busy with a prior operation.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_UNSUPPORTEDCode Flash Programming is not enabled.
FSP_ERR_NOT_OPENFlash API has not yet been opened.
FSP_ERR_PE_FAILUREFailed to enter or exit Code Flash P/E mode.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_WRITE_FAILEDStatus is indicating a Programming error for the requested operation.
FSP_ERR_CMD_LOCKEDFCU 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_SUCCESSAccess window successfully removed.
FSP_ERR_IN_USEFLASH peripheral is busy with a prior operation.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_UNSUPPORTEDCode Flash Programming is not enabled.
FSP_ERR_NOT_OPENFlash API has not yet been opened.
FSP_ERR_PE_FAILUREFailed to enter or exit Code Flash P/E mode.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_WRITE_FAILEDStatus is indicating a Programming error for the requested operation.
FSP_ERR_CMD_LOCKEDFCU 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_SUCCESSFlash circuit successfully reset.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_NOT_OPENThe control block is not open.
FSP_ERR_PE_FAILUREFailed to enter or exit P/E mode.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_CMD_LOCKEDFCU 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_SUCCESSStart-up area successfully toggled.
FSP_ERR_IN_USEFLASH peripheral is busy with a prior operation.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_NOT_OPENThe control block is not open.
FSP_ERR_UNSUPPORTEDCode Flash Programming is not enabled.
FSP_ERR_PE_FAILUREFailed to enter or exit Code Flash P/E mode.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_WRITE_FAILEDStatus is indicating a Programming error for the requested operation.
FSP_ERR_CMD_LOCKEDFCU 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_SUCCESSStart-up area successfully toggled.
FSP_ERR_IN_USEFLASH peripheral is busy with a prior operation.
FSP_ERR_ASSERTIONNULL provided for p_ctrl.
FSP_ERR_NOT_OPENThe control block is not open.
FSP_ERR_UNSUPPORTEDCode Flash Programming is not enabled.
FSP_ERR_PE_FAILUREFailed to enter or exit Code Flash P/E mode.
FSP_ERR_TIMEOUTTimed out waiting for the FCU to become ready.
FSP_ERR_INVALID_MODECannot switch banks while flash is in Linear mode.
FSP_ERR_WRITE_FAILEDFlash write operation failed.
FSP_ERR_CMD_LOCKEDFCU 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_SUCCESSStart-up area successfully toggled.
FSP_ERR_IN_USEFlash is busy with an on-going operation.
FSP_ERR_ASSERTIONNULL provided for p_ctrl
FSP_ERR_NOT_OPENFlash API has not yet been opened.
FSP_ERR_FCLKFCLK 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_SUCCESSSuccessful retrieved the request information.
FSP_ERR_NOT_OPENThe control block is not open.
FSP_ERR_ASSERTIONNULL 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_SUCCESSSuccessful close.
FSP_ERR_NOT_OPENThe control block is not open.
FSP_ERR_ASSERTIONNULL 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_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.


http://www.ppmy.cn/devtools/131959.html

相关文章

反序列化失败问题

关于ROS2(Robot Operating System 2)中的反序列化失败问题,通常这个问题可能出现在订阅端,因为反序列化是指将接收到的数据流转换成数据结构,例如对象。如果订阅端接收到的数据格式与预期不符,或者使用的反…

Array.prototype.map()的用法和手写

1.Array.prototype.map()的基本使用 Array.prototype.map() 是 JavaScript 中数组的原型方法之一,用于对数组中的每个元素执行指定的操作,并返回操作结果组成的新数组。它的基本语法如下: const newArray array.map(callback(element,inde…

Tomcat 启动卡住,日志显示 At least one JAR was scanned for TLDs yet contained no TLDs.

现象 Tomcat 启动后,控制台输出卡在了: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JA…

主流OLAP对比

参考 主流大数据OLAP框架对比 分类 按照架构实现划分: MPP 架构系统:Presto、Impala、Doris、Clickhouse、Spark SQL、Flink SQL…,这种架构主要还是从查询引擎入手,使用分布式查询引擎。搜索引擎架构的系统:es。预计…

udp丢包问题

udp或者tcp丢包问题监测方式: netstat -su 问题分析: 1. 内存 2. cpu 3. 发送接收缓存 动画图解 socket 缓冲区的那些事儿-CSDN博客

Python自动化运维的未来趋势

Python自动化运维的未来趋势 目录 🤖 AIOps的概念与实践:自动化与智能化的未来🧠 人工智能在运维中的潜力与应用:革新运维操作🌐 新兴技术(如边缘计算)对运维的影响:技术变革下的新…

Claude 3.5 Sonnet模型新增了PDF支持功能

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗?订阅我们的简报,深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同,从行业内部的深度分析和实用指南中受益。不要错过这个机会,成为AI领…

十四届蓝桥杯STEMA考试Python真题试卷第二套第四题

来源:十四届蓝桥杯STEMA考试Python真题试卷第二套编程第四题:糖果罐调整 该题解通过贪心策略在每一步都选择对当前状态最有利的操作,从而达到最少调整次数的目标。 题目描述 现有 N 罐糖果,且已知每罐糖果的初始数量。现给出两个数值 L 和 R(L≤R),需要把每罐糖果的数…