Framework for Stm32 MCU on C++ templates. Project based on "mcucpp" by Konstantin Chizhov.
Support: I created public group in telegram, where I'll try help everyone with using the framework. Sorry, but I can answer only on russian:)
Also I write small lessons about applying c++ templates (and my framework) for stm32.
I'm using following stack:
Basically c++17 is required, c++20 needed only for USB. But I'm planning to use more new features from modern C++ (such as concepts and maybe coroutines and some features from c++23), so it's strongly recommended to use latest toolchain.
Download Visual Studio Code from official site and install it.
Download new Arm Embedded Toolchain from official site. Choose latest (arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-eabi).
Download exe and install, or you can download zip and add bin folder location to system PATH.\
If you use *nix system download appropriate linux hosted cross toolchains.
There is no latest version in official repo (I tried on ubuntu), so unpack toolchain manually
and add to path. Tutorial post.\
Check that compiler available from terminal.
Download and install Cmake.
Check that cmake is available from terminal.
Install C++ extension pack and Cmake Tools in VSCode (it's not requires but useful).
Create project folder or download template.\ You can download stm32-cmake manually. Read README.
Add CMakeLists to project root
cmake_minimum_required(VERSION 3.16)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/stm32_gcc.cmake)
set (CMAKE_CXX_STANDARD 23)
project(zhele_template CXX C ASM)
stm32_fetch_cmsis(F1) find_package(CMSIS COMPONENTS STM32F1 REQUIRED)
include(FetchContent) FetchContent_Declare(Zhele GIT_REPOSITORY https://github.com/azhel12/Zhele.git GIT_TAG zhele_v0.1.1 ) FetchContent_MakeAvailable(Zhele)
set(PROJECT_SOURCES src/main.cpp )
add_executable(zhele_template ${PROJECT_SOURCES})
target_link_libraries(zhele_template zhele::zhele CMSIS::STM32::F103C8 STM32::NoSys STM32::Nano)
target_compile_options(zhele_template PRIVATE -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections)
stm32_print_size_of_target(zhele_template)
stm32_generate_binary_file(zhele_template)
6. Write code in source file.
```c++
// Define target cpu frequence.
#define F_CPU 8000000
#include <zhele/iopins.h>
using namespace Zhele::IO;
// Connect LED on A4 for this example (or edit example code, it's simple).
int main()
{
Pa4::Port::Enable();
Pa4::SetConfiguration(Pa4::Configuration::Out);
Pa4::SetDriverType(Pa4::DriverType::PushPull);
Pa4::Clear();
for (;;)
{
}
}
Press Build button in CMake extension.
First time you need choose toolchain.
Profit! You can flash files i