Question about ESP32 heap size?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Question about ESP32 heap size?

Post by bulletmark » Mon Sep 13, 2021 3:50 am

When I download and flash the generic 1.17 firmware from the website, I get a 111169 byte heap size:

Code: Select all

 >>> micropython.mem_info()
stack: 704 out of 15360
GC: total: 111168, used: 1120, free: 110048
 No. of 1-blocks: 15, 2-blocks: 9, max blk sz: 18, max free sz: 6865
However, when I build and flash a generic image from current source, I only get a 64000 byte heap size:

Code: Select all

>>> micropython.mem_info()
stack: 704 out of 15360
GC: total: 64000, used: 1040, free: 62960
 No. of 1-blocks: 12, 2-blocks: 8, max blk sz: 18, max free sz: 3929
Can somebody please explain this and how to fix it?

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

Re: Question about ESP32 heap size?

Post by Roberthh » Mon Sep 13, 2021 8:45 am

I've seen the same issue. The difference is related to the esp-idf version when building. Using v4.2 I get > 100k heap, using v4.3-beta1 I get ~64k heap. So it looks as if the binaries from the web site are built with esp-if v4.2.

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

Re: Question about ESP32 heap size?

Post by Roberthh » Mon Sep 13, 2021 8:49 am

Using esp-idf v4.3-dev also brings back >100k heap.

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Question about ESP32 heap size?

Post by bulletmark » Mon Sep 13, 2021 10:31 pm

I had discounted the thought I had about not using v4.2 because I couldn't imagine it breaking something so fundamental. Just seemed like a configuration error. However you are right, that was the issue! Thanks for your help Robert.

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Question about ESP32 heap size?

Post by bulletmark » Wed Oct 06, 2021 7:25 am

Robert, or anybody?

Does anybody know why this happens? i.e using any recent version of esp-idf (i.e. v4.3 and later) gives a small heap size of 64 kB instead of the normal 128 kB? I am seeing a very weird UART bug whenever I build with any v4.2 version but that does not occur if I build with v4.3 or master. So it seems I require the later esp-idf version but this damn heap size reduction problem is inhibiting me from using it.

Edit: should make it clear that v4.3-dev which Robert mentions above works, is actually a very old tag (2020-May-20), much older than v4.2 (2020-Dec-04) so that is why I guess it does not have this heap issue, but it has the UART issue. All other v4.3.* versions are later than v4.2.

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Question about ESP32 heap size?

Post by bulletmark » Wed Oct 06, 2021 10:55 pm

ok, I have worked out a solution although I really would like an understanding. In making my last post here I had to look through the various esp-idf version tags and noticed a tag v4.2.2 which was made relatively recently (2021-Jun-16). So I used that version and built the latest master of MicroPython and that combination is the only one I found that works, i.e. does not have the small heap and does not have the UART bug.

tangerino
Posts: 17
Joined: Sun Jul 25, 2021 8:34 am

Re: Question about ESP32 heap size?

Post by tangerino » Sun Oct 24, 2021 8:57 am

Same problem here.
If I compile the original code I get 100K but if I change anything I get 60K
And the version get a 'dirty' word. Is this kind of a debug mode?
Both were compiled with 'release/v4.4'

Code: Select all

MicroPython v1.17-93-g7e62c9707 on 2021-10-23; ESP32 module with ESP32
Type "help()" for more information.
>>> import gc
>>> gc.mem_free()
101680
>>> 

Code: Select all

MicroPython v1.17-dirty on 2021-10-24; ESP32 module with ESP32
Type "help()" for more information.
>>> import gc
>>> gc.mem_free()
54544
>>> 

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Question about ESP32 heap size?

Post by bulletmark » Sun Oct 24, 2021 9:46 am

tangerino wrote:
Sun Oct 24, 2021 8:57 am
Same problem here.
If I compile the original code I get 100K but if I change anything I get 60K
Actually, you are describing the problem differently though. I found that if I built the source (modified or not) with any esp-edf 4.2 version then I got a 128K heap, but if I used any later esp-idf version (i.e. greater than 4.3), then I got a 64K heap. You are saying that you only get the smaller heap if you "change anything". When I built the generic master branch (or 1.17 tag) clean source with esp-idf 4.4-dev I still got the smaller heap.

What are you changing? The "dirty" tag is not significant. That is just a tag added automatically by git when it sees the source directory has been changed.

tangerino
Posts: 17
Joined: Sun Jul 25, 2021 8:34 am

Re: Question about ESP32 heap size?

Post by tangerino » Mon Oct 25, 2021 9:02 am

Fair enough. I'll redo my tests and post back here.
Meanwhile, what is the 'official' esp-idf version to use to compile MP?
I see many combinations and some raises weird errors.
I'd like to use the latest esp tools possible to avoid to bring old bugs to MP and at the same time newer versions seems to not compile.

Thank you

bulletmark
Posts: 59
Joined: Mon Mar 29, 2021 1:36 am
Location: Brisbane Australia

Re: Question about ESP32 heap size?

Post by bulletmark » Mon Oct 25, 2021 10:46 am

tangerino wrote:
Mon Oct 25, 2021 9:02 am
Meanwhile, what is the 'official' esp-idf version to use to compile MP?
It's clearly stated in the ports/esp32/README.md file where is says "Currently MicroPython supports v4.0.2, v4.1.1 and v4.2, although other IDF v4 versions may also work". But as I say above, those versions do not work for me - they get the correct heap size but have a bad UART bug. The only version which works, i.e. does not have the heap problem and the UART works fine, is v4.2.2.

Post Reply