I have an M5Stack Core2 (AWS) that I'm using for a controller to drive an amplifier.
Last fall I ran into a problem where the 4Relay (Module 13.2) failed. I proved that the hardware wasn't bad by loading in a simple script to exercise the relays. I've been troubleshooting it and ran into 2 issues.
If I compile the project on my Laptop: Arduino IDE 2.3.8, it compiles OK, but the 4Relay board doesn't work, the I2C bus doesn't recognize the Address 0x26 (nor any of the others!).
If I compile the project on a new Desktop, (I recently loaded the everything new, Arduino IDE 2.3.10) It will run the smaller version of the sketch where the 4Relay board works, but my project fails with the error:
"IRAM0 segment data does not fit" & "region 'iram0_0_seg' overflowed by 1324 bytes".
I DO NOT GET THAT error on the IDE 2.3.8.
I tried changing all of the instances of Serial.print("string"); to Serial.print(F("string")); but it made absolutely no difference. Obviously, I don't understand what the "IRAM0" is!
Why does this compile on the older version 2.3.8 (where the 4Relay board doesn't work), and won't compile on 2.3.10 where the 4Relay board & the I2C works?
Is there something in the M5Stack "Partition Scheme" that will allow it to work? I seem to remember playing with this setting sometime in the past...
I suspect that this is not so much about the IDE version but about the version of the board package and possibly versions of the libraries that you use.
You can use the board manager and the library manager to compare the versions on both systems.
You can also enable verbose output during compilation in File → Preferences to see the versions of the board package (first few lines) and the libraries used by your application (near the end of the output).
It's further advisable to set the Warning level in File → Preferences to All if you haven't done so yet; it might reveal something.
Well, what I've found out so far is that it's not the version of the Compiler, but the version of the M5Stack board that's causing the IRAM0 problem.
I tried uninstalling and reinstalling the Module_4RELAY Library, didn't help.
I then uninstalled the M5Stack by M5Stack (was 2.1.3, didn't update!) and reinstalled it and it installed 3.3.7.
Now, BOTH of my installations will allow the Relays to work, but also BOTH give me the IRAM0 Error (1324 bytes). I'm assuming that the newer version it taking up more of the IRAM0, and so I'm supposed to reduce my own usage????
I've been digging into it and found that you can possibly change the Arduino IDE Tools/Flash Size, but it only lists "16MB (128Mb)".
I've tried to change all Serial.print("string"); to Serial.print(F("string)); but that made no difference.
I do have a global structure:
// Keep the fields that are used across functions in AmpState
struct AmpState {
double volts;
int fwdPower;
int refPower;
float swr;
int ampTemp;
int currentBand;
byte hours;
byte minutes;
byte mode;
bool act1_byp0; // Active (1) or Bypass (0) state
int fanOutput; // Amplifier Fan Output speed as read from NANO.
byte rigModel; // 0 = None, 1 = K3, 2 = KX3, 3 = IC-705
};
// Create a global instance
AmpState ampState = { 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, 0 };
but I don't think that removing will give me 1324 bytes!!!
If I remove the BluetoothSerial.h OR the SD.h, it fits. Somewhere along the line the esp32 started grabbing more IRAM0. When I updated to the latest M5Unified, it no longer fit.
I'm having this same problem. I'm using M5Unified 0.2.19 and M5Stack 3.3.8, which my M5AtomS3 uses and working nicely (and 48% full). My M5Core2 (with 16M Flash) isn't getting past those same errors and I've tried all the partition schemes, even the 16MB Flash. I'm using Arduino IDE 2.3.10.
IRAM0 segment data does not fit
region `iram0_0_seg' overflowed by 552 bytes
I can take out full subsections of my code, even the Serial.print statements, and the same overflow stays the same or goes down to 528 bytes overflow. Also the different partition schemes don't change this error. Sure seems to be something strange going on with a library.
I would check linker files. Those are shipped with board support package. These files have descriptions of memory segments and .elf section names. May be it is good idea to compare these files to original linker files from ESP-IDF or from an older installation of Arduino Core
I’ll check linker files. It just seems strange that M5StomS3 works nicely, but Core2 doesn’t. Maybe those linker partitions are not up to date? Even the M5AtomLite compiles and loads, albeit witb 89%.
Ok, looking at those memory.ld files .. that's definitely out of depth for user level changes. The esp32 version (which the core2 seems to be) is definitely smaller, which we know:
You can determine this by checking the board selection Arduino IDE's Tools > Board menu (if the board selection is under Tools > Board > M5Stack or Tools > Board > esp32), or by examining the verbose compilation output (looking at the first lines of the output).
Additionally, which specific version of that platform do you have installed. You can determine this by looking in the Arduino IDE Boards Manager.
I was trying the board: M5Stack 3.3.8 but also have tried M5AtomS3.
The esp32 tools are Arduino IDE 2.3.10.
Any insight on other things to try would be appreciated.
thanks,
FQBN: m5stack:esp32:m5stack_core2 Using board 'm5stack_core2' from platform in folder: /Users/scott/Library/Arduino15/packages/m5stack/hardware/esp32/3.3.8 Using core 'esp32' from platform in folder: /Users/scott/Library/Arduino15/packages/m5stack/hardware/esp32/3.3.8
That's 0_0 vs 0_2. Apparently, each chip variant has both.
esp32$ rg -B 1 -A 1 'iram0_._seg \('
tools/esp32-libs/3.3.10/ld/memory.ld
54- /* IRAM for PRO cpu. Not sure if happy with this, this is MMU area... */
55: iram0_0_seg (RX) : org = 0x40080000, len = 0x20000 + 0x0
56- /* Even though the segment name is iram, it is actually mapped to flash
57- */
58: iram0_2_seg (RX) : org = 0x400D0020, len = 0x330000-0x20
59- /*
tools/esp32s2-libs/3.3.10/ld/memory.ld
46- /* IRAM for CPU.*/
47: iram0_0_seg (RX) : org = (0x40020000 + 0x2000 + 0x2000), len = 0x3FFDE000 - (0x3FFB0000 + 0x2000 + 0x2000)
48- /* Even though the segment name is iram, it is actually mapped to flash
49- */
50: iram0_2_seg (RX) : org = 0x40080020, len = 0x780000-0x20
51- /*
tools/esp32c3-libs/3.3.10/ld/memory.ld
50- /* IRAM for PRO CPU. */
51: iram0_0_seg (RX) : org = (0x4037C000 + 0x4000), len = 0x403CE710 - (0x4037C000 - 0x3FC7C000) - (0x3FC7C000 + 0x4000)
52- /* Flash mapped instruction data */
53: iram0_2_seg (RX) : org = 0x42000020, len = 0x800000-0x20
54- /**
tools/esp32s3-libs/3.3.10/ld/memory.ld
57- /* IRAM for PRO CPU. */
58: iram0_0_seg (RX) : org = (0x40370000 + 0x4000), len = (((0x403CB700 - (0x40378000 - 0x3FC88000)) - 0x3FC88000) + 0x8000 - 0x4000)
59- /* Flash mapped instruction data */
60: iram0_2_seg (RX) : org = 0x42000020, len = 0x800000-0x20
61- /**
The repeated comments says that 0_2 is actually flash. But the OP error is with 0_0. The original ESP32's length is easy enough -- 0x20000 + 0x0 -- but the others are more cryptic
$ readelf -l /home/kenb4/.cache/arduino/sketches/86A48A2F572C707983213B7DF6D73E7F/sketch_aug19a.ino.elf
Elf file type is EXEC (Executable file)
Entry point 0x400819a8
There are 7 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x001020 0x3f400020 0x3f400020 0x10bd8 0x10bd8 RW 0x1000
LOAD 0x000ff0 0x3ff81ff0 0x3ff81ff0 0x00000 0x00010 RW 0x1000
LOAD 0x012b60 0x3ffbdb60 0x3ffbdb60 0x041c1 0x05640 RW 0x1000
LOAD 0x017000 0x40080000 0x40080000 0x1ffff 0x20000 RWE 0x1000
LOAD 0x037020 0x400d0020 0x400d0020 0x1dc08 0x1dc08 R E 0x1000
LOAD 0x055200 0x50000200 0x50000200 0x00020 0x00020 RW 0x1000
LOAD 0x000fe8 0x50001fe8 0x50001fe8 0x00000 0x00018 RW 0x1000
Section to Segment mapping:
Segment Sections...
00 .flash.appdesc .flash.rodata
01 .rtc_fast_reserved
02 .dram0.data .noinit .dram0.bss
03 .iram0.vectors .iram0.text .iram0.text_end
04 .flash.text
05 .rtc.force_slow
06 .rtc_slow_reserved
Reading from the bottom, segment 03 -- the one in the middle -- contains iram0. And on the middle LOAD line, the MemSiz is exactly 0x20000. Increasing the REPEAT_COUNT to "8870"
IRAM0 segment data does not fit.
region `iram0_0_seg' overflowed by 8 bytes
I guess NOP is 2 bytes? When it links successfully with "8869", the sketch size is
Sketch uses 338336 bytes (25%) of program storage space. Maximum is 1310720 bytes.
Global variables use 22076 bytes (6%) of dynamic memory, leaving 305604 bytes for local variables. Maximum is 327680 bytes.
So that reported size -- and therefore the partition scheme -- does not address this specific issue. BTW, the AI says that iram0_0_seg
is allocated for time-critical executable code, low-level handlers, and specific drivers that must run rapidly or function while flash cache operations are suspended
M5Atom -- that's the board you use; there is no Lite-specific one, right?
region `iram0_0_seg' overflowed by 8 bytes
M5Core2
region `iram0_0_seg' overflowed by 4720 bytes
So the M5Atom is equivalent to stock ESP32, while M5Core2 has a bunch more code, even in an empty sketch. The latter has more built-in hardware -- screen, audio, sensors. There could be a bug somewhere marking some of that additional code as IRAM_ATTR
Doing the math, the max filler sketch that fits has
> 8870 - 4720 / 8
8280
Confirmed that with "8280" the segment size with M5Core2 is exactly 0x20000; and for the record, at that size
M5Core2
Sketch uses 346368 bytes (5%) of program storage space. Maximum is 6553600 bytes.
Global variables use 22148 bytes (0%) of dynamic memory, leaving 4499836 bytes for local variables. Maximum is 4521984 bytes.
M5Atom
Sketch uses 333592 bytes (10%) of program storage space. Maximum is 3145728 bytes.
Global variables use 22076 bytes (6%) of dynamic memory, leaving 305604 bytes for local variables. Maximum is 327680 bytes.
the total sketch size difference is 12776 bytes, about 2.7 times the segment size difference.
Switching to esp32 board version 2.0.17, "8870" fits on M5Stack-Core2 with the segment size 0x1fda8; M5Stack-ATOM is 0x1e914. That difference, 5268 bytes, is actually larger, but the total size fits for both.