Help nailing down soft OS memory issues on the ESP32-S3 (SD and WiFi don't work consistently, framebuffer hates them.) #15194
Replies: 3 comments 10 replies
-
Hi, what kind of errors do you get? I maybe have similar errors, I use ans ESP32-S3 Wroom with 8MB Flash and 2MB SPIRAM and get often ESP-IDF errors like: MPY version : v1.23.0 on 2024-06-08
I also use a lot of RAM aprox. 600-700Kb. I have some rather big arrays with dicts in it and I have seen that sometimes the data gets corrupted. First i thought it happened because of interrupts but i rewrote everything to async tasks. But the errors persisted. So my guess is also that there is a memory issue and/or ESP-IDF Issue. My next step is to try to recompile it with different version of the ESP-IDF currently I use v5.2. |
Beta Was this translation helpful? Give feedback.
-
Have you read this doc? It describes well established techniques for minimising RAM fragmentation which I suspect may be at the root of your problem. |
Beta Was this translation helpful? Give feedback.
-
Can these ESP-IDF Errors, also be associated with RAM/Heap fragmentation? Or are these all ENOMEM errors?
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
TLDR: Launcher program uses WiFi, SDcard, and framebuffer simultaniously, neither SDCard or WiFi work. Without a framebuffer they work. With a quarter sized framebuffer they don't work. Weird janky larger-than-quater-sized framebuffer works, but I hate it. Please help me make quarter framebuffer work <3
I'm developing a project for the ESP32-S3 (with no PSRAM, so 512kb RAM total.) and I've been struggling with odd, 'soft' memory issues for a few months now. Some changes I make improve the issues, or make them worse, but I'm struggling to fully understand why, and I would really appreciate some help if anyone is willing to offer it!
Description of the Project:
It's a simple MicroPython app switcher I'm calling MicroHydra.
It's designed for the M5Stack Cardputer (I'd like to expand it for multi-platform support, but that's only tangential to this issue), with some convenient 'OS-like' features builtin.
One major design choice that has been causing particular problems, is that I decided the project should run both as a plain ".py" micropython project, as well as a frozen firmware. Compiling the modules makes all issues go away, so I admit I'm tempted to do away with this self-imposed restriction. However, a lot of users of the software tell me they are using the .py version so they can poke around and see what's going on/makes changes on the fly, which is what's currently stopping me from abandoning that goal.
Description of the issues:
Any time too much memory is used, the WiFi and SDcard modules start misbehaving in inconsistent ways.
Specifically, using a framebuffer, the sound modules, a font module, an SDCard, and WLAN causes the WLAN modules to give OS-Memory errors, or causes either the SDcard, or WLAN, or both, to give some various non-specific OS-errors. These issues specifically pop up in the main launcher.py program, which is designed to sync the clock using WiFi, and find apps on the SDcard.
When I say the issues are "inconsistent" or hard to pin down, I mean it's really hard to tell what will make the issues get better or worse. Sometimes it seems like drastically decreasing the memory usage does not fix the issues, and sometimes increasing memory usage does not make it worse, and I can't tell why.
Restarting the device, or hard power cycling it, can also change the behaviour.
I've rewritten the launcher quite a few times in this process.
I suspect this has something to do with the way the ESP32 port shares memory with ESP-IDF, but beyond that I have no clue what's happening under the surface.
What I've done about
The issues go away entirely if I do not try to use a framebuffer for the display, however the graphics quality suffers quite a bit. (A full framebuffer for the display is 240 * 135 * 2 bytes).
I made an alternate version of the "launcher" app which uses a custom, non-framebuffer version of the display driver, but instead just stored the moving elements in their own framebuffers, and that worked without issue, however it was really janky code that couldn't really be reused, so I wanted to try some other solution.
I completely rewrote the display driver to use a quarter-sized framebuffer (240 * 135 / 2 bytes) which is converted as it's sent to the display. In theory, this framebuffer should be smaller than the partial framebuffers used beforehand, but it doesn't seem to have worked like that, and the WiFi/SDcard issues are back.
Running
micropython.mem_info(1)
is interesting, but I still struggle to tell exactly what to make of it most of the time. There are a lot of densely packed objects in the memory visualization, but also some spaces. Heap fragmentation may or may not be the culprit; I can't really tell.Regardless, the memory is never anywhere near 'used up', and I think that's because it's the non-micropython stuff (as in, the esp-idf components) that're running out of space.
What I'm asking for help with
Basically, I'm just asking for any help. If anyone is willing to skim over my code to spot any obvious point where memory issues could be worsened, I'd be super appreciative.
If anyone has additional troubleshooting steps or insight on the topic to offer, I could benefit from that too, I think.
If you have any other form of help to offer, I'll take it.
I would just really like to get the launcher to a point where it's stable with the new display driver, if that's even possible :)
Thanks for reading, and thanks in advance for any help! 😊
Beta Was this translation helpful? Give feedback.
All reactions