ESP8266 中 cache 和 iram 一点理解

版权声明:本文为博主原创文章,可以随意引用或转载,但未经博主允许不得用于任何商业用途。 https://blog.csdn.net/ustccw/article/details/84721188

前提阅读

指令载入方式

一. iram 方式(0x4010…, 需 load)

用户可通过 ld 文件中 iram1_0_seg 指定某个lib/某个段, 或者通过下面方式指定某个函数/某个变量, 将其放在 iram 中。

#define IRAM_ATTR	__attribute__((section(".text")))

在编译选项 -ffunction-sections 打开的情况下,函数的默认属性为 *.text*.text 属性的函数,将会被放到 .text.
如下 ld 所示,esp8266 sdk 默认将 iRAM 中 0x40100000 开始的 32KB 空间用作 iram,sdk 启动后, bootloader 将 flash 中代码 load 到 iram 中。

iram1_0_seg :   org = 0x40100000, len = 0x8000
二. cache 方式(0x4020…, 无需 load, 也被称为 flash 方式)

用户可通过 ld 文件中 irom0_0_seg 指定某个lib/某个段, 或者通过下面方式指定某个函数/某个变量, 将其放在 flash 中, 通过 cache 映射到内存。

#define ICACHE_RODATA_ATTR  __attribute__((section(".irom.text")))
#define ICACHE_FLASH_ATTR  __attribute__((section(".irom0.text")))

在编译选项 -ffunction-sections 打开的情况下,函数的默认属性为 .text..text. 属性的函数,将会被放到 .irom0.text.
如下 ld 所示,esp8266 sdk 默认将 iRAM 中 0x40108000 开始的 32KB 空间用作 cache,sdk 启动后会将对应的 spi flash 空间映射到 cache 空间。

irom0_0_seg :	org = 0x40201010, len = 0xE0000

Tips

  1. 默认放在 iram 中代码最多 32KB, 而放在 flash 中代码可以很大,根据 flash 大小决定。
  2. 操作 flash 相关代码,需放在 iram 中,否则会造成 crash.[DH]
    例如: T 客户在配网过程中,会读写 flash, 如果这时候有不可屏蔽中断(NMI), 调用 RxNodeNum() 函数,如果该函数放在 iram 中,则没问题,如果该函数放在 flash 中,则会 crash。

猜你喜欢

转载自blog.csdn.net/ustccw/article/details/84721188
今日推荐