azhel12 / Zhele

Framework for Stm32 MCU on C++ templates. Project based on "mcucpp" by Konstantin Chizhov.
BSD 2-Clause "Simplified" License
42 stars 9 forks source link

STM32Gxx add #35

Closed dlprfid closed 1 month ago

dlprfid commented 1 month ago

Hi! Can you help add STM32Gxx targets to library? Or send manual step-by-step for add it. Thank you

azhel12 commented 1 month ago

Hi!

Now library has partial support for G0 (some features, such as EXTI does not works). Which series is your target?

In general, for add port you should implement series-specific methods for classes

dlprfid commented 1 month ago

Custom target, base on stm32g431.

azhel12 commented 1 month ago

Custom target, base on stm32g431.

You can open Reference Manual for G431and nearest analog already presented in framework (I think it will be F4XX). Duplicate this target folder and rename it with g4.

Next, compare features from RM, register names and CMSIS content and edit corresponding lines.

Usually it's simplest way to add new target if it not too different from "classic" ST MCUs.

You can ask me a questions in telegram.

dlprfid commented 1 month ago

Thank you! It's work )) Another one question. Can you write me method add FreeRTOS in project? Thank for your replay.

azhel12 commented 1 month ago

Thank you! It's work )) Another one question. Can you write me method add FreeRTOS in project? Thank for your replay.

Hm, FreeRTOS and Zhele are independent. You can configure clocks with Zhele.

It's CMakeLists sample from some my project wich combines FreeRTOS ans my lib.

# Add zhele
include(FetchContent)
FetchContent_Declare(Zhele
    zhele
    GIT_REPOSITORY https://github.com/azhel12/Zhele.git
    GIT_TAG        master
)
FetchContent_MakeAvailable(zhele)

# Add FreeRTOS
include(FetchContent)
FetchContent_Declare(
    freertos_kernel
    GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
    GIT_TAG        V11.1.0
)
FetchContent_Populate(freertos_kernel)
set(FREERTOS_PATH "${freertos_kernel_SOURCE_DIR}")
find_package(FreeRTOS COMPONENTS ARM_CM4F REQUIRED)
target_include_directories(FreeRTOS INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty_configs/FreeRTOS)

...

add_executable(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
    CMSIS::STM32::F407VG zhele::zhele
    FreeRTOS FreeRTOS::ARM_CM4F FreeRTOS::Timers FreeRTOS::Heap::4 FreeRTOS::EventGroups
    lwip_core lwip_apps lwip_mbedtls
    STM32::NoSys STM32::Nano)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE HSE_VALUE=16000000 HSI_VALUE=16000000 F_CPU=168000000)
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -flto)

UPD: but I can recommend you more lighweight RTOS, such as scmRTOS.

dlprfid commented 1 month ago

Maybe you are right. Can you show me changes in make file if i make RTOS such as scmRTOS?

azhel12 commented 1 month ago

Maybe you are right. Can you show me changes in make file if i make RTOS such as scmRTOS?

From another sample project (scm does not has CMake support out the box, just clone and copy it):

cmake_minimum_required(VERSION 3.16)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/stm32_gcc.cmake)
set (CMAKE_CXX_STANDARD 20)

project(expander_scm CXX C ASM)

stm32_fetch_cmsis(F0)

find_package(CMSIS COMPONENTS STM32F0 REQUIRED)

# Add zhele
include(FetchContent)
FetchContent_Declare(Zhele
    GIT_REPOSITORY https://github.com/azhel12/Zhele.git
    GIT_TAG        cmake_0.1
)
FetchContent_MakeAvailable(Zhele)

# Initialize and add BuguRTOS
set(SCM_CONFIG_DIR "config/")
set(SCM_ARCH "cortex")
include(${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/scmRTOS/scmRTOS.cmake)

# Project sources
set(PROJECT_SOURCES
    src/main.cpp
    src/int_handlers.cpp
)

add_executable(expander_scm ${PROJECT_SOURCES})

target_link_libraries(expander_scm zhele::zhele CMSIS::STM32::F030x6 scm_core STM32::NoSys STM32::Nano)
target_compile_options(expander_scm PRIVATE -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections)

# Custom LD with stack=0x100, heap=0
stm32_add_linker_script(expander_scm PRIVATE src/f030f0.ld)

stm32_print_size_of_target(expander_scm)
stm32_generate_binary_file(expander_scm)
dlprfid commented 1 month ago

Thx! I will try now

dlprfid commented 1 month ago

Sorry, scmRTOS folder put in src folder in project or in project's folder?

dlprfid commented 1 month ago

Can you show me this your file? scmRTOS.cmake

azhel12 commented 1 month ago

scmRTOS cmake removeext

dlprfid commented 1 month ago

Don't open (

dlprfid commented 1 month ago

Thx! All is ok.