Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

alatarum/stm32-cmake

 
 

Repository files navigation

Table of Contents

About

This project is used to develop applications for stm32 - ST's ARM Cortex-M3 MCUs, using cmake, GCC, newlib (libc) and STM32 Standard Peripherals Library. For now it support only STM32F10x and STM32L1xx families, but it is easy to add other families in the future.

Requirements:

  • cmake >= 2.6
  • GCC toolchain with newlib.
  • STM32F10x or STM32L1xx Standard Peripherals Library
Project contains:
  • CMake toolchain file, that configures cmake to use arm toolchain.
  • CMake projects that builds CMSIS and Standard Peripherals Library into static libraries.
  • CMake modules to find and configure CMSIS ans StdPeriphLib libraries.
  • CMake project template.
  • Example projects for STM32F10x (will be adapted for STM32L1xx later)
    • blinky - blink LED using timers and PWM.
    • newlib - show date from RTC using uart and libc functions from newlib

Building & Installing

First of all you need to configure toolchain and libraries, you can do this by editing gcc_stm32.cmake or pass it throught command line. Variables for toolchain:

  • TOOLCHAIN_PREFIX - where toolchain is located, default: /usr
  • TARGET_TRIPLET - toolchain target triplet, default: arm-none-eabi
Variables for CMSIS and StdPeriphLib:
  • STM32_SPL_DIR - path to STM32F10x Standard Peripherals Library default: /opt/STM32F10x_StdPeriph_Lib_V3.5.0
  • STM32_FAMILY - STM32 family for which build (without "STM32" prefix) default: F10x
  • USE_ASSERT - Use internal asserts in Standard Peripherals Library.

Build CMSIS and Standard Peripherals Library

In cmsis folder:

 cmake -DCMAKE_TOOLCHAIN_FILE=../gcc_stm32.cmake -DSTM32_FAMILY=<family> -DCMAKE_INSTALL_PREFIX=<path_to_toolchain>/arm-none-eabi/ -DCMAKE_BUILD_TYPE=Release
 make && make install

In stdperiph folder

 cmake -DCMAKE_TOOLCHAIN_FILE=../gcc_stm32.cmake -DSTM32_FAMILY=<family> -DCMAKE_INSTALL_PREFIX=<path_to_toolchain>/arm-none-eabi/ -DCMAKE_BUILD_TYPE=Release
 make && make install

Note: You can use different CMAKE_INSTALL_PREFIX, but than you'll have to configure cmake search paths when using cmake modules.

Usage

After building you need to copy cmake modules in cmake's modules path, or just set CMAKE_MODULE_PATH in project. Than you need to adjust some variables in CMakeLists.txt (example for stm32f103ve):

  • PROJECT(stm32-template) - Set the project name.
  • FIND_PACKAGE(StdPeriphLib REQUIRED) - comment/remove this if you don't need StdPeriphLib. CMSIS package are always required.
  • STM32_SET_PARAMS("512K" "64K" "0x20010000") - Set chip's flash size, ram size, and stack bottom address. Also, you can change min heap size, stack size, etc. - look into FindCMSIS.cmake
  • All projects sources should be listed in PROJECT_SOURCES variable.
Also, if you using StdPeriphLib you need to adjust modules in stm32f10x_conf.h.

Build

Generate Makefile:

 cmake -DSTM32_FAMILY=<family> -DSTM32_CHIP_TYPE=<chip type> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Debug <path_to_source_dir>

Where <chip></chip> for STM32F10x is:

  • HD - High Density MCUs
  • HD_VL - High Density Value Line MCUs
  • MD - Medium Density MCUs
  • MD_VL - Medium Density Value Line MCUs
  • LD - Low Density MCUs
  • LD_VL - Low Density Value Line MCUs
  • CL - Connectivity Line MCUs
  • XL - XL Density MCUs
and for STM32L1xx is:

  • HD - High Density MCUs
  • MD - Medium Density MCUs
  • MDP - Medium Density Plus MCUs

Build:

 make

The result is a .elf file, to build .hex:

 make hex

or .bin:

 make bin

For using with Code::Blocks:

 cmake -DSTM32_FAMILY=&lt;family&gt;&lt;/family&gt; -DSTM32_CHIP_TYPE=&lt;chip&gt;&lt;/chip&gt; -DCMAKE_TOOLCHAIN_FILE=&lt;path_to_stm32.cmake&gt;&lt;/path_to_stm32.cmake&gt; -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" &lt;path_to_source_dir&gt;&lt;/path_to_source_dir&gt;

For release build:

 cmake -DSTM32_FAMILY=&lt;family&gt;&lt;/family&gt; -DSTM32_CHIP_TYPE=&lt;chip&gt;&lt;/chip&gt; -DCMAKE_TOOLCHAIN_FILE=&lt;path_to_stm32.cmake&gt;&lt;/path_to_stm32.cmake&gt; -DCMAKE_BUILD_TYPE=Release -G "CodeBlocks - Unix Makefiles" &lt;path_to_source_dir&gt;&lt;/path_to_source_dir&gt;

For using with Eclipse CDT:

 cmake -DSTM32_FAMILY=&lt;family&gt;&lt;/family&gt; -DSTM32_CHIP_TYPE=&lt;chip&gt;&lt;/chip&gt; -DCMAKE_TOOLCHAIN_FILE=&lt;path_to_stm32.cmake&gt;&lt;/path_to_stm32.cmake&gt; -DCMAKE_BUILD_TYPE=Debug -G "Eclipse CDT4 - Unix Makefiles" &lt;path_to_source_dir&gt;&lt;/path_to_source_dir&gt;

For release build:

 cmake -DSTM32_FAMILY=&lt;family&gt;&lt;/family&gt; -DSTM32_CHIP_TYPE=&lt;chip&gt;&lt;/chip&gt; -DCMAKE_TOOLCHAIN_FILE=&lt;path_to_stm32.cmake&gt;&lt;/path_to_stm32.cmake&gt; -DCMAKE_BUILD_TYPE=Release -G "Eclipse CDT4 - Unix Makefiles" &lt;path_to_source_dir&gt;&lt;/path_to_source_dir&gt;

About

CMake for stm32 developing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 82.7%
  • C++ 17.3%