I have a STM32H7 project that compiles and runs with plenty of spare RAM and FLASH, However, when I add to main.cpp a small test, the build fails, saying that it can’t be fit in Flash. Any idea what’s going on and how to fix it? The probject is based on files generated by Cube IDE, and the .ld file (below) is an exact copy of the Cube IDE file.
Build without the code
Building in debug mode
Checking size .pio\build\my_env\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [== ] 18.1% (used 23788 bytes from 131072 bytes)
Flash: [== ] 16.9% (used 88732 bytes from 524288 bytes)
The test code that was added:
class A {
public:
A() {}
virtual ~A() {}
virtual void foo() = 0;
};
template <uint16_t N>
class B : public A {
public:
B() {}
virtual ~B() {}
virtual void foo() {}
};
B<10> b;
Building with the test code.
Compiling .pio\build\my_env\src\host_link.o
Compiling .pio\build\my_env\src\main.o
Compiling .pio\build\my_env\src\tasks.o
Linking .pio\build\my_env\firmware.elf
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\my_env\firmware.elf section `.rodata' will not fit in region `FLASH'
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: region `FLASH' overflowed by 4432 bytes
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\my_env\firmware.elf] Error 1
platformio.ini
[env:my_env]
platform = ststm32
extra_scripts = extra_script.py
board = weact_mini_h750vbtx
build_type = debug
debug_tool = stlink
upload_protocol = stlink
debug_build_flags = -O0 -ggdb3 -g3
board_build.ldscript = STM32H750VBTX_FLASH.ld
monitor_port = COM6
lib_archive = no
lib_deps =
cube_ide
serial_packets
build_flags =
-fmax-errors=5
-mfpu=fpv5-sp-d16
-mfloat-abi=hard
-Wl,-Map,${BUILD_DIR}/firmware.map
-mthumb
-D DEBUG
-D USE_HAL_DRIVER
-DSTM32_THREAD_SAFE_STRATEGY=4
-fstack-usage
-std=gnu11
-Ilib/cube_ide/Core/Inc
-Ilib/cube_ide/Core/ThreadSafe
-Ilib/cube_ide/Drivers/CMSIS/Device/ST/STM32H7xx/Include
-Ilib/cube_ide/Drivers/CMSIS/Include
-Ilib/cube_ide/Drivers/STM32H7xx_HAL_Driver/Inc
-Ilib/cube_ide/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
-Ilib/cube_ide/Middlewares/ST/STM32_USB_Device_Library/Core/Inc
-Ilib/cube_ide/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
-Ilib/cube_ide/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/Include
-Ilib/cube_ide/Middlewares/Third_Party/FreeRTOS/Source/include
-Ilib/cube_ide/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
-Ilib/cube_ide/USB_DEVICE/App
-Ilib/cube_ide/USB_DEVICE/Target
-D CONFIG_MAX_PACKET_DATA_LEN=100
-D CONFIG_MAX_PENDING_COMMANDS=5
STM32H750VBTX_FLASH.ld
/*
******************************************************************************
**
** File : LinkerScript.ld
**
** Author : STM32CubeIDE
**
** Abstract : Linker script for STM32H7 series
** 128Kbytes FLASH and 1056Kbytes RAM
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
** Distribution: The file is distributed as is, without any warranty
** of any kind.
**
*****************************************************************************
** @attention
**
** Copyright (c) 2023 STMicroelectronics.
** All rights reserved.
**
** This software is licensed under terms that can be found in the LICENSE file
** in the root directory of this software component.
** If no LICENSE file comes with this software, it is provided AS-IS.
**
****************************************************************************
*/
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x1000; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >FLASH
/* Constant data goes into FLASH */
.rodata :
{
. = ALIGN(4);
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} >FLASH
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
*(.RamFunc*) /* .RamFunc* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM_D1 AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM_D1
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM_D1
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
.ARM.attributes 0 : { *(.ARM.attributes) }
}