-->
Page 1 of 2

Hitting a hard limit on code size

PostPosted: Tue Jan 13, 2015 5:39 pm
by hamishcunningham
Hi,

gwizz and I have been hitting a hard limit on code size that triggers chip restart. The problem presents on a chunk of around 8KB.

Probably we're just sucking up all the heap, but I guess it might also be some limitation in how loadfile works -- is this configurable?

To duplicate the problem: https://github.com/hamishcunningham/fishy-wifi/tree/master/code-size-bug

(Copy two files defining a meaningless print function to the ESP; running the shorter one works, but the longer one triggers restart.)

We've verified this on two different modules...

Any ideas?

Cheers

Hamish

Re: Hitting a hard limit on code size

PostPosted: Tue Jan 13, 2015 5:51 pm
by gwizz
I've narrowed the bug down to 137/138 lines for my new olimex dev board.

That's with
Code: Select all> =node.heap()
22968


After restart.

If I clear out my wifi settings then I get some more heap:
Code: Select all> =node.heap()
23400


And now I can get the bug between lines 169/170!

Interestingly, after this my heap is just a little over 8K:
Code: Select all> =node.heap()
8104

Re: Hitting a hard limit on code size

PostPosted: Sat Feb 07, 2015 3:25 am
by jaquinn
I have run into similar sounding issues. They can be really frustrating because a small code change can break what was working code for no obvious reason.

I am still working on this but did find two interesting behaviours:
1. Splitting the source and using DOFILE to load the "split" part helped a lot.
2. The wifi.sta.getap() function seems to consume about 2k of heap.

I have been trying to put together a basic framework in Lua that provides a setup page (with the ESP8266 running as an AP) to get the device attached to the target network and come other configuration specified and then the operational pages (with the ESP8266 running as a client to the target network).

I was not able to have this all in one lua source file without the restart problem but I am having good results with a main.lua (for the operational page), setup.lua (for the setup), common.lua (common functions shared by both and loaded using DOFILE).

Either setup.lua or main.lua are loaded from init.lua using DOFILE based on a GPIO read to check if the device is physically in "setup mode" which makes it more secure even if it is a hack to work around the memory limitation.

Re: Hitting a hard limit on code size

PostPosted: Sun Feb 08, 2015 4:48 pm
by raz123
jaquinn wrote:I have been trying to put together a basic framework in Lua that provides a setup page (with the ESP8266 running as an AP) to get the device attached to the target network and come other configuration specified and then the operational pages (with the ESP8266 running as a client to the target network).


Seen this? https://github.com/hamishcunningham/fis ... ter/joinme