rogerclarkmelbourne / Arduino_STM32

Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
Other
2.5k stars 1.26k forks source link

Malloc hangs at blackpill F401CC - incorrect HEAP settings? #869

Closed board707 closed 8 months ago

board707 commented 2 years ago

I am using a STM32 F401CC blackpill. If I am trying to allocate memory using malloc, my program hangs/crashes on the malloc command. But for bluepill STM32F103 malloc works fine. My research into the problem led me to the memory heap settings in the file STM32F4/variants/blackpill_f401/ld/common.inc Lines 152-153 of the file defines borders of the heap. Traditionally the heap is placed between msp and bss sections, but in this file it placed between msp_init and __data_end. But data_end is situated in FLASH, far from RAM area and not suitable for HEAP. It looks like a bug. To fix this, I replaced in the line 152 data_end to bss_end__ : `_lm_heap_start = DEFINED(_lm_heap_start) ? _lm_heap_start : bss_end__;` and as result malloc on F401 blackpill now works fine.