Skip to content

Commit 5b4edf6

Browse files
committed
7.3.3a
Cmake support
1 parent 9c903f8 commit 5b4edf6

File tree

13 files changed

+518
-258
lines changed

13 files changed

+518
-258
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# dpp
2+
3+
# use a recent CMake version
4+
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
5+
cmake_policy(SET CMP0083 NEW)
6+
7+
# first of all protect against in-source builds
8+
file(REAL_PATH "${CMAKE_SOURCE_DIR}" _srcdir)
9+
file(REAL_PATH "${CMAKE_BINARY_DIR}" _bindir)
10+
11+
if(${_srcdir} STREQUAL ${_bindir})
12+
message(FATAL_ERROR " FATAL: In-source builds are not allowed!
13+
You should create a separate directory for build files.")
14+
endif()
15+
unset(_srcdir)
16+
unset(_bindir)
17+
18+
# set up configurable options
19+
set(PROJECT_NAME dpp CACHE STRING "set to the project name of the qpc library project (default: QPC)")
20+
set(QPC_CFG_KERNEL QV CACHE STRING "set to the kernel to use (QV, QK, QXK) (default: QV)")
21+
set(QPC_SDK_PATH "${CMAKE_SOURCE_DIR}/../../.." CACHE STRING "set to the source path of QPC (default: ../../..)")
22+
23+
option(QPC_CFG_UNIT_TEST "set to ON, if Q_UTEST shall be enabled (default: OFF)" OFF)
24+
option(QPC_CFG_GUI "set to ON, if a Windows (TM) GUI shall be compiled in (default: ON)" OFF)
25+
option(QPC_CFG_VERBOSE "set to ON, to enable more verbosity. (default: OFF)" OFF)
26+
option(QPC_CFG_DEBUG "set to ON, to enable debug settings. (default: ON)" ON)
27+
28+
# update CMAKE_MODULE_PATH
29+
list(PREPEND CMAKE_MODULE_PATH ${QPC_SDK_PATH}/3rd_party/cmake ${CMAKE_SOURCE_DIR}/Source/cmake ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_SOURCE_DIR} ${HOME_PATH}/cmake)
30+
31+
# import QPC SDK; download from git, if necessary
32+
include(qpc_sdk_import)
33+
34+
if(NOT SW_VERSION)
35+
set(SW_VERSION "1.0.0" CACHE STRING "Software Version")
36+
endif()
37+
38+
project(
39+
${PROJECT_NAME}
40+
VERSION ${SW_VERSION}
41+
DESCRIPTION "Dining Philosophers Problem (dpp)"
42+
LANGUAGES C
43+
)
44+
45+
# add support for SPY configuration if not set via CMAKE_TOOLCHAIN_FILE
46+
if(NOT CMAKE_C_FLAGS_SPY)
47+
foreach(LANG IN ITEMS C CXX ASM)
48+
set(CMAKE_${LANG}_FLAGS_SPY "${CMAKE_${LANG}_FLAGS_DEBUG} -DQ_SPY")
49+
endforeach()
50+
endif()
51+
52+
include(CTest)
53+
include(CheckIncludeFile)
54+
include(CheckLibraryExists)
55+
56+
# the project main target
57+
set(TGT ${PROJECT_NAME})
58+
add_executable(${TGT})
59+
60+
# set position independent code compile/link parameters
61+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14")
62+
include(CheckPIESupported)
63+
check_pie_supported()
64+
set_property(TARGET ${TGT} PROPERTY POSITION_INDEPENDENT_CODE FALSE)
65+
endif()
66+
67+
# add the qpc library to the project
68+
qpc_sdk_init()
69+
70+
# check for plausible settings
71+
string(TOLOWER ${CMAKE_C_COMPILER_ID} _compiler_)
72+
string(TOLOWER ${QPC_CFG_PORT} PORT)
73+
if(NOT (PORT STREQUAL arm-cm AND _compiler_ STREQUAL gnu))
74+
message(FATAL_ERROR "'${QPC_CFG_PORT}'/'${CMAKE_C_COMPILER_ID}' not supported! Only 'arm-cm' port with GNU compiler is currently supported!")
75+
endif()
76+
77+
# add project specific setting to the library buiild
78+
target_compile_definitions(qpc PUBLIC
79+
STM32L053xx
80+
)
81+
82+
target_compile_options(qpc PUBLIC
83+
$<$<BOOL:${QPC_CFG_VERBOSE}>:-v>
84+
-mcpu=cortex-m0plus
85+
)
86+
87+
# the main target's sources
88+
target_sources(${TGT} PRIVATE
89+
$<LOWER_CASE:${QPC_CFG_KERNEL}>/bsp.c
90+
main.c
91+
philo.c
92+
table.c
93+
)
94+
95+
add_subdirectory(${QPC_SDK_PATH}/3rd_party/nucleo-l053r8 nucleo-l053r8)
96+
target_include_directories(dpp PRIVATE
97+
${CMAKE_CURRENT_SOURCE_DIR}
98+
)
99+
100+
target_compile_definitions(dpp PRIVATE
101+
STM32L053xx
102+
$<$<CONFIG:Spy>:Q_SPY>
103+
)
104+
105+
target_link_options(dpp PRIVATE
106+
$<$<BOOL:${QPC_CFG_VERBOSE}>:-v>
107+
-T${CMAKE_CURRENT_SOURCE_DIR}/$<LOWER_CASE:${QPC_CFG_KERNEL}>/${_compiler_}/dpp-$<LOWER_CASE:${QPC_CFG_KERNEL}>.ld
108+
-Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${TGT}.map
109+
-mcpu=cortex-m0plus
110+
)
111+
112+
# link the library with the application
113+
target_link_libraries(dpp PRIVATE
114+
qpc
115+
)
116+
117+
# show configuration results
118+
message(STATUS
119+
"Configured project ${PROJECT_NAME} for ${PORT}
120+
Configuration options set:
121+
PROJECT_NAME = ${QPC_PROJECT}
122+
SW_VERSION = ${SW_VERSION}
123+
124+
CONFIG_GUI = ${QPC_CFG_GUI}
125+
CONFIG_QSPY = ${QPC_CFG_QSPY}
126+
CONFIG_UNIT_TEST = ${QPC_CFG_UNIT_TEST}
127+
CONFIG_DEBUG = ${CONFIG_DEBUG}
128+
129+
QPC_CFG_KERNEL = ${QPC_CFG_KERNEL}
130+
QPC_DIR = ${QPC_DIR}"
131+
)
132+
133+
if(QPC_CFG_VERBOSE)
134+
message(STATUS
135+
" System information:
136+
CMAKE_VERSION = ${CMAKE_VERSION}
137+
CMAKE_CROSSCOMPILING = ${CMAKE_CROSSCOMPILING}
138+
CMAKE_HOST_SYSTEM = ${CMAKE_HOST_SYSTEM}
139+
CMAKE_HOST_SYSTEM_NAME = ${CMAKE_HOST_SYSTEM_NAME}
140+
CMAKE_HOST_LINUX = ${CMAKE_HOST_LINUX}
141+
CMAKE_HOST_UNIX = ${CMAKE_HOST_UNIX}
142+
CMAKE_HOST_WIN32 = ${CMAKE_HOST_WIN32}
143+
CMAKE_SYSTEM = ${CMAKE_SYSTEM}
144+
CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}
145+
CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}
146+
WIN32 = ${WIN32}
147+
MSYS = ${MSYS}
148+
MINGW = ${MINGW}
149+
UNIX = ${UNIX}
150+
LINUX = ${LINUX}
151+
152+
CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}
153+
CMAKE_CONFIGURATION_TYPES = ${CMAKE_CONFIGURATION_TYPES}
154+
155+
CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}
156+
CMAKE_C_COMPILER_ID = ${CMAKE_C_COMPILER_ID}
157+
CMAKE_C_COMPILER_VERSION = ${CMAKE_C_COMPILER_VERSION}
158+
CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}
159+
160+
CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}
161+
CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}
162+
163+
CMAKE_ASM_COMPILER = ${CMAKE_ASM_COMPILER}
164+
CMAKE_ASM_FLAGS = ${CMAKE_ASM_FLAGS}"
165+
)
166+
endif()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 23,
6+
"patch": 0
7+
},
8+
9+
"configurePresets": [
10+
{
11+
"name": "gen",
12+
"hidden": true,
13+
"generator": "Ninja Multi-Config",
14+
"cacheVariables": {
15+
"CMAKE_CONFIGURATION_TYPES": {
16+
"type": "STRING",
17+
"value": "Debug;Release;Spy"
18+
}
19+
}
20+
},
21+
{
22+
"name": "dpp",
23+
"displayName": "Nucleo L053r8 build",
24+
"description": "Build for ARM Cortex-M0+ on Nucleo L0538r8",
25+
"inherits": "gen",
26+
"toolchainFile": "${sourceDir}/../../../3rd_party/cmake/toolchain/tc_gnuarm.cmake",
27+
"binaryDir": "${sourceDir}/Build/arm"
28+
}
29+
],
30+
31+
"buildPresets": [
32+
{
33+
"name": "dpp",
34+
"configuration": "Debug",
35+
"configurePreset": "dpp"
36+
}
37+
]
38+
}

arm-cm/real-time_nucleo-l053r8/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ This example implements the "Periodic-Sporadic" application on the STM32 NUCLEO-
99
<b>STM32 NUCLEO-L053R8</b>
1010
</p>
1111

12+
> NOTE<br>
13+
The CPU is specifically clocked very slowly (only at 2 MHz) to better demonstrate all overheads and delays.
14+
1215
<p align="center">
1316
<img src="./real-time_trace.png"/><br>
1417
<b>Logic analyzer trace after pressing the button (QK kernel)</b>
@@ -22,24 +25,30 @@ examples\arm-cm\real-time_nucleo-l053r8
2225
| +---armclang // ARM/KEIL MDK with Compiler 6 (ARM/CLANG)
2326
| | rt-qk.uvprojx // uVision project
2427
|
25-
+---qv-ms // cooperative QV kernel (multi-stage tasks)
28+
+---qv // cooperative QV kernel
29+
| +---armclang // ARM/KEIL MDK with Compiler 6 (ARM/CLANG)
30+
| | rt-qv.uvprojx // uVision project
31+
|
32+
+---qv-ms // cooperative QV kernel (multi-stage threads)
2633
| +---armclang // ARM/KEIL MDK with Compiler 6 (ARM/CLANG)
2734
| | rt-qv-ms.uvprojx // uVision project
2835
|
2936
+---qv-tt // cooperative QV kernel (time-triggered)
3037
| +---armclang // ARM/KEIL MDK with Compiler 6 (ARM/CLANG)
3138
| | rt-qv-tt.uvprojx // uVision project
32-
3339
```
3440

3541
## Features Demonstrated
36-
The example QP application consists of 2 periodic threads (Active Objects) and two sporadic, lon-running threads (Active Objects). Additionally, the Time-Triggered (TT) version has a tt-schedulier thread.
42+
The example QP application consists of 2 periodic threads (Active Objects) and two sporadic, long-running threads (Active Objects). Additionally, the Time-Triggered (TT) version has a tt-scheduler thread.
3743

3844
- directory `qk`: preemptive run-to-completion QK kernel
3945

40-
- directory `qv-ms`: cooperative run-to-completion QV kernel with multi-stage tasks
46+
- directory `qv`: cooperative run-to-completion QV kernel with the same threads as QK
47+
48+
- directory `qv-ms`: cooperative run-to-completion QV kernel with multi-stage threads
49+
50+
- directory `qv-tt`: cooperative run-to-completion QV kernel with time-triggered threads
4151

42-
- directory `qv-tt`: cooperative run-to-completion QV kernel with time-triggered tasks
4352

4453
# Building the Examples
4554

0 commit comments

Comments
 (0)