Flashing (STM32)
Build outputs and how to flash a kbox-stack STM32 (HAL) firmware — with OpenOCD over ST-Link, or from VS Code and STM32CubeIDE.
Once the example is built (see Getting Started) you flash the resulting image to the board. This page covers the build outputs and the flashing options.
Build outputs
The build produces an ELF, and a CMake post-build step derives an Intel HEX and a
raw binary with objcopy, then prints the image size:
add_custom_command(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:...> ${CMAKE_PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:...> ${CMAKE_PROJECT_NAME}.bin
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:...>
COMMENT "Generating .hex and .bin"
)Inside the build directory you get:
| File | Use |
|---|---|
led-indicator.elf | Full image with symbols — best for flashing and debugging. |
led-indicator.hex | Intel HEX (addressed) — for programmers that want HEX. |
led-indicator.bin | Raw binary — flash at the base address (0x08000000). |
The single-image example boots directly at 0x08000000, so any of the three
outputs works.
Flash with OpenOCD
Connect the ST-Link probe to the board's SWD header and to your PC.
Program, verify, reset, and exit in one command, using the OpenOCD config shipped with the example:
openocd -f "led-indicator Debug.cfg" \
-c "program build_dbg/led-indicator.elf verify reset exit"program writes the image, verify reads it back to confirm, reset restarts
the MCU, and exit closes OpenOCD. You can pass the .hex instead of the
.elf.
Confirm it runs. After reset the device is a live KNX node; a 1-bit
GroupValueWrite to its On/Off object lights the indicator LED.
The OpenOCD config
The example ships led-indicator Debug.cfg (generated by STM32CubeIDE). It
selects the ST-Link interface over SWD and the STM32F1 target:
source [find interface/stlink-dap.cfg]
set WORKAREASIZE 0x5000
transport select "dapdirect_swd"
set CHIPNAME STM32F103TBUx
set BOARDNAME genericBoard
set ENABLE_LOW_POWER 1 # allow debug in low-power modes
set STOP_WATCHDOG 1 # stop watchdog counters when halted
set CLOCK_FREQ 8000 # ST-Link debug clock (kHz)
reset_config srst_nogate
set GDB_PORT 3333
source [find target/stm32f1x.cfg]set STOP_WATCHDOG 1 halts the IWDG counters while the core is halted. This is
what lets you sit at a breakpoint without the watchdog resetting the device
during a debug session.
IDE flashing
Open led-indicator.code-workspace. The .vscode/ folder ships build tasks and
a Cortex-Debug launch configuration that drives OpenOCD + GDB. Install the
Cortex-Debug extension and have OpenOCD on your PATH, then start debugging
— the extension flashes and halts at main.
The project ships a CubeMX .ioc (led-indicator.ioc) alongside the CMake
build. Import it via File → Import → C/C++ → Existing Code as CMake Project
(or Import CMake project), then use the IDE's Run/Debug to build, flash over
ST-Link, and debug from the GUI.
If your ARM toolchain is not on the default path, pass its bin/ directory when
configuring: cmake -S . -B build_dbg -DTOOLCHAIN_BIN=/path/to/arm-none-eabi/bin ....