-->
Page 39 of 55

Re: New Working GCC for ESP8266

PostPosted: Fri Feb 13, 2015 5:52 pm
by bojanpotocnik
joostn wrote:
jcmvbkbc wrote:This script produces ELF as expected, but still doesn't work when I flash it. Maybe I'm doing something wrong as well...

I found a way to get all code in Flash by default! Modify the linker script as follows:
Code: Select all .text : ALIGN(4)
  {
...
/*    *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) */
    *(.literal .text .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
...
  } >iram1_0_seg :iram1_0_phdr

  .irom0.text : ALIGN(4)
  {
    _irom0_text_start = ABSOLUTE(.);
    *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
    *(.literal.* .text.*)
    _irom0_text_end = ABSOLUTE(.);
  } >irom0_0_seg :irom0_0_phdr

So I've moved the .text.* and .literal.* to the irom0 section. I've added '-ffunction-sections -fdata-sections' to the gcc compiler flags, which causes my own code to go into .text.* instead of .text. The startup code is in .text so it will end up in the right section.

Thank you for that great tip! I was searching for solutions for days now and it is finally working. I believe there is slight effect on the performance because my debug prints (which were all nice and aligned before) are all kinda messed up.
One question - ICACHE_FLASH_ATTR and ICACHE_RODATA_ATTR does not have sense now as all goes to the irom0_0_seg section automatically. But what if I want to move something back, as example ISR (UART) functions? Will macro like this help? :
#define ICACHE_IRAM_ATTR __attribute__((section(".text")))

Just tested - it is working as expected :D But, is it the right section or should I use any other or even define my own?

Re: New Working GCC for ESP8266

PostPosted: Sun Feb 15, 2015 12:30 pm
by joostn
Or you could use this:
__attribute__((section(".iram1.text")))
This would force it into ram regardless of where .text goes.

And yes all interrupt code must go into ram entirely:
http://bbs.espressif.com/viewtopic.php?f=7&t=150

Re: New Working GCC for ESP8266

PostPosted: Sun Feb 15, 2015 12:46 pm
by bojanpotocnik
Hmm, can I be sure that there aren't any ISR functions in the precompiled .a libs from Espressif? I'm careful writing my code and I checked all SDK (Drivers) source files to have proper attributes, but I am afraid that someday my program will hit some function in Espressif libs, which does not have FLASH attribute or my new IRAM attribute and the program will crash :? And I think that now when I get "Fatal exception", program is stopped at that point rather than chip being restarted (but I think enabling Watchdog should resolve this problem).

Re: New Working GCC for ESP8266

PostPosted: Sun Feb 15, 2015 2:00 pm
by joostn
Should be no problem, Espressif's ISRs are in .text (not .text.*) which still goes to ram.