$REPO_NAME
NOTE: Gitea replaces
$REPO_NAMEabove when a new repo is created from this template (README.mdmust be listed in.gitea/template).
Toolchain
| Item | Required / Supported |
|---|---|
| Build System | CMake (>= 3.22) + Ninja |
| Compiler | arm-none-eabi-gcc |
| Config Generator | STM32CubeMX |
| Default MCU Target | STM32F767ZITx (Nucleo-144) |
1. Install Prerequisites
macOS
- Install CMake, Ninja, ARM-GCC Toolchain (arm-none-eabi-gcc), and OpenOCD/ST-Link utilities via Homebrew:
brew install cmake, ninja, arm-none-eabi-gcc stlink openocd
- Verify tools are on your path:
cmake --version
arm-none-eabi-gcc --version
- (Optional for GUI pin/clock config) Install STM32CubeMX & STM32CubeIDE for Visual Studio Code Extension in VS Code / Cursor.
Windows
-
Install STM32CubeCLT from here;
-
Alternatively, install via WinGet (powershell):
winget install Kitware.CMake Ninja-build.Ninja Arm.GnuArmEmbeddedToolchain
- Keep project paths short and without spaces, e.g.
C:\dev\arcs\<repo>
Linux
- Install toolchain:
sudo apt update
sudo apt install cmake ninja-build gcc-arm-none-eabi libnewlib-arm-none-eabi stlink-tools openocd
2. Build (CLI or VS Code / Cursor)
Terminal (CLI)
- From repository root, configure and build using the included CMake presets:
cmake --preset Debug
cmake --build build/Debug
A successful build links build/Debug/<project_name>.elf and prints the RAM and FLASH memory usage.
VS Code / Cursor
- Open repository root folder in VS Code or Cursor.
- Ensure the CMake Tools extension is installed.
- Open command pallete (cmd+shift+p / ctrl+shift+p) -> CMake: Select Configuration Preset -> choose Debug.
- Click Build in the bottom status bar (or press f7).
3. Flash & Debug
Using OpenOCD (macOS / Linux / Windows)
With the board connected via USB (ST-Link):
openocd -f interface/stlink.cfg -f target/stm32f7x.cfg -c "program build/Debug/STM32-bringup.elf verify reset exit"
Adjust target/stm32f7x.cfg to e.g. target/stm32g4x.cfg if retargeting another board.
Using st-flash (stlink-tools)
Convert the .elf to a .bin and flash to 0x08000000:
arm-none-eabi-objcopy -O binary build/Debug/STM32-bringup.elf build/Debug/firmware.bin
st-flash write build/Debug/firmware.bin 0x08000000
Using VS Code / STM32Cube Extension
Connect the board and use the Run and Debug sidebar with STM32CubeCLT (ST-Link GDB Server)
4. Changing pins, clocks, or target silicon
Hardware initilization is managed by STM32CubeMX via STM32-bringup.ioc
- Open STM32-bringup.ioc in STM32CubeMX.
- Modify pinout, peripheral settings, or clock config tree.
- Keep Project Manager -> Toolchain / IDE set to CMake.
- Click Generate Code
- User Code placed strictly between /* USER CODE BEGIN ... / and / USER CODE END ... */ comments in Core/ is preserved across code generations. Never write custom code outside of these blocks in generated files.
Project layout
CMakeLists.txt Project definition
CMakePresets.json Standard Debug/Release CMake presets
cmake/
gcc-arm-none-eabi.cmake ARM cross-compiler toolchain definition
stm32cubemx/CMakeLists.txt CubeMX autogen source & HAL linkage
Core/
Inc/ Application & HAL Config Headers
Src/main.c Entry point, SystemClock_Config(), and super loop
Src/stm32f7xx_it.c Interrupt service routines
Src/stm32f7xx_hal_msp.c HAL MSP initilization
Drivers/
CMSIS/ ARM Cortex-M & device header files
STM32F7xx_HAL_Driver/ ST Hardware Abstraction Layer (HAL) drivers
startup_stm32f767xx.s MCU assembly startup & interrupt vector table
STM32F767XX_FLASH.ld Linker script defining Flash/RAM layout
STM32-bringup.ioc STM32CubeMX config file
.gitea/template Files gitea fills in when generating a new repo
Config rules
- Commit
.ioc,CMakeLists.txt,CMakePresets.json,cmake/,Core/,Drivers/, the.sstartup file and the.ldlinker script. - Never commit
/build,.vscode/, or compiled binaries (.elf,.bin,.hex,.map). - Always keep custom C code inside of /* USER CODE BEGIN ... / and / USER CODE END ... */ blocks so CubeMX never overwrites your work.
Troubleshooting
| Symptom | Fix |
|---|---|
Origin
Template from STM32CubeIDE for Visual Studio Code wizard, selecting board selector, selecting the STM32F767ZI, creating as a CMake project, and allowing default initilization of peripherals.