In pure micropython ver 1.12 there is approx 32K of free memory to use.
Earlier versions 1.9 had only 30k free. So thanks micropython team for great job to save 2K. It is a lot!
I have already included asyncio, mqtt, http server, captive DNS, wifi connection, logging, settings saving, queues.
This minimal IoT framework used over 20k now.
Finally i have only 12k free memory after garbage collection - gc.collect()
What is a recommended minimum free memory for a stable work?
I want to estimate my micropython appetite for this chip
what a min free memory amount for stable work on esp8266 ?
Re: what a min free memory amount for stable work on esp8266 ?
You should consider freezing you Python scripts into the flash. Then you will have that space available again on the heap.
Re: what a min free memory amount for stable work on esp8266 ?
All my project sources *.py files is 15K
I compiled *.py files into *.mpy with micropython mpy-cross utility for linux and got 8K of *.mpy
Sent them to esp8266 flash with a command:
In both cases (*.py and *.mpy) the free RAM memory is the same - 12k
In addition i splited project into little files and import modules with certain class name
from MODULE import CLASS
What you mean saying "freezing your Python scripts into the flash" ?
I compiled *.py files into *.mpy with micropython mpy-cross utility for linux and got 8K of *.mpy
Sent them to esp8266 flash with a command:
Code: Select all
mpy-cross Inc/NetHttp.py -o Inc/NetHttp.mpy
....
....
ampy --port /dev/ttyUSB0 --baud 115200 put Inc
In addition i splited project into little files and import modules with certain class name
from MODULE import CLASS
Code: Select all
import gc
from Inc.NetHttp import THttpServer, THttpApi
gc.collect()
print('mem_free Led', gc.mem_free())
What you mean saying "freezing your Python scripts into the flash" ?
Last edited by VladVons on Thu Feb 27, 2020 7:56 am, edited 2 times in total.
Re: what a min free memory amount for stable work on esp8266 ?
Yep, you'll have saved space on the filesystem (flash), but the RAM usage is the same because the bytecode still has to be loaded into RAM.
Here's a recent explanation of this: viewtopic.php?f=2&t=7830#p44693
See the rest of that linked thread. Basically you include the .mpy into the firmware (rather than putting it in the filesystem) such that it can be directly memory mapped and executed from flash.
On ESP8266, the very simplest way to do this is to just add your code to the ports/esp8266/modules directory before building the firmware. (Search the forum for how to do build the ESP8266 firmware with docker -- e.g. viewtopic.php?f=15&t=7136#p40603)
The better answer is that you at a minimum you just need to write a manifest.py (and build the firmware), but the best way to do this is to define your own board config. see ports/esp32/boards/TINYPICO for a good example. (That's for ESP8266, but the idea is the same on ESP8266 and STM32).