Skip to content

npm version npm npm licence

Libopencm3 CMake

vbat

cmake configuration for stm32 libopencm3, with automatic linker script generator

Introduction

cmake configuration for stm32 libopencm3, with automatic linker script generator

Build Step

Prerequisite:

  • cmake
  • arm-none-eabi-gcc
  • mkdocs (optional )
  • make (optional, if you build with gnu-make )
  • doxygen (optional, to build libopencm3 documentation )

Almost all prerequisite available in pacman(arch linux), clone this repo and change directory to this folder then...

git clone https://github.com/ahsanu123/learnRepo.git
cd embedded
cmake -S . -B build
cd build
make

you also can generate documentation by

cd build/_deps/libopencm3-src/doc
make

Working Principle

to use this script you only need to fill arch and devicefor your stm32 on main CMakeLists.txt, then let cmake do the job

# ============================================
# THIS VALUE MUST BE SET BASED ON
# STM32 ARCHITECTURE AND
# DEVICE SERIES
# ============================================
set(auto_stm32_arch "f4")
set(auto_stm32_device "stm32f407vgt6")
# ============================================

then link your project

# ============================================
# CHANGE YOUR TARGET BASED ON YOUR PROJECT
# ============================================
project(blink VERSION 0.0.1 LANGUAGES CXX C ASM)

.....

add_executable(blink src/blink.cpp)
target_link_libraries(blink auto_stm32)

basic principle for this cmake script.

graph TD
  A(Start) --> B{Detected Arch \nand Device?};
  B -->|No| Z
  B -->|Yes| C{libopencm3 \ndownloaded?}
  C -->|No| D[Fetch Content]
  C -->|Yes| E[build libopencm3]
  D --> C
  E --> F[Generate Linker \nscript based on \ndevice and arch]
  F --> G[Compile All Source File]
  G --> H[Link all Object]
  H --> I[.elf generated]
  I --> J
  J(Stop)
  Z[Error!!] --> J[Stop]

Reference

most of cmake configuration come from official libopencm3 documentation, cmake documentation and

Sunday 04:28 2024 in the morning, Made with ♥️ by AH...