STM32CubeIDE
STM32CubeIDE is Eclipse-based, so the general shortcuts and known issues on the Tools page apply here too.
Build Analyzer
Window ▸ Show View ▸ Build Analyzer shows how the linked image occupies flash
and RAM, broken down by memory region and by symbol.
-
It does not refresh on its own. Rebuild or switch projects, then press the refresh button in the view's toolbar.
-
An empty Memory Regions tab means no map file was produced. Check the linker settings under
Project ▸ Properties ▸ C/C++ Build ▸ Settings ▸ MCU GCC Linker ▸ Miscellaneous, where the flag should read:-Wl,-Map=${ProjName}.map-Mapis a linker option, so it has to be passed through GCC with-Wl,and no space. Writing-Map=... -Wlputs the arguments in the wrong order and GCC never forwards the option.
The Memory Details tab is the one worth reading when flash is tight: it sorts symbols by size and makes it obvious which buffer or lookup table is responsible.
CMake projects
Configure-time arguments go in Project ▸ Properties ▸ C/C++ Build ▸ CMake Settings ▸ Other options:
-DCMAKE_TOOLCHAIN_FILE=cubeide-gcc.cmake -DCMAKE_BUILD_TYPE=Debug -DMFLOAT_ABI_HARDWARE=hard
Build type
Either pass it on the command line:
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_BUILD_TYPE=Release
or pin it in CMakeLists.txt:
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Release")
Do not do both — a set() without FORCE is overridden by the cached
command-line value, so the file appears to be ignored. Prefer the command line
and keep the build type out of CMakeLists.txt entirely.
Debug builds at -O0 -g3, which is what makes single-stepping match the
source. Release at -Os or -O2 reorders and inlines heavily, so breakpoints
land on unexpected lines and locals read as optimised out. That is the optimiser
working correctly, not a broken debugger.
Toolchain file
-DCMAKE_TOOLCHAIN_FILE has to be passed on the first configure. CMake caches
it, and a later change is ignored until the build directory is deleted.
STM32CubeProgrammer
Flashing an ELF directly:
Erase flash memory ▸ Memory & File editing ▸ Load *.elf ▸ Download
- The warning
File corrupted. Two or more segments defines the same memory zonecan be ignored. It comes from overlapping load segments that the linker emits legitimately — typically initialised data present both in flash and at its RAM address. - If the debugger will not attach afterwards, press the board's
RESETbutton. The core is often left halted in a state the probe cannot resume from. - Boards with external flash need the matching external loader selected first. See Development boards.
Naming
| Abbreviation | Meaning |
|---|---|
| BSP | Board Support Package — drivers for on-board components |
| HAL | Hardware Abstraction Layer — the portable peripheral API |
| LL | Low Layer — thin register-level API, an alternative to HAL |
| MSP | MCU Specific Package — the board-dependent half of peripheral init |
| MX | CubeMX-generated code, as in MX_GPIO_Init |
| IOC | The CubeMX project file, *.ioc |
MSP is the one that causes confusion: HAL_UART_MspInit is not part of the HAL
proper. The HAL calls it, and you supply it, because clocks, pins and DMA
channels depend on the board rather than the part. See
UART and virtual COM port.