本应用笔记介绍如何使用内置实用程序rom擦除/写入maxq7665微控制器(μc)中的程序和数据闪存。此信息适用于带可页面擦除(pe)闪存的基于maxq7665闪存的μc。
介绍本应用笔记介绍如何管理带有页面擦除(pe)闪存的maxq7665闪存微控制器(μc)中的内部数据和程序闪存。此讨论包括有关执行程序闪存的应用程序内编程 (iap) 的一般信息。
内存映射本节详细介绍maxq7665 μc系列各种存储器尺寸的一般闪存信息和存储器结构。max7665器件提供三种类型的闪存:扇区擦除、单字擦除和两页擦除。本文档仅介绍带pe闪存和两页擦除数据闪存的maxq7665器件;该讨论不适用于仅扇区擦除设备或具有单字可擦除数据闪存的设备。
表1至表3分别显示了从程序闪存、实用程序rom和数据sram执行代码时16kb器件的存储器映射。图 1 和图 2 显示了 16kb 和 256b 程序闪存的扇区和页面结构。其他闪光灯选项可用;请参考maxq7665数据资料获取完整列表。
表 1.16kb 内存空间 — 从程序闪存执行
表 2.16kb 内存空间 — 从实用程序 rom 执行
表 3.16kb 内存空间 — 从数据 sram 执行
图1.16kb程序闪存的扇区/页面结构。
图2.256b数据闪存的扇区/页面结构。
使用数据闪存存储数据闪存可用于可靠地存储系统数据,这些数据需要在系统运行期间进行一次或定期编程。与eeprom不同,maxq7665上的pe闪存不能被字节/字擦除。必须一次擦除两页。这通常需要 10 毫秒,但在最坏的情况下可能需要更长的时间。在此期间,用户代码将停止,因此不会进行其他处理。
有多种存储数据到闪存的技术,在为应用程序选择适当的方法时,必须考虑几个因素。应用程序是否需要确保在新数据完全写入之前当前数据保持不变?如果答案是肯定的,那么某种形式的组切换技术是必要的,这样在写入新数据时不会丢失当前数据。在产品的生命周期内将发生多少个擦除/写入周期?如果擦除/写入周期数将超过数据手册中规定的最大值,则使用绑定队列方法可以将这些周期分散到数据闪存的多页上,从而显著增加总擦除/写入周期。对于大多数周期性数据存储需求,银行交换和/或有界队列技术满足系统的可靠性要求和需求。以下是每种技术的简单示例。
银行切换存储体交换是在擦除/写入周期中防止数据丢失或损坏的有效方法。此方法通过始终维护至少一个数据副本来很好地工作。组交换的缺点是它需要的数据闪存量是有界队列方法的两倍。事实上,银行切换实际上只是队列大小为 2 的有界队列方法。因此,有关如何实现有界队列的详细信息,请参阅下一节。
有界队列有界队列是受固定数量的项限制的队列,通常在处理定期数据时使用。有界队列是通过创建与所需数据块大小相等的“条目”的固定长度队列来形成的。条目大小特定于应用程序,必须向上舍入到最接近的页面擦除边界。 注意 :可以擦除的最小大小为两页/字。虽然可以根据应用程序要求以多种方式对数据闪存进行分区,但由于数据闪存施加的两页擦除限制,条目被限制为两页的倍数。例如,512 x 16 数据闪存可以分为 32 个 16 字条目,这将产生表 4 中的内存映射。
初始化后,启动例程可以扫描队列条目以确定队列中的下一个可用条目。一旦队列已满,就可以使其包装回开头。擦除数据闪存条目后,可以写入新条目。图 3 说明了进入有界队列的条目流。
有关简单的 c 源代码示例,请参阅附录 a。
表 4.有界队列内存映射示例| 闪光灯[ ] |
| ------------- |
| 队列索引 | 数据闪存地址 |
| 31 | 0xc1f0-0xc1ff |
| 30 | 0xc1e0-0xc1ef |
| 29 | 0xc1d0-0xc1df |
| . . . . | . . . . |
| 2 | 0xc020-0xc05f |
| 1 | 0xc010-0xc03f |
| 0 | 0xc000-0xc00f |
图3.有界队列流的图示。
实用程序 rom 闪存例程为了编程、擦除和验证闪存,maxq7665微控制器在rom (只读存储器)中提供了片内闪存支持程序。有两种方法可以访问这些例程:直接访问和通过查找表间接访问。最快的方法是直接访问,即直接调用例程。为此,请提供包含以下行的头文件:
u16 flasherasepage(void *);u16 flasherasesector(void *);u16 flasheraseall(void);u16 dataflashwrite(u16 *paddress, u16 idata);u16 dataflasherasepage(void *);u16 dataflasherasesector(void *);u16 dataflasheraseall(void);接下来,添加链接器定义以为每个例程分配适当的地址。对于 iar 链接器文件,添加的行如下所示:
-dflasherasesector=0x8xxx-dflasherasepage=0x8xxx-dflasheraseall=0x8xxx将 0x8xxx 替换为每个例程的相应内存地址。其他编译器可能会使用不同的方法来添加这些引用。
flashwrite() 实用程序例程不能直接从 c 调用,因为参数传递与 c 语言不兼容。必须编写如下所示的小型程序集例程才能调用此函数。
注意:直接访问方法不提供与未来 rom 版本的向前兼容性。
第二种方法是通过表查找进行间接访问。此方法提供了与未来rom版本的更大兼容性,但消耗更多的执行时间。在下面描述的每个例程之后,程序集例程使用表查找方法来获取 rom 实用程序例程的地址。表 5 显示了实用程序 rom 提供的闪存例程。有关实用程序rom例程的完整列表,请参考maxq7665用户指南。
表 5.闪存实用程序 rom 例程| 例程编号 | 例程名称 | 入口点可 romtable = rom[800dh] | 入口点物理地址 |
| ---------------------------------------------------------------------- | ---------- | -------------------------------- | ---------------- |
| 1 | 闪写 | 罗姆[可浪漫] | 0x8xxx |
| 2 | 闪光擦除页面 | 罗姆[可浪漫 + 1] | 0x8xxx |
| 3 | 闪光擦除全部 | 罗姆[可浪漫 + 2] | 0x8xxx |
| 4 | 移动dp0 | 罗姆[可浪漫 + 3] | 0x8xxx |
| 16 | 闪存擦除扇区 | 罗姆[可浪漫 + 15] | 0x8xxx |
| 17 | 数据闪写 | 罗姆[可浪漫 + 16] | 0x8xxx |
| 19 | 数据闪光擦除页面 | 罗姆[可浪漫 + 18] | 0x8xxx |
| 20 | 数据闪存擦除扇区 | 罗姆[可浪漫 + 19] | 0x8xxx |
| 21 | 数据闪存擦除全部 | 罗姆[可浪漫 + 20] | 0x8xxx |
闪写()| 常规: | u16 flashwrite(u16 *pdest, u16 *psrc) |
| ---------------------------------------------------- | ------------------------------------------ |
| 总结: | 对单页(32 字)的程序闪存进行编程。 |
| 输入: | dp[0] - 闪存中的目标地址。
dp[1]—sram 中的源地址,包含 32 个要写入的数据字。 |
| 输出: | 携带:错误时设置,成功时清除。如果设置,则 a[0] 包含以下错误代码之一: 1:由于软件超时而导致的故障
2:硬件 (dq5/ferr)
报告故障 4:
不支持
命令 sw_ferr - 出错时设置,成功时清除。 |
| 笔记: | 监视器不得处于活动状态,或者监视器超时必须设置足够长的时间才能在不触发重置的情况下完成此例程。 |
下面的汇编代码示例使用间接寻址方法(查找表)调用 flashwrite() 实用例程。此例程可由 c 代码调用。
; this routine is callable by c code using the following prototype; u16 flashwrite(u16 *pdest, u16 *psrc);;flashwrite: move apc, #0 ; no auto inc/dec of accumulator. move ap, #2 ; set acc to a[2]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #14 ; add the index to the flashwrite routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. push dp[1] ; save frame pointer on the stack. move dp[0],a[0] ; move argument 0(dest address) to dp[0]. move dp[1],a[1] ; move argument 1(src address) to dp[1]. call acc ; execute the routine. pop dp[1] ; restore frame pointer. ret ; status returned in a[0].flasherasepage()| 常规: | u16 闪存擦除页面(无效 *paddress) |
| ---------------------------------------------- | ------------------------------------ |
| 总结: | 擦除两页的程序闪存块。 |
| 输入: | a[0] - 位于要擦除的两页块中的地址,即要擦除第 0 页和第 1 页,a[0] 可以包含从 0x0000 到 0x001f 的任何地址。 |
| 输出: | 携带:错误时设置,成功时清除。如果设置,则 a[0] 包含以下错误代码之一: 1:由于软件超时而导致的故障
2:硬件 (dq5/ferr)
报告故障 4:
不支持
命令 sw_ferr - 出错时设置,成功时清除。 |
| 笔记: | 监视器不得处于活动状态,或者监视器超时必须设置足够长的时间才能在不触发重置的情况下完成此例程。 |
; this routine is callable by c code using the following prototype; u16 flasherasepage(void *paddress);;flasherasepage: move apc, #0 ; no auto inc/dec of accumulator. move ap, #1 ; set acc to a[1]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #1 ; add the index to the flasherasesector routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. call acc ; execute the routine. ret ; status returned in a[0].flasheraseall()| 常规: | 虚空闪光擦除全部(虚空) |
| ------------------------------------ | -------------------------- |
| 总结: | 擦除整个程序和数据闪存。此例程只能从 ram 调用。 |
| 输入: | 没有 |
| 输出: | 携带:错误时设置,成功时清除。
sw_ferr - 出错时设置,成功时清除。 |
| 笔记: | 监视器不得处于活动状态,或者监视器超时必须设置足够长的时间才能在不触发重置的情况下完成此例程。 |
; this routine is callable by c code using the following prototype; void flasheraseall(void);;flasheraseall: move apc, #0 ; no auto inc/dec of accumulator. move ap, #0 ; set acc to a[0]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #2 ; add the index to the flasheraseall routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. call acc ; execute the routine. ret移动dp0| 常规: | 移动dp0 |
| ------------------- | --------- |
| 总结: | 读取闪存的一个字。 |
| 输入: | dp[0] - 闪存中的源地址。添加0x8000以读取程序闪存。 |
| 输出: | gr将包含指定地址的数据。 |
| 笔记: | 不能直接从 c 调用此函数,因为参数和返回寄存器与 c 调用约定不兼容。 |
下面的汇编代码示例将 movedp0 转换为 c 可调用例程。如果速度对应用程序至关重要,则应为特定任务编写自定义汇编语言例程。有几个像这样的实用程序rom例程将有助于从闪存写入有效的数据传输。
; this routine is callable by c code using the following prototype; u16 flashread(u16 *paddress);;flashread: move apc, #0 ; no auto inc/dec of accumulator. move ap, #1 ; set acc to a[1]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #3 ; add the index to the movedp0 routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. push dp[1] ; save frame pointer on the stack. move dp[0],a[0] ; move argument 0(src address) to dp[0]. call acc ; execute the routine. pop dp[1] ; restore frame pointer. move a[0],gr ret ; data word returned in a[0].flasherasesector()| routine: | u16 flasherasesector(void *paddress) |
| -------------------------------------------------- | -------------------------------------- |
| summary: | erases a single sector of program-flash memory. |
| inputs: | a[0]—address located in the sector to erase. |
| outputs: | carry: set on error and cleared on success. if set, then a[0] contains one of the following error codes:
1: failure due to software timeout
2: failure reported by hardware (dq5/ferr)
4: command not supported
sw_ferr—set on error, cleared on success. |
| notes: | the watchdog must not be active or the watchdog timeout must be set long enough to complete this routine without triggering a reset. |
; this routine is callable by c code using the following prototype; u16 flasherasesector(void *paddress);;flasherasesector: move apc, #0 ; no auto inc/dec of accumulator. move ap, #1 ; set acc to a[1]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #15 ; add the index to the flasherasesector routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. call acc ; execute the routine. ret ; status returned in a[0].数据闪存写入()| 常规: | u16 dataflashwrite(void *paddress, u16 *pdata) |
| ------------------------------------------------------------- | --------------------------------------------------- |
| 总结: | 对单个字的数据闪存进行编程。 |
| 输入: | a[0] - 闪存中要写入的字地址。
a[1] — 要写入闪存的字值。 |
| 输出: | 携带:错误时设置,成功时清除。如果设置,则 a[0] 包含以下错误代码之一: 1:由于软件超时而导致的故障
2:硬件 (dq5/ferr)
报告的故障 4:
不支持
命令 sw_fer - 出错时设置,成功时清除。 |
| 笔记: | 监视器不得处于活动状态,或者监视器超时必须设置足够长的时间才能在不触发重置的情况下完成此例程。 |
下面的汇编代码示例使用间接寻址方法(查找表)调用 dataflashwrite() 实用工具例程。此例程可由 c 代码调用。
; this routine is callable by c code using the following prototype; u16 dataflashwrite(void *paddress, u16 idata);;dataflashwrite: move apc, #0 ; no auto inc/dec of accumulator. move ap, #2 ; set acc to a[2]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #16 ; add the index to the flashwrite routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. call acc ; execute the routine. ret ; status returned in a[0].dataflasherasepage()| 常规: | u16 dataflasherasepage(void *paddress) |
| ---------------------------------------------------- | ------------------------------------------ |
| 总结: | 擦除两页数据闪存。 |
| 输入: | a[0] - 位于要擦除的两页块中的地址,即要擦除第 0 页和第 1 页,a[0] 可以包含地址0x4000或0x4001。 |
| 输出: | 携带:错误时设置,成功时清除。如果设置,则 a[0] 包含以下错误代码之一: 1:由于软件超时而导致的故障
2:硬件 (dq5/ferr)
报告故障 4:
不支持
命令 sw_ferr - 出错时设置,成功时清除。 |
| 笔记: | 监视器不得处于活动状态,或者监视器超时必须设置足够长的时间才能在不触发重置的情况下完成此例程。 |
; this routine is callable by c code using the following prototype; u16 dataflasherasepage(void *paddress);;dataflasherasepage: move apc, #0 ; no auto inc/dec of accumulator. move ap, #1 ; set acc to a[1]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #18 ; add the index to the dataflasherasepage routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. call acc ; execute the routine. ret ; status returned in a[0].dataflasherasesector()| 常规: | u16 dataflasherasesector(void *paddress) |
| ------------------------------------------------------ | -------------------------------------------- |
| 总结: | 擦除数据闪存的单个扇区。 |
| 输入: | a[0] - 位于要擦除的扇区中的地址。 |
| 输出: | 携带:错误时设置,成功时清除。如果设置,则 a[0] 包含以下错误代码之一: 1:由于软件超时而导致的故障
2:硬件 (dq5/ferr)
报告故障 4:
不支持
命令 sw_ferr - 出错时设置,成功时清除。 |
| 笔记: | 监视器不得处于活动状态,或者监视器超时必须设置足够长的时间才能在不触发重置的情况下完成此例程。 |
; this routine is callable by c code using the following prototype; u16 dataflasherasesector(void *paddress);;dataflasherasesector: move apc, #0 ; no auto inc/dec of accumulator. move ap, #1 ; set acc to a[1]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #19 ; add the index to the dataflasherasesector routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. call acc ; execute the routine. ret ; status returned in a[0].数据闪存擦除全部| 常规: | void dataflasheraseall(void) |
| ------------------------------------------ | -------------------------------- |
| 总结: | 擦除整个数据闪存。 |
| 输入: | 没有 |
| 输出: | 携带:错误时设置,成功时清除。
sw_ferr - 出错时设置,成功时清除。 |
| 笔记: | 监视器不得处于活动状态,或者监视器超时必须设置足够长的时间才能在不触发重置的情况下完成此例程。 |
; this routine is callable by c code using the following prototype; void dataflasheraseall(void);;dataflasheraseall: move apc, #0 ; no auto inc/dec of accumulator. move ap, #0 ; set acc to a[0]. move dp[0], #0800dh ; this is where the address of the table is stored. move acc, @dp[0] ; get the location of the routine table. add #20 ; add the index to the flasheraseall routine. move dp[0], acc move acc, @dp[0] ; retrieve the address of the routine. call acc ; execute the routine. ret应用程序内编程 (iap)大多数基于闪存的系统的一个重要要求是能够在系统安装在最终产品中时更新固件。此过程称为应用程序内编程 (iap)。本节将概述创建 iap 应用程序的一般准则。
上一节中概述的实用程序 rom 闪存例程执行擦除和写入闪存 rom 所需的所有操作。因此,最终用户应用程序可以在闪存上执行操作。与任何其他子例程调用一样,控件将在例程完成后返回到最终用户的代码。
对于可靠的 iap,引导加载程序应用程序必须与主应用程序分开。这确保了即使在发生不完整的重编程序列后,也可以重试重编程过程。
引导加载程序rom 在初始化后跳转到寻址 0x0000 。因此,引导加载程序应用程序的入口点必须放在0x0000处。引导加载程序应用程序可以根据需要扩展到任意数量的闪存扇区/页面,但使用的任何页面都不适用于用户的应用程序代码。表6列出了擦除和写入闪存时必须满足的具体要求。
表 6.调用闪存实用程序 rom 例程的要求
不能从执行代码的同一闪存页中擦除或编程。这通常不是问题,因为在 iap 期间绝不应擦除闪存引导加载程序应用程序。
在调用 flasherasesector() 或 flasherasepage() 例程之前,必须将监视器超时设置得足够长,以便完成此例程,而不会触发重置。如果在擦除完成之前出现看门狗超时,它将重置器件。
因为系统控制寄存器位,sc。upa,必须设置为 0 才能访问实用程序 rom,实用程序 rom 例程不能直接从程序内存地址调用≥ 0x8000。如果需要从上层内存 (≥ 0x8000) 中的程序访问实用程序 rom 例程,则程序必须通过驻留在下层内存中的例程间接调用 rom 例程 (< 0x8000)。此限制有效地将引导加载程序限制为 = 64kb (32kb x 16)。
图4中的流程图显示了maxq7665退出复位状态时的作用。在诊断rom本身并验证闪存已准备就绪后,rom初始化代码将直接跳转到地址 0x0000 。
图4.简化rom初始化的流程图。
图 5 流程图显示了一个简单的引导加载程序应用程序如何运行。一个简单的应用程序标头可能如下所示:
typedef struct { u16 isize; // the size of the application in words u32 icrc; // the crc of the application u8 id[8]; // id string for current application} application_header;使用此标头中的信息,引导加载程序可以检查主应用程序的有效性,并在请求时报告版本标识。
图5.简化的闪存引导加载程序的流程图。
编程顺序本身非常简单。通过调用 flasherasesector() 和/或 flasherasepage() 擦除包含主应用程序代码的每个扇区/页面。然后通过为每 32 个需要编程的单词调用 flashwrite() 一次写一页。我们建议您先擦除包含应用程序标题的页面,最后对crc数据进行编程,以最大程度地减少crc匹配错误的可能性。重新刷新通过串行端口获取数据的微控制器的一个非常简单的例程如下所示:
如何从庞大的客户车队中获取训练数据,以训练其自动驾驶神经网络
360度全方位认识便携设备中的3D显示技术
DxO FilmPack 6:精准演绎胶片摄影之魂
中科院研究人员研发中国超音速飞机测试成功 高速可达8600公里/时
英特尔公司CEO帕特·基辛格致开放生态系统的一封公开信
MAXQ7665寻页(PE)程序和数据闪存的应用内编程(IAP)
人工智能将成为药物研究常用手段 全球首个AI设计疫苗问世
华为全球市场销量超过了苹果,为什么华为在英国禁止销售?
华为首次、大规模融资曝光!
电池充电器IC基本原理
7 FPGA VC707评估方案
盖茨将18亿美元股票转给梅琳达
为什么区块链在不同行业中越来越流行被用来改进数据完整性
企业如何解决数据科学家短缺详细方法什么
半导体投资风口正盛,硅谷模式是否适用于当今中国?
国产BMS模拟前端突围消费、工业市场,汽车市场仍困难重重
中国移动钱岭:大数据更像是一种“倍增器”
浅析奥迪的四种不同电动汽车平台
德州农工大学获得100万美元捐款用于半导体教育
紫外固化的氧抑制解决方案介绍