What is maximum valid heap size

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Posts: 40
Joined: Sun Oct 29, 2017 5:14 pm

What is maximum valid heap size

Post by manseekingknowledge » Fri Aug 02, 2019 7:41 am

main.c has this line:

Code: Select all

STATIC char heap[38 * 1024];
I've slowly been increasing this in an effort to process larger strings. I've seen some behavior I don't understand and I'm hoping someone can enlighten me.

When I have the ESP running in station mode I'm able to have the heap set to 47KB and things seem mostly stable. I do get a random reset which I asked about here, but I'm not sure if that is related or not.

When I have the ESP running as an AP I'm only able to have the heap set to 43KB before it becomes unstable. In this situation I don't even have any other code running. The only thing I've done is configure the AP. So this is confusing to me.

What is the max heap size that can be specified in main.c? Is disabling features in mpconfigport.h the best (only?) way to allow the heap size to be increased?

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

Re: What is maximum valid heap size

Post by jimmo » Fri Aug 02, 2019 12:49 pm

I'm fairly sure the heap is fine tuned to match the available RAM of the target device, leaving enough space for stack, data, bss, etc. I'm less familiar with the non-STM32 ports (i.e. ESP*) which use an rtos.

But I suspect the issues you're seeing are memory corruption (stack and bss) by overrunning the heap.

Disabling features in mpconfigport won't likely help very much because features mostly take ROM (i.e. code space), and only use RAM when you actually call them from MicroPython. (There are a few exceptions to this, i.e. static buffers etc).

Unfortunately the ESP8266 just doesn't have that much RAM available for the heap.

Post Reply