InfiniTimeOrg / InfiniTime

Firmware for Pinetime smartwatch written in C++ and based on FreeRTOS
GNU General Public License v3.0
2.64k stars 907 forks source link

Heap unification #1709

Closed JF002 closed 1 year ago

JF002 commented 1 year ago

This PR unifies the 3 memory heaps used in InfiniTime (stdlib, LVGL and FreeRTOS) into a single memory space managed by FreeRTOS.

The goals are

According to the memory analysis I've previously done, dynamic memory allocations (which consume heap memory) are done in multiple parts of the code:

LVGL support custom memory manager, so I simply edited the configuration to point the alloc/free functions to FreeRTOS memory manager. For other parts of the code that use malloc(), delete(), new(), free(), I defined custom implementations of malloc(), free(), realloc() so that they'll be linked in the code in place of the ones from stdlib. This ensures that the heap from stdlib is not used anymore.

In the end, here's a rough overview of the memory allocation:

This leaves 784B unallocated at build time.

I used this branch for multiple days and the minimum memory available in the FreeRTOS heap was around 6KB. Which means that we still have ~6KB of RAM available for static allocation (we'll need a bit of this for the new HR implementation) or for dynamic allocation (for new apps, fonts,...).

github-actions[bot] commented 1 year ago
Build size and comparison to main: Section Size Difference
text 406104B -352B
data 940B 0B
bss 62772B 9212B
kieranc commented 1 year ago

Initital testing looks good, I can switch from PTS to G7710 to Infineat without corrupted fonts.