Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By Ravi S Kashi
#46931 Well, there are a lot of guys who have had this issue and have solved this. Apparently, I am not sure which is the right way to handle this and after I decide on the way - how to do it is also not very clear.

There are 2 ways:
1. Change the linker file (len and the address of the iROM segment - to what and how is not clear to me yet.
2. There is also a thread where you can use a non-OTA enabled mode in which you get the space used up for OTA activity for your application at the cost of the OTA feature. How to do this also not clear.
User avatar
By martinayotte
#46933 Understood, but the error you got is not related to the lack of IROM space, but really IRAM.
So, changing the IROM length, even if you don't need OTA, won't fix anything there.

Here are some interesting reading :
http://stackoverflow.com/questions/3450 ... egion-iram
https://github.com/esp8266/Arduino/issues/1582
User avatar
By Ravi S Kashi
#47227 I changed the liker script eagle.app.v6.ld to below, now it links and also works
Code: Select all/* This linker script generated from xt-genldscripts.tpp for LSP . */
/* Linker Script for ld -N */
MEMORY
{
  dport0_0_seg :                        org = 0x3FF00000, len = 0x10
  dram0_0_seg :                         org = 0x3FFE8000, len = 0x14000
  iram1_0_seg :                         org = 0x40100000, len = 0x8000
  irom0_0_seg :                         org = 0x40240000, len = 0x3D000 /*0x3C000*/
}


The build output is as below:
Code: Select all
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000968  3ffe8000  3ffe8000  000000e0  2**4
                  CONTENTS, ALLOC, LOAD, DATA
  1 .rodata       00001d94  3ffe8970  3ffe8970  00000a50  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .bss          00006638  3ffea708  3ffea708  000027e8  2**4
                  ALLOC
  3 .text         0000721a  40100000  40100000  000027e4  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .irom0.text   0003cd54  40240000  40240000  00009a00  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
------------------------------------------------------------------------------
   Section|                   Description| Start (hex)|   End (hex)|Used space
------------------------------------------------------------------------------
      data|        Initialized Data (RAM)|    3FFE8000|    3FFE8968|    2408
    rodata|           ReadOnly Data (RAM)|    3FFE8970|    3FFEA704|    7572
       bss|      Uninitialized Data (RAM)|    3FFEA708|    3FFF0D40|   26168
      text|          Uncached Code (IRAM)|    40100000|    4010721A|   29210
irom0_text|             Cached Code (SPI)|    40240000|    4027CD54|  249172
------------------------------------------------------------------------------
Entry Point : 40100004 call_user_start()
Total Used RAM : 36148
Free RAM : 45772
Free IRam : 3558 or 19942 if 48k IRam
------------------------------------------------------------------------------
Generate 0x00000.bin and 0x40000.bin successully in folder firmware.
0x00000.bin-------->0x00000
0x40000.bin-------->0x40000
Done

ESP-01 does not work - rather fails to load the Application, I can only see the SDK prints
Code: Select all ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 29212, room 16
tail 12
chksum 0x11
ho 0 tail 12 room 4
load 0x3ffe8000, len 2408, room 12
tail 12
chksum 0xf9
ho 0 tail 12 room 4
load 0x3ffe8970, len 7572, room 12
tail 8
chksum 0xe8
csum 0xe8


Amica NodeMCU board works( with the same SW of course), as expected see log below:
Code: Select all ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x40100000, len 29212, room 16
tail 12
chksum 0x11
ho 0 tail 12 room 4
load 0x3ffe8000, len 2408, room 12
tail 12
chksum 0xf9
ho 0 tail 12 room 4
load 0x3ffe8970, len 7572, room 12
tail 8
chksum 0xe8
csum 0xe8
ªµ+ Õ­…-+PUUP´TT
S
load ...
MQTT_InitConnection
MQTT_InitClient

Connecting to SSID: GTD-Labs, Password: password_not_shared
WIFI_INIT

System started ...
mode : sta(18:fe:34:e1:1d:aa)
add if0
f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 2
cnt

connected with GTD-Labs, channel 4
dhcp client start...
STATION_IDLE
STATION_IDLE
ip:192.168.1.101,mask:255.255.255.0,gw:192.168.1.1
TCP: Connect to IP  192.168.1.5:1883
MQTT connect : Insecure Connection
MQTT: Connected to broker 192.168.1.5:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: data received 4 bytes
MQTT: Connected to 192.168.1.5:1883
MQTT: Connected
MQTT: queue subscribe, topic"/mqtt/topic/0", id: 1

What am I missing?
User avatar
By eriksl
#50947 Even with an OTA-enabled image, there is still quite a bit of space (about 200 kbytes on a standard 4 Mbits flash chip), so I don't think you should focus on that. It's quite hard to get the 200 kbytes completely filled with code.

So indeed focus on the IRAM usage. There is only 32 kbytes of IRAM so be very economic with it. Make sure that every function you make (unless it's an interrupt handler), is tagged as "store in IROM" (which means: keep in flash, do not copy to IRAM). You can do that with the ICACHE_FLASH_ATTR magical incantation as already suggested. Put it before every function. I myself find this keyword is very unclear as to what it does exactly, so I added two #defines myself:

#define irom __attribute__((section(".irom0.text")))
#define iram __attribute__((section(".text")))

This allows you to prepend every function with either "irom" or "iram", so you can see very quickly if one escaped your attention.

If your short on DRAM (which isn't that common), you can keep strings in flash using this directive:

#define roflash __attribute__((section(".flash.rodata"))) __attribute__((aligned(sizeof(char*))))

But be aware, they need to be read using chunks of four bytes at a time now, aligned at four bytes as well. So you can't use sprintf etc. I have a couple of functions to achieve that ;)