what a min free memory amount for stable work on esp8266 ?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
VladVons
Posts: 43
Joined: Sun Feb 12, 2017 6:49 pm
Location: Ukraine

what a min free memory amount for stable work on esp8266 ?

Post by VladVons » Wed Feb 26, 2020 9:25 pm

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 :)

User avatar
Roberthh
Posts: 1889
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: what a min free memory amount for stable work on esp8266 ?

Post by Roberthh » Thu Feb 27, 2020 4:52 am

You should consider freezing you Python scripts into the flash. Then you will have that space available again on the heap.

VladVons
Posts: 43
Joined: Sun Feb 12, 2017 6:49 pm
Location: Ukraine

Re: what a min free memory amount for stable work on esp8266 ?

Post by VladVons » Thu Feb 27, 2020 5:25 am

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:

Code: Select all

mpy-cross Inc/NetHttp.py -o Inc/NetHttp.mpy
....
....
ampy --port /dev/ttyUSB0 --baud 115200 put Inc
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

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.

User avatar
jimmo
Posts: 1440
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: what a min free memory amount for stable work on esp8266 ?

Post by jimmo » Thu Feb 27, 2020 6:26 am

VladVons wrote:
Thu Feb 27, 2020 5:25 am
In both cases (*.py and *.mpy) the free memory is the same - 12k
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
VladVons wrote:
Thu Feb 27, 2020 5:25 am
What you mean saying "freezing your Python scripts into the flash" ?
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).

Post Reply