← index #9921PR #7963
Related · medium · value 4.109
QUERY · ISSUE

The memory of ESP32S3 is too large when using microython

openby Zhengqinze05opened 2022-11-11updated 2022-11-17
enhancement

I use the board of the ESP32. When I turn on microython, there will be more than 100 k of internal memory consumption. I have other functions to add. This more than 100 k of memory will cause me to run out of memory. What can I do to reduce the memory consumption of esp32 when using microython

CANDIDATE · PULL REQUEST

ESP32: Set maximum heap size in mpconfigport.h.

closedby glenn20opened 2021-11-03updated 2023-05-25
port-esp32

The problem: Too much memory allocated to heap on ESP32S2.

Micropython allocates too much RAM to the microython heap on ESP32S2 leaving insufficient RAM available for other IDF functions (causing panics in networking and espnow code). On the ESP32 101563 bytes is allocated to the heap by default. On the ESP32S2 this is ~120kB.

NOTE: when this this bug is resolved the default heap size on ESP32S2 will increase to ~160kB.

This fix: Set a maximum allowed value for the heap size.

Micropython currently allocates the largest available memory block to the micropython heap. This PR allows the maximum allowed heap size to be #defined as MICROPY_HEAP_SIZE_MAX. The default value is set to 104000 in mpconfigport.h and can be overridden in the board definition files: mpconfigboard.h.

With this default setting the espnow and wireless functions no longer generate panics on the ESP32S2.

Other approaches

https://github.com/micropython/micropython/pull/6785 allows the heap size to be set at run time (from NVS variables) which is a useful and powerful feature.

Nonetheless, it should be possible to deterministically set a reasonable maximum for the heap size"out of the box" in a compiled image that allows normal operation of an ESP32XX chip irregardless of exactly how the memory on the chip is fragmented.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied