This is a simple project template for STM32F411CE (Blackpill).
Implemented:
- build a binary file for STM32F411
- works under Linux and Windows
- uses ARM GNU toolchain
Planned:
- build using clang (LLVM)
- support for unit testing under the host
Requirements: cmake, make, ARM Toolchain (from ARM or your distribution package system)
cd stm32f411ce-template
mkdir build
cd build
cmake -Darm_toolchain=~/gcc-arm-none-eabi-10-2020-q4-major/ -DCMAKE_TOOLCHAIN_FILE=../arm-gcc-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug ..
make
On windows you will need to get make
installed. The easies way seems to be getting it from Chocolatey.
- go to https://chocolatey.org/install
- Install Chocolatey
- then
choco install make
in the terminal
Cmake and ARM Toolchain can be installed using installer packages.
- https://cmake.org/download/
- https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads
I like to used cmake-gui on Windows (because I find it difficult to type paths in windows shell):
- Open cmake-gui
- Select your source folder.
- Select build folder (usually a folder named
build
in the root of the project). - Click "Configure"
- In the dialog window select "Unix Makefiles" and "Specify toolchain file for cross-compiling".
- Browse for the toolchain file.
- Error will show up. Fill out
arm_toolchain
to point at the installation of the ARM toolchain. Usually "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major". - Select
CMAKE_BUILD_TYPE
to either "Debug" or "Release". - Run Configure again. It should work now.
- Run Generate.
- Open a powershell window in the "build" folder. Open the folder in Explorer, Shift+Right-click anywhere in the folder and select "Open Powershell window here".
- Type
make
.
Another useful options options are make clean
to remove build artifacts, make VERBOSE=1
to show how the compiler is invoked with all parameters.
Create a new .c
or .cpp
file and add it to the CMakeLists.txt
in the folder with the source, ie src/CMakeLists.txt
.
If a new root level folder is needed, create the folder and then copy the src/CMakeLists.txt
file into the new folder. Modify the file to include sources files in the new folder and give the target a unique name (ie. rename app
to something else). Then modify the root CMakeLists.txt
to add_subdirectory("new_folder")
and also add the new target to target_link_libraries
.
- https://github.com/ObKo/stm32-cmake an excellent project that provides CMake targets for the entire lineup of STM32 Arm Cortex MCUs. This works well and is easy to use, however it is a complex project with many features therefore I decided to create something simpler.
This project contains several files from ST Micro, the vendor of he MCU. The files are in the folder vendor
.
There is also a hard fault handler from SEGGER https://wiki.segger.com/Cortex-M_Fault