2025-11-28 8:37 AM - last edited on 2025-11-28 9:05 AM by Imen.D
Hi Community,
I'm trying to build the BLE_TransparentMode example for the NUCLEO-WB05KZ, but I'm getting the following build error:
region 'FLASH' overflowed by 93348 bytes
Steps to reproduce:
Environment:
STM32CubeMX: v6.16
STM32CubeIDE for VS Code: v3.6.4
Has anyone encountered this issue or knows what might be causing the FLASH overflow with the CMake/GCC configuration?
Thanks!
2025-11-28 8:59 AM
@Dadigno wrote:
- Open the BLE_TransparentMode example from the MX Example Selector for NUCLEO_WB05KZ.
- Change the toolchain to CMake with GCC compiler.
Are you sure that the optimisation level is the same in your modified project?
What happens if you build the example as-is - without any modifications ?
2025-11-30 11:53 PM
Hi,
build runs fine without any modifications, using stm32cubeide.
@Andrew Neil wrote:Are you sure that the optimisation level is the same in your modified project?
I think so, I didn’t change anything else except the compiler and toolchain settings from MX.
2025-12-01 2:19 AM
@Dadigno wrote:I think so
But have you checked?
@Dadigno wrote:I didn’t change anything else except the compiler and toolchain
Well, the optimisation level is a compiler setting!
2025-12-01 8:17 AM
I found a difference in the optimization level: in the STM32CubeIDE project it's set to -Os, while in the CMake project it's -O0. However, after switching to -Os the flash overflow is now 100.2%. Maybe there's something else? What else can I check?
2025-12-01 8:34 AM
So what was the flash use percentage in the CubeIDE build ?
Have you done a thorough check of all the other settings; eg,
Do you get a map file from the CMake build?
Note that the full command line appears in the Console when you do the CubeIDE build.
2025-12-01 9:30 AM
Other compilation flags are exactly the same; I can't find any differences.
CubeIDE reports 100% RAM usage and 99.35% flash usage, so it's very close to the memory limit. Comparing the map files, it seems that more code is being included in many sections.
But I don’t understand why, the project and the libraries should be the same. Why does it change when using the CMake toolchain?
2025-12-01 9:34 AM
@Dadigno wrote:Comparing the map files, it seems that more code is being included in many sections.
Have you enabled ASSERTs, or some other debug/diagnostic/logging feature?
@Dadigno wrote:Why does it change when using the CMake toolchain?
Are you sure your CMake toolchain is using the exact same GCC version as CubeIDE ?
2025-12-01 9:48 AM
@Dadigno wrote:Why does it change when using the CMake toolchain?
Are you sure your CMake toolchain is using the exact same GCC version as CubeIDE ?
GCC versions is 13.3.1 for both env
The .cmake I'm using:
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER_ID GNU)
set(CMAKE_CXX_COMPILER_ID GNU)
# Some default GCC settings
# arm-none-eabi- must be part of path environment
set(TOOLCHAIN_PREFIX arm-none-eabi-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)
set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# MCU specific flags
set(TARGET_FLAGS "-mcpu=cortex-m0plus")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS_DEBUG "-Os -g3")
set(CMAKE_C_FLAGS_RELEASE "-Os -g0")
set(CMAKE_CXX_FLAGS_DEBUG "-Os -g3")
set(CMAKE_CXX_FLAGS_RELEASE "-Os -g0")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics")
set(CMAKE_EXE_LINKER_FLAGS "${TARGET_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_SOURCE_DIR}/stm32wb05_flash.ld\"")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nano.specs")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--print-memory-usage")
set(TOOLCHAIN_LINK_LIBRARIES "m")