Chat freely about anything...

User avatar
By murraylang
#62306 Hi All,

I know that the iram1_0_seg overflow problem is an old one, and the solution offered is generally to ensure that all of your functions are declared with the ICACHE_FLASH_ATTR. I have done that, but it is of no consequence because all of that segment, and more, is occupied by libraries.

I should point out that I am using CMake rather than the provided build system because my project is cross-platform, and requires an appropriate source code arrangement. I am using esp-open-sdk, but linking with ESP8266_RTOS_SDK. I have used the FreeRTOS version in an attempt to have some common code with the ESP32 version of my project.

I have a webserver accepting POSTs of JSON to program a robotics-based byte-code interpreter. As well as the network code, it cannot do without the UART, GPIO, PWM or SPI Flash. Some maths is also necessary. So the following libraries are linked (with -nostdlib option):
gcc m main driver hal ssc freertos json pwm net80211 wpa lwip pp phy crypto c

When I got the iram1_0_seg overflow error I used a map file to see what was gobbling up the Flash cache RAM. It turns out that while iram1_0_seg is declared thus...
Name Origin Length
...
iram1_0_seg 0x0000000040100000 0x0000000000008000
...
...it's all library code until 0x000000004010ae93, at which point my code starts. That's 0xae93-0x8000 = 0x2e93 (=11923) bytes of overflow before I even get a look in. I tried the gcc -Os option, but obviously that was futile.

So, where does the problem reside? Have I missed some setting that will make this problem go away? Am I expecting too much of the ESP8266? Something is not right.

Cheers,
Murray
User avatar
By murraylang
#62334 OK,
Looking at the map file, I noticed that there were a lot of functions weren't being called - dead code. So I tried the settings described @ https://gcc.gnu.org/ml/gcc-help/2003-08/msg00128.html to remove dead code. That is, I added...
Code: Select all-fdata-sections -ffunction-sections

...to the compiler flags and...
Code: Select all-Wl,--gc-sections

...for the linker (note no space between the "-Wl," and "--gc-sections").

The good news is that there was a dramatic reduction in the memory used. The bad news for me is that it wasn't enough. Now the libraries exactly fill the iram1_0_seg segment and the 4597 bytes remaining overflow is all mine. Still, I am now optimistic that I can get everything to fit by getting rid of the FreeRTOS calls (and any common code between the ESP8266 and ESP32 versions of my code!)

I don't know if these compiler/linker options render the ESP8266 binaries unusable for some reason because I haven't made it through the entire build/upload process yet. I will post my results when they are clear, because I have seen a lot of questions on the web about this overflow problem, and this could solve the issue for a lot of people.

Then again, if these options are already used in the standard ESP8266 makefile system then nothing will be gained.

Regards,
Murray
User avatar
By murraylang
#62434 I can confirm that the compiler and linker options described above for removing dead code do not break the binary, and that my program built this way runs OK (so far!)

(I hope I haven't posted this twice - I had a connection dropout)

Murray