force IRAM_ATTR ? / default to IRAM_ATTR

djamu-
Posts: 1
Joined: Sun Apr 04, 2021 11:56 am

force IRAM_ATTR ? / default to IRAM_ATTR

Postby djamu- » Sun Apr 04, 2021 12:35 pm

I was wondering if there's an option to default to IRAM_ATTR, to make everything load into IRAM. ( or a global linker option ?)
The reason why I'm asking and forgive me my ignorance, is that by far the majority of projects will fit into ram, and will quite a bit faster for those that don't fit into the cache.
Cache misses are a problem when a tight timing is necessary. I mean much faster then the 1kHz RTOS tick.

It took me a few days to figure out the issue with cache misses the first time I wrote running code that exceeded the cache size, resulting in jittery behavior, which I regularly fix by adding IRAM_ATTR to any function except setup code.

Currently I'm porting a large project to esp32 and adding IRAM_ATTR everywhere is quite tedious.

My question is probably a feature request, I propose making IRAM_ATTR the default and to add either a NOIRAM_ATTR / FLASH_ATTR attribute.

By far the majority of projects will fit into IRAM, and for those that don't, the new attribute will run code that doesn't need to be called often or once, like setup code or static webpages for example onto flash.
As a matter of fact I find it quite strange that it's not the default behavior, it's like writing an app for PC and telling it > don't use ram for code, run it from HD, which everybody knows is a terrible idea.

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: force IRAM_ATTR ? / default to IRAM_ATTR

Postby ESP_Sprite » Mon Apr 05, 2021 2:47 am

By far the majority of projects will fit into IRAM
That is a very strange assertion. A very simple example (esp-idf/examples/wifi/getting_started/station/) when you run 'esp.py size' 'idf.py size' on it will give you the following:

Code: Select all

 DRAM .data size:   16632 bytes
 DRAM .bss  size:   15504 bytes
Used static DRAM:   32136 bytes ( 148600 available, 17.8% used)
Used static IRAM:   88469 bytes (  42603 available, 67.5% used)
      Flash code:  474391 bytes
    Flash rodata:   92368 bytes
Total image size:~ 671860 bytes (.bin may be padded larger)
Disregarding everything else, the code in this (very simple) example already is (88469+474391=)549KiB. That's more memory than the ESP32 has *in total*, and that's ignoring the fact that only a fraction of that is (usable as) IRAM.

axellin
Posts: 200
Joined: Mon Sep 17, 2018 9:09 am

Re: force IRAM_ATTR ? / default to IRAM_ATTR

Postby axellin » Tue Apr 06, 2021 6:15 am

ESP_Sprite wrote:
Mon Apr 05, 2021 2:47 am
By far the majority of projects will fit into IRAM
That is a very strange assertion. A very simple example (esp-idf/examples/wifi/getting_started/station/) when you run 'esp.py size' on it will give you the following:
I think you mean 'idf.py size'.

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: force IRAM_ATTR ? / default to IRAM_ATTR

Postby ESP_Sprite » Tue Apr 06, 2021 11:08 am

axellin wrote:
Tue Apr 06, 2021 6:15 am
I think you mean 'idf.py size'.

You are correct, thanks, I changed it.

Who is online

Users browsing this forum: No registered users and 111 guests