Difference 'instruction RAM' and 'variables RAM' ?

arjen1
Posts: 28
Joined: Sun Aug 06, 2023 4:48 pm

Difference 'instruction RAM' and 'variables RAM' ?

Postby arjen1 » Mon Jan 20, 2025 12:30 pm

Dear forum

Till now I never worried too much about RAM size in my projects, but today I noticed this after compiling a rather large program:

Code: Select all

. Variables and constants in RAM (global, static), used 48480 / 80192 bytes (60%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ DATA     1724     initialized variables
╠══ RODATA   13932    constants       
╚══ BSS      32824    zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 61499 / 65536 bytes (93%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ ICACHE   32768    reserved space for flash instruction cache
╚══ IRAM     28731    code in IRAM    
. Code in flash (default, ICACHE_FLASH_ATTR), used 409604 / 1048576 bytes (39%)
║   SEGMENT  BYTES    DESCRIPTION
╚══ IROM     409604   code in flash  
Instruction RAM is 93% occupied.

I tried to put some Serial.print statements in Flash with the 'F' macro. The 1st number -Variables and constants in RAM- lowered, but nothing happens to the Instruction RAM number.

So the questions are:
1 What is Instruction RAM?
2 what is the difference between the 2 RAM?
3 Should I worry that it is 93% upon compilation?
4 What to do to lower this number?

Thanks.

It is an ESP8266 NodeMCU ESP12F
Using arduino IDE 2.3.4

Kouzerumatsukite
Posts: 1
Joined: Wed May 14, 2025 11:45 pm

Re: Difference 'instruction RAM' and 'variables RAM' ?

Postby Kouzerumatsukite » Thu May 15, 2025 12:00 am

Instruction RAM (IRAM) is used to execute program code that has been cached from FLASH, while variable RAM (data RAM) is dedicated to storing data. IRAM and the instruction cache (ICACHE) do not increase or decrease during program execution, and they are entirely separate from variable RAM.

By default, the SDK compiles the firmware in a way that uses around 28KB of IRAM, which cannot be reduced. This leaves only about 3–4KB of IRAM available for your own functions.

I use IRAM to store functions that are critical for interrupts—such as routines for flushing data to a HUB-15 LED matrix. You can't simply use leftover IRAM for data storage; that's what variable RAM is for, not IRAM.

Don't worry if your IRAM seems heavily used—this is normal for most projects.

Who is online

Users browsing this forum: PerplexityBot and 1 guest