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

User avatar
By MikeyMoMo
#72122 I have a rather large program but it only claims to take up about 300K of memory. But if I add just one more line it starts putting out odd error messages or if it compiles, it does not operate properly. The program is too large to load here but I will show what to do to see the memory blow. Please get the program from ILikeTheInternet.com. It is the WeMoWX Master code and is in a ZIP file.

Code: Select allSketch uses 320757 bytes (30%) of program storage space. Maximum is 1044464 bytes.
Global variables use 51176 bytes (62%) of dynamic memory, leaving 30744 bytes for local variables. Maximum is 81920 bytes.

At line 1132, you will find the SendLogOK routine. This is copied and modified code and is perfectly valid.

If you uncomment line 1136, an erroneous error appears saying that a routine is not defined yet it is defined and used all over the program. Here is the line to uncomment:

Code: Select all//  AppendAndSendHTML("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n", true, false);

AppendAndSendHTML is used multiple places and works just fine but when this line is uncommented, it claims it is not defined thus:

Code: Select all'AppendAndSendHTML' was not declared in this scope

What is causing the compiler to suddenly believe that this routine is not there?

I have had problems, previously, when I got much over 60% usage of dynamic memory. I have put everything that I can into F macros and that saved some space. Some stuff won't go into them. Something about not having a helper. Not sure what that is about but there is not a lot of it, anyway. But I cannot imagine why the compiler would care, anyway, about "too much" dynamic memory being used.

All help and pointers on this appreciated. This error ends project development until it is solved.
User avatar
By McChubby007
#72130 There is RAM put aside for non-user code, I seem to recall about 32k, which is close to the fiqures you quote on free ram. I may have got confused and/or forgotten this stuff as it is from very long ago, but you can be sure that not all ram is available for your use, and also wifi/ip etc and strings all consume ram as you use them.
It might be worth looking at the details of the memory map to see.
User avatar
By MikeyMoMo
#72136
McChubby007 wrote:It might be worth looking at the details of the memory map to see.

Is there a tool for displaying a specific memory map of my code? I have not found such by Google searching.

I am also seeing random deaths or parts will start to be missing on the display. When vital parts go missing, it dies. Non-vital parts just cause the display to lose lines.

It could well be this free memory problem you mentioned. I just can't imagine why the compiler is complaining. I will try to catch a dump, if any, when it hangs. So far, I have not been able to get one. It likes to crash while I am not looking. The cussedness of inanimate objects! Sounds like a good book title...

I am going to try my best to reduce the memory needed. I already have but will keep plugging away at it. Since I have so much free RAM, I really wish I could dedicate some of it to this use but I expect that is impossible. It does seem like there is an invisible line at about 32K that I have crossed and the project is now unstable. Thanks for that thought. Will run with it as far as I can.

Mike
User avatar
By McChubby007
#72140 I just googled espressif's site, and this might help understanding :

There are no individual limits for the sizes of .data, .rodata and .bss (but see caveat below). The ESP8266 has 80K of User Ram which is occupied by .data, .rodata, .bss, the stack and the heap. Basically, the space represented by (80K - sizeof(.data) - sizeof(.rodata) - sizeof(.bss)) is used by the heap growing from one end and the stack growing from the other end. If the heap and stack collide bad things will happen (probably an exception, eventually, and a reboot).

The caveat that I mentioned is that the .data and .rodata sections, along with the .text section (itself limited to 32K) must fit in the first 64K of Flash. The sizes of each of these sections is rounded up to an integral multiple of 4 bytes and an additional 8 bytes of overhead are added for each section plus an additional 8 bytes of overhead. Finally, space for the checksum is added (between 1 and 16 bytes) so that the overall size is an integral multiple of 16 bytes. The total of all that must be 64K or less. The image containing all of this data is often called app.v6.flash.bin but the name itself is not important.

From : http://bbs.espressif.com/viewtopic.php?t=1108

It may be the compiler plus linker script has encountered the limit and hence caused the error you see. I'm definitely not clear on this, never seen myself, but it 'feels' like you have exceeded some threshold. Definitely chop out some data and see what effects it has.