Skip to content

Commit

Permalink
CMSIS RTOS feature
Browse files Browse the repository at this point in the history
Adds the full features set for CMSIS RTOS support, with a lot
work provided by g-arjones. Builds on ObKo#190
and ObKo#189.

It allows to use the CMSIS support provided in the STM32 cube
repository.

Also adds documentation and an updated freertos example with the
same architecture as ObKo#225
  • Loading branch information
robamu committed Aug 1, 2021
1 parent 28e4de0 commit a642c5e
Show file tree
Hide file tree
Showing 47 changed files with 2,462 additions and 1,013 deletions.
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**Sources to reproduce**
Please provide link to repository showing the problem.
- Fork this repository
- Modify an existing example to show the abnormal behavior
- Share the link to the commit in your fork showing the problem

**Steps to reproduce**
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
- OS: [e.g. iOS]
- Compiler: [e.g. arm-none-eabi-gcc +version]
- stm32-cmake: [v2.0 or 86d1dd2 or ...]
- cmake: [e.g 3.21.0]
- HAL/cube/CMSIS: [stm32cubeL4 v1.2.3]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Tests

on: [push]
on: [push, pull_request]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
191 changes: 156 additions & 35 deletions README.md

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions cmake/FindBSP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ foreach(COMP ${BSP_FIND_COMPONENTS})
set(FAMILY ${CMAKE_MATCH_1})
string(TOLOWER ${FAMILY} FAMILY_L)

if((NOT STM32_CUBE_${FAMILY}_PATH) AND (DEFINED ENV{STM32_CUBE_${FAMILY}_PATH))
set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "ENV STM32_CUBE_${FAMILY}_PATH specified, using STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
endif()

if(NOT STM32_CUBE_${FAMILY}_PATH)
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "No STM32_CUBE_${FAMILY}_PATH specified using default: ${STM32_CUBE_${FAMILY}_PATH}")
Expand Down Expand Up @@ -322,13 +327,13 @@ foreach(COMP ${BSP_FIND_COMPONENTS})
target_link_libraries(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE BSP::STM32::${FAMILY}${CORE_C} CMSIS::STM32::${FAMILY}${CORE_C})
target_include_directories(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE "${BSP_${FAMILY}_PATH}/Components/${BCOMP}")

find_file(BSP_${BOARD_CANONICAL}_${COMP}_SOURCE
find_file(BSP_${BOARD_CANONICAL}_${BCOMP}_SOURCE
NAMES ${BCOMP}.c
PATHS "${BSP_${FAMILY}_PATH}/Components/${BCOMP}"
NO_DEFAULT_PATH
)
if (BSP_${BOARD_CANONICAL}_${COMP}_SOURCE)
target_sources(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE "${BSP_${BOARD_CANONICAL}_${COMP}_SOURCE}")
if (BSP_${BOARD_CANONICAL}_${BCOMP}_SOURCE)
target_sources(BSP::STM32::${FAMILY}${CORE_C}::${BCOMP_U} INTERFACE "${BSP_${BOARD_CANONICAL}_${BCOMP}_SOURCE}")
endif()
endforeach()

Expand Down
90 changes: 82 additions & 8 deletions cmake/FindCMSIS.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(CMSIS_RTOS RTOS RTOS_V2)

if(NOT CMSIS_FIND_COMPONENTS)
set(CMSIS_FIND_COMPONENTS ${STM32_SUPPORTED_FAMILIES_LONG_NAME})
endif()
Expand All @@ -7,6 +9,35 @@ if(STM32H7 IN_LIST CMSIS_FIND_COMPONENTS)
endif()
list(REMOVE_DUPLICATES CMSIS_FIND_COMPONENTS)

# This section fills the RTOS or family components list
foreach(COMP ${CMSIS_FIND_COMPONENTS})
string(TOLOWER ${COMP} COMP_L)
string(TOUPPER ${COMP} COMP)

# Component is RTOS component
if(${COMP} IN_LIST CMSIS_RTOS)
list(APPEND CMSIS_FIND_COMPONENTS_RTOS ${COMP})
continue()
endif()

# Component is not RTOS component, so check whether it is a family component
string(REGEX MATCH "^STM32([A-Z][0-9])([0-9A-Z][0-9][A-Z][0-9A-Z])?_?(M[47])?.*$" COMP ${COMP})
if(CMAKE_MATCH_1)
list(APPEND CMSIS_FIND_COMPONENTS_FAMILIES ${COMP})
endif()
endforeach()

if(NOT CMSIS_FIND_COMPONENTS_FAMILIES)
set(CMSIS_FIND_COMPONENTS_FAMILIES ${STM32_SUPPORTED_FAMILIES_LONG_NAME})
endif()

if(NOT CMSIS_FIND_COMPONENTS_RTOS)
set(CMSIS_FIND_COMPONENTS_RTOS ${CMSIS_RTOS})
endif()

message(STATUS "Search for CMSIS families: ${CMSIS_FIND_COMPONENTS_FAMILIES}")
message(STATUS "Search for CMSIS RTOS: ${CMSIS_FIND_COMPONENTS_RTOS}")

include(stm32/devices)

function(cmsis_generate_default_linker_script FAMILY DEVICE CORE)
Expand Down Expand Up @@ -41,7 +72,7 @@ function(cmsis_generate_default_linker_script FAMILY DEVICE CORE)
stm32_add_linker_script(CMSIS::STM32::${DEVICE}${CORE_C} INTERFACE "${OUTPUT_LD_FILE}")
endfunction()

foreach(COMP ${CMSIS_FIND_COMPONENTS})
foreach(COMP ${CMSIS_FIND_COMPONENTS_FAMILIES})
string(TOLOWER ${COMP} COMP_L)
string(TOUPPER ${COMP} COMP)

Expand All @@ -53,10 +84,10 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})

if(CMAKE_MATCH_2)
set(FAMILY ${CMAKE_MATCH_1})
set(DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
set(STM_DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
else()
set(FAMILY ${CMAKE_MATCH_1})
stm32_get_devices_by_family(DEVICES FAMILY ${FAMILY} CORE ${CORE})
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
endif()

if(CMAKE_MATCH_3)
Expand All @@ -71,9 +102,14 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})

string(TOLOWER ${FAMILY} FAMILY_L)

if((NOT STM32_CMSIS_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH) AND (DEFINED ENV{STM32_CUBE_${FAMILY}_PATH}))
set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "ENV STM32_CUBE_${FAMILY}_PATH specified, using STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
endif()

if((NOT STM32_CMSIS_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH))
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_CMSIS_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_CMSIS_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
endif()

find_path(CMSIS_${FAMILY}${CORE_U}_CORE_PATH
Expand Down Expand Up @@ -133,8 +169,8 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
target_sources(CMSIS::STM32::${FAMILY}${CORE_C} INTERFACE "${CMSIS_${FAMILY}${CORE_U}_SOURCE}")
endif()

set(DEVICES_FOUND TRUE)
foreach(DEVICE ${DEVICES})
set(STM_DEVICES_FOUND TRUE)
foreach(DEVICE ${STM_DEVICES})
stm32_get_cores(DEV_CORES FAMILY ${FAMILY} DEVICE ${DEVICE})
if(CORE AND (NOT ${CORE} IN_LIST DEV_CORES))
continue()
Expand All @@ -151,7 +187,7 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
)
list(APPEND CMSIS_SOURCES "${CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP}")
if(NOT CMSIS_${FAMILY}${CORE_U}_${TYPE}_STARTUP)
set(DEVICES_FOUND FALSE)
set(STM_DEVICES_FOUND FALSE)
break()
endif()

Expand All @@ -166,11 +202,49 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS})
cmsis_generate_default_linker_script(${FAMILY} ${DEVICE} "${CORE}")
endforeach()

if(DEVICES_FOUND)
if(STM_DEVICES_FOUND)
set(CMSIS_${COMP}_FOUND TRUE)
else()
set(CMSIS_${COMP}_FOUND FALSE)
endif()

foreach(RTOS_COMP ${CMSIS_FIND_COMPONENTS_RTOS})
if (${RTOS_COMP} STREQUAL "RTOS_V2")
set(RTOS_COMP_VERSION "2")
else()
unset(RTOS_COMP_VERSION)
endif()

find_path(CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_PATH
NAMES "cmsis_os${RTOS_COMP_VERSION}.h"
PATHS "${STM32_CUBE_${FAMILY}_PATH}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_${RTOS_COMP}"
NO_DEFAULT_PATH
)
if (NOT CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_PATH)
continue()
endif()

find_file(CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_SOURCE
NAMES "cmsis_os${RTOS_COMP_VERSION}.c"
PATHS "${STM32_CUBE_${FAMILY}_PATH}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_${RTOS_COMP}"
NO_DEFAULT_PATH
)
if (NOT CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_SOURCE)
continue()
endif()

if(NOT (TARGET CMSIS::STM32::${FAMILY}${CORE_C}::${RTOS_COMP}))
add_library(CMSIS::STM32::${FAMILY}${CORE_C}::${RTOS_COMP} INTERFACE IMPORTED)
target_link_libraries(CMSIS::STM32::${FAMILY}${CORE_C}::${RTOS_COMP} INTERFACE CMSIS::STM32::${FAMILY}${CORE_C})
target_include_directories(CMSIS::STM32::${FAMILY}${CORE_C}::${RTOS_COMP} INTERFACE "${CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_PATH}")
target_sources(CMSIS::STM32::${FAMILY}${CORE_C}::${RTOS_COMP} INTERFACE "${CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_SOURCE}")
endif()

list(APPEND CMSIS_SOURCES "${CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_SOURCE}")
list(APPEND CMSIS_INCLUDE_DIRS "${CMSIS_${FAMILY}${CORE_U}_${RTOS_COMP}_PATH}")
set(CMSIS_${RTOS_COMP}_FOUND TRUE)
endforeach()

list(REMOVE_DUPLICATES CMSIS_INCLUDE_DIRS)
list(REMOVE_DUPLICATES CMSIS_SOURCES)
endforeach()
Expand Down
54 changes: 45 additions & 9 deletions cmake/FindFreeRTOS.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
set(FreeRTOS_PORTS ARM_CM0 ARM_CM3 ARM_CM4F ARM_CM7)
set(FreeRTOS_PORTS ARM_CM0 ARM_CM3 ARM_CM4F ARM_CM7 ARM_CM4_MPU ARM_CM3_MPU ARM_CM7_MPU)
if(NOT FreeRTOS_FIND_COMPONENTS)
set(FreeRTOS_FIND_COMPONENTS ${FreeRTOS_PORTS})
endif()
list(REMOVE_DUPLICATES FreeRTOS_FIND_COMPONENTS)

if((NOT FREERTOS_PATH) AND (DEFINED ENV{FREERTOS_PATH}))
set(FREERTOS_PATH $ENV{FREERTOS_PATH} CACHE PATH "Path to FreeRTOS")
message(STATUS "ENV FREERTOS_PATH specified, using FREERTOS_PATH: ${FREERTOS_PATH}")
endif()

if(NOT FREERTOS_PATH)
set(DEFAULT_FREERTOS_PATH "/opt/FreeRTOS")
if(EXISTS ${DEFAULT_FREERTOS_PATH})
set(FREERTOS_PATH ${DEFAULT_FREERTOS_PATH} CACHE PATH "Path to FreeRTOS")
message(STATUS "No FREERTOS_PATH specified using default: ${DEFAULT_FREERTOS_PATH}")
else()
message(STATUS
"No FreeRTOS folder found at default location ${DEFAULT_FREERTOS_PATH}. "
"Leaving empty"
)
endif()
endif()

if(STM32H7 IN_LIST FreeRTOS_FIND_COMPONENTS)
list(REMOVE_ITEM FreeRTOS_FIND_COMPONENTS STM32H7)
list(APPEND FreeRTOS_FIND_COMPONENTS STM32H7_M7 STM32H7_M4)
endif()

# This section fills the family and ports components list
foreach(COMP ${FreeRTOS_FIND_COMPONENTS})
string(TOUPPER ${COMP} COMP)
string(REGEX MATCH "^STM32([A-Z][0-9])([0-9A-Z][0-9][A-Z][0-9A-Z])?_?(M[47])?.*$" FAMILY_COMP ${COMP})
# Valid family component, so add it (e.g. STM32H7)
if(CMAKE_MATCH_1)
list(APPEND FreeRTOS_FIND_COMPONENTS_FAMILIES ${FAMILY_COMP})
continue()
endif()

# Was not a family component, so add it to the port list
list(APPEND FreeRTOS_FIND_COMPONENTS_PORTS ${COMP})
endforeach()

Expand All @@ -33,14 +54,19 @@ macro(stm32_find_freertos FreeRTOS_NAMESPACE FREERTOS_PATH)
find_path(FreeRTOS_COMMON_INCLUDE
NAMES FreeRTOS.h
PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS"
PATH_SUFFIXES "Source/include"
PATH_SUFFIXES "Source/include" "include"
NO_DEFAULT_PATH
)

if(NOT FreeRTOS_COMMON_INCLUDE)
message(WARNING "FreeRTOS common include path not found, build might fail")
endif()

list(APPEND FreeRTOS_INCLUDE_DIRS "${FreeRTOS_COMMON_INCLUDE}")

find_path(FreeRTOS_SOURCE_DIR
NAMES tasks.c
PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS"
PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS"
PATH_SUFFIXES "Source"
NO_DEFAULT_PATH
)
Expand Down Expand Up @@ -90,9 +116,18 @@ macro(stm32_find_freertos FreeRTOS_NAMESPACE FREERTOS_PATH)
find_path(FreeRTOS_${PORT}_PATH
NAMES portmacro.h
PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS"
PATH_SUFFIXES "Source/portable/GCC/${PORT}" "Source/portable/GCC/${PORT}/r0p1"
PATH_SUFFIXES
"portable/GCC/${PORT}/r0p1"
"portable/GCC/${PORT}"
"Source/portable/GCC/${PORT}"
"Source/portable/GCC/${PORT}/r0p1"
NO_DEFAULT_PATH
)

if(NOT FreeRTOS_${PORT}_PATH)
message(WARNING "FreeRTOS port path not found, build might fail")
endif()

list(APPEND FreeRTOS_INCLUDE_DIRS "${FreeRTOS_${PORT}_PATH}")

find_file(FreeRTOS_${PORT}_SOURCE
Expand All @@ -118,15 +153,16 @@ macro(stm32_find_freertos FreeRTOS_NAMESPACE FREERTOS_PATH)
endforeach()
endmacro()

message(STATUS "Search for FreeRTOS ports: ${FreeRTOS_FIND_COMPONENTS_PORTS}")

if(NOT FreeRTOS_FIND_COMPONENTS_FAMILIES)
if(NOT FREERTOS_PATH)
set(FREERTOS_PATH /opt/FreeRTOS CACHE PATH "Path to FreeRTOS")
message(STATUS "No FREERTOS_PATH specified using default: ${FREERTOS_PATH}")
message(STATUS "No FREERTOS_PATH specified, using default: ${FREERTOS_PATH}")
endif()
stm32_find_freertos(FreeRTOS ${FREERTOS_PATH})
else()
message(STATUS "Search for FreeRTOS families: ${FreeRTOS_FIND_COMPONENTS_FAMILIES}")
message(STATUS "Search for FreeRTOS ports: ${FreeRTOS_FIND_COMPONENTS_PORTS}")

foreach(COMP ${FreeRTOS_FIND_COMPONENTS_FAMILIES})
string(TOLOWER ${COMP} COMP_L)
Expand All @@ -140,10 +176,10 @@ else()

if(CMAKE_MATCH_2)
set(FAMILY ${CMAKE_MATCH_1})
set(DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
set(STM_DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
else()
set(FAMILY ${CMAKE_MATCH_1})
stm32_get_devices_by_family(DEVICES FAMILY ${FAMILY} CORE ${CORE})
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
endif()

if(CMAKE_MATCH_3)
Expand Down
5 changes: 5 additions & 0 deletions cmake/FindHAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES})
set(FAMILY ${CMAKE_MATCH_1})
string(TOLOWER ${FAMILY} FAMILY_L)

if((NOT STM32_HAL_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH) AND (DEFINED ENV{STM32_CUBE_${FAMILY}_PATH}))
set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "ENV STM32_CUBE_${FAMILY}_PATH specified, using STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
endif()

if((NOT STM32_HAL_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH))
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_HAL_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
Expand Down
Loading

0 comments on commit a642c5e

Please sign in to comment.