ESP8266: What can I do to overcome “section `.text

2019-07-20 02:49发布

问题:

What are general measures against the .text region not fitting into "iram1_0_seg" when linking for the ESP8266 using the xtensa GCC based toolchain?

I guess that the ESP8266s RAM is not big enough to hold certain functions. However, what can I do to move as many functions into flash as possible?

Here is an example of what the linker returns:

/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc  -I/home/user/git/esp-open-sdk/sdk/include -I/home/user/git/esp-open-sdk/sdk/include/json -I/home/user/git/mart3/src/RTMain/ESP8266TargetGroup -Os -D__ESP8266__ -std=c99 -pedantic -Wall -Wpointer-arith -pipe -Wno-unused-parameter -Wno-unused-variable -Os -g -O2 -Wpointer-arith -Wundef -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -ffunction-sections -fdata-sections  -L/home/user/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/tools/sdk/lib -L/home/user/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/tools/sdk/ld -Teagle.flash.512k0.ld -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--gc-sections src/code/CMakeFiles/FX6CodeObj.dir/FX6Generated/src-gen/fxfu___program1.c.obj src/code/CMakeFiles/FX6CodeObj.dir/FX6Generated/src/emptyHello/fxfu___helloart.c.obj src/code/CMakeFiles/FX6CodeObj.dir/FXStd/FXRTMain.c.obj src/code/CMakeFiles/FX6CodeObj.dir/FXStd/NamedList.c.obj  -o src/ARTApp/ARTApp.out  -Wl,--start-group src/ART/libART.a -lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig -lwps -lcrypto -laxtls -Wl,--end-group
/home/user/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: src/ARTApp/ARTApp.out section `.text' will not fit in region `iram1_0_seg'
collect2: error: ld returned 1 exit status

回答1:

I don't know about Arduino but if you were to program using the Espressif libraries found here https://github.com/esp8266/esp8266-wiki/raw/master/sdk/ then they have a lot of Macros for things such as that.

As an example the "main" of the ESP is put into flash using the following line.

void ICACHE_FLASH_ATTR user_init(){

If you trace the ICACHE... command you will find this define

#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text")))

If you then look through how espressif sets up the memory sections https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map .irom0.text is labelled as the flash memory. Basically anything with the ICACHE... command is loaded into flash memory anything without is not.

Again not sure how to translate this to Arduino code but it might be time to move away from the Arduino libraries if you are running out of flash space. You didn't specify which ESP breakout you are using and my mind may be playing tricks on me but I believe the ESP12-e uses a newer chip which has more flash memory then say the ESP01, just another option.