As my project grew, I was constantly hitting the RAM limit of the esp8266. Using frozen modules wasn't enough anymore so I started searching and getting "creative".
This are ways I've found to maximise the available RAM. Feel free to comment and add or criticize the methods and point out the dangers.
I thought it would be nice to have an entry about this on the forum, so it is easier to find.
(Maybe it is somewhere else but I did not find a good summary).
1) Disable the filesystem
Disabling the filesystem by commenting out the filesystem initialization in the _boot.py made an additional ~4kB of RAM usable.
Of course you won't be able to upload, write or read any files anymore. Everything has to be frozen into the firmware.
Code: Select all
"""
from flashbdev import bdev
try:
if bdev:
uos.mount(bdev, '/')
except OSError:
import inisetup
inisetup.setup()
"""
This is admittedly more like an unsafe hack but in combination with 1) I was able to increase it to 44 * 1024B without any problem.
If you increase this too much, allocation can fail or the esp might be stuck rebooting.
Code: Select all
STATIC char heap[36 * 1024];
If not all your modules are frozen bytecode you can store qstr in flash according to this http://docs.micropython.org/en/latest/p ... ained.html.
The first 2 methods made ~12kB of RAM available, which already is quite an impressive amount making development a lot easier.
The 3rd does not apply do me as all my modules are part of the firmware as frozen bytecode.
(Tested with uPy 1.9.4 running a project of mine)