"ICACHE_FLASH_ATTR" macro

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

"ICACHE_FLASH_ATTR" macro

Postby ESP_Faye » Wed Apr 15, 2015 8:08 pm

:!: :!: :!:

Q :
What is the purpose of the ICACHE_FLASH_ATTR macro in ESP8266_NONOS_SDK ? I see that it depends on ICACHE_FLASH, but I don’t know when that symbol should be defined.
When is it necessary to include it?
A :
For ESP8266_NONOS_SDK
Functions decorated with ICACHE_FLASH_ATTR compile to the IROM section; for such functions, the CPU execute the codes in the instruction cache.
Conversely, functions without ICACHE_FLASH_ATTR load into IRAM when the system starts. Hence, using the ICACHE_FLASH_ATTR helps reduce the IRAM requirements.
Do not use ICACHE_FLASH_ATTR-functions in interrupt handler, as it may conflict with the flash R/W operations.

For ESP8266_RTOS_SDK
In this SDK, we have made execution from I-cache to be the default mode. Hence, only functions that need to run from IRAM are to be decorated with IRAM_ATTR.
In another words, functions that are to execute from the I-cache, do not need to be decorated with ICACHE_FLASH_ATTR. They inherit this characteristic by default, unless they are decorated with IRAM_ATTR.

问:
为什么 ESP8266_NONOS_SDK 中有的函数前面添加了 "ICACHE_FLASH_ATTR" 宏?我们应该如何使用它呢?
答:
对于 ESP8266_NONOS_SDK
添加了 "ICACHE_FLASH_ATTR" 宏的函数,将存放在 IROM 中,CPU 仅在调用到它们的时候,将它们读到 cache 中运行;
没有添加 "ICACHE_FLASH_ATTR" 宏的函数,将在一开始上电运行时,就加载到 IRAM 中运行;
由于空间有限,我们无法将所有代码都一次性加载到 IRAM 中运行,因此在大部分函数前添加 "ICACHE_FLASH_ATTR" 宏,放在 IROM 中。
请注意,不要在中断处理函数中调用带有 "ICACHE_FLASH_ATTR" 宏的函数,否则将引起异常。

对于 ESP8266_RTOS_SDK
函数默认存放在 IROM 中,无需再添加"ICACHE_FLASH_ATTR" 宏。
中断处理函数也可以定义在 IROM 中。
如果开发者需要将一些频繁调用的函数定义在 IRAM 中,在函数前添加 “IRAM_ATTR” 宏即可。

Thanks for your intereset in ESP8266 !

Who is online

Users browsing this forum: Baidu [Spider] and 0 guests