Useful, header-only C++ library collection for STM32 microcontrollers.
-
Modern C++ (C++23).
-
Simple Integration with CMake.
-
Provide wrapper classes over STM32 HAL drivers.
-
Install STM32CubeMX
Download and install STM32CubeMX from the official website.
-
Install Git
Download and install Git from the official website.
-
Install Visual Studio Code
Download and install Visual Studio Code from the official website.
-
Install the STM32CubeIDE for Visual Studio Code Extension
-
Open Visual Studio Code.
-
Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressing
Ctrl+Shift+X. -
Search for
STM32CubeIDE for Visual Studio Code. -
Click
Installon the STM32CubeIDE for Visual Studio Code extension.
-
-
Generate Code Using STM32CubeMX
-
Open STM32CubeMX.
-
Create a new project and configure your STM32 microcontroller as needed.
-
In the
Project Managertab, set theToolchain / IDEtoCMake. -
Click on
Generate Codeto generate the project files.
-
-
Open the Generated Project in Visual Studio Code
-
Open Visual Studio Code.
-
Click on
File>Open Folder...and select the folder where STM32CubeMX generated the project files. -
Follow the instructions provided by the STM32CubeIDE for Visual Studio Code extension to set up the project.
-
Click on
STM32CubeIDEextension icon >Setup STM32Cube project(s), then select your STM32 Board/Device and set theToolchaintoGCC. -
Rename the
main.cfile tomain.cppand update the MX_Application_Src from the CMakeLists.txt file. -
Add the following compile flags to the
.clangdfile in the root directory of your project as shown below:
CompileFlags: Add: - '-ferror-limit=0' - '-Wno-implicit-int' - '-std=c++23' - '-Wall' - '-Wextra' - '-Wfatal-errors' - '-Wpedantic' -
-
Add STM32 Library Collection to Your Project
- Add STM32 Library Collection as a submodule to your project repository by running the following command in your project directory:
git submodule add git@github.com:oguztoraman/stm32-library-collection.git External/STM32LibraryCollection
- Initialize and update the submodule:
git submodule update --init --recursive
- Add the following lines to your top-level
CMakeLists.txtfile:
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) add_subdirectory(External/STM32LibraryCollection) target_link_libraries(${CMAKE_PROJECT_NAME} STM32::LibraryCollection )
-
Include the Desired Header Files in Your Code
- Include the desired header files from the STM32 Library Collection in your
main.cppor other source files. For example:
#include "STM32LibraryCollection/Gpio.hpp" #include "STM32LibraryCollection/Timer.hpp"
- Include the desired header files from the STM32 Library Collection in your
-
To prevent your existing code from being overwritten when regenerating code, write your code between the
USER CODE BEGINandUSER CODE ENDsections. -
Rename
main.cpptomain.cbefore modifying the.iocfile and regenerating code. After regeneration, rename the newly generatedmain.cback tomain.cpp.
Licensed under the GNU LGPL version 3. See the COPYING.LESSER file for details.