- Mon Jul 18, 2016 1:44 am
#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