Skip to content

Commit c8424b7

Browse files
committed
Manage CMSIS_RTOS versions
Move CMSIS_RTOS* to portable. Add source and header files wrappers. Add new custom definition to use CMSIS-RTOSv2. Important note: no support will be provided for this configuration. Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent fafe24e commit c8424b7

File tree

9 files changed

+73
-8
lines changed

9 files changed

+73
-8
lines changed

src/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c renamed to portable/CMSIS_RTOS_V2/cmsis_os2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static HeapRegion_t xHeapRegions[] = {
118118
/* FreeRTOS tick timer interrupt handler prototype */
119119
extern void xPortSysTickHandler (void);
120120

121+
/* SysTick handler implementation done in the core and call osSystickHandler */
122+
#ifndef ARDUINO_ARCH_STM32
121123
/*
122124
SysTick handler implementation that also clears overflow flag.
123125
*/
@@ -128,6 +130,7 @@ void SysTick_Handler (void) {
128130
/* Call tick handler */
129131
xPortSysTickHandler();
130132
}
133+
#endif
131134
#endif /* SysTick */
132135

133136
/*---------------------------------------------------------------------------*/

src/FreeRTOSConfig_Default.h

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,63 @@
4848
* Default -1 see heap.c
4949
*/
5050
/*#define configMEMMANG_HEAP_NB 3*/
51+
52+
/* configUSE_CMSIS_RTOS_V2 has to be defined and set to 1 to use CMSIS-RTOSv2 */
53+
/*#define configUSE_CMSIS_RTOS_V2 1*/
54+
5155
/* End custom definitions for STM32 */
5256

5357
/* Ensure stdint is only used by the compiler, and not the assembler. */
5458
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
5559
#include <stdint.h>
5660
extern uint32_t SystemCoreClock;
5761
#endif
62+
63+
#if defined(configUSE_CMSIS_RTOS_V2) && (configUSE_CMSIS_RTOS_V2 == 1)
64+
/*------------- CMSIS-RTOS V2 specific defines -----------*/
65+
/* When using CMSIS-RTOSv2 set configSUPPORT_STATIC_ALLOCATION to 1
66+
* is mandatory to avoid compile errors.
67+
* CMSIS-RTOS V2 implmentation requires the following defines
68+
*/
69+
/* cmsis_os threads are created using xTaskCreateStatic() API */
70+
#define configSUPPORT_STATIC_ALLOCATION 1
71+
/* CMSIS-RTOSv2 defines 56 levels of priorities. To be able to use them
72+
* all and avoid application misbehavior, configUSE_PORT_OPTIMISED_TASK_SELECTION
73+
* must be set to 0 and configMAX_PRIORITIES to 56
74+
*
75+
*/
76+
#define configMAX_PRIORITIES (56)
77+
/*
78+
* When set to 1, configMAX_PRIORITIES can't be more than 32
79+
* which is not suitable for the new CMSIS-RTOS v2 priority range
80+
*/
81+
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
82+
83+
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
84+
#define configTOTAL_HEAP_SIZE ((size_t)(15 * 1024))
85+
86+
#else
5887
extern char _end; /* Defined in the linker script */
5988
extern char _estack; /* Defined in the linker script */
6089
extern char _Min_Stack_Size; /* Defined in the linker script */
6190

62-
#define configUSE_PREEMPTION 1
63-
#define configUSE_IDLE_HOOK 1
64-
#define configUSE_TICK_HOOK 1
65-
#define configCPU_CLOCK_HZ (SystemCoreClock)
66-
#define configTICK_RATE_HZ ((TickType_t)1000)
6791
#define configMAX_PRIORITIES (7)
92+
6893
/*
6994
* _Min_Stack_Size is often set to 0x400 in the linker script
7095
* Use it divided by 8 to set minmimal stack size of a task to 128 by default.
7196
* End user will have to properly configure those value depending to their needs.
7297
*/
7398
#define configMINIMAL_STACK_SIZE ((uint16_t)((uint32_t)&_Min_Stack_Size/8))
7499
#define configTOTAL_HEAP_SIZE ((size_t)(&_estack - _Min_Stack_Size - &_end))
100+
101+
#endif /* configUSE_CMSIS_RTOS_V2 */
102+
103+
#define configUSE_PREEMPTION 1
104+
#define configUSE_IDLE_HOOK 1
105+
#define configUSE_TICK_HOOK 1
106+
#define configCPU_CLOCK_HZ (SystemCoreClock)
107+
#define configTICK_RATE_HZ ((TickType_t)1000)
75108
#define configMAX_TASK_NAME_LEN (16)
76109
#define configUSE_TRACE_FACILITY 1
77110
#define configUSE_16_BIT_TICKS 0
@@ -154,9 +187,18 @@ header file. */
154187
#define vPortSVCHandler SVC_Handler
155188
#define xPortPendSVHandler PendSV_Handler
156189

157-
/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware,
158-
to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
190+
/*
191+
* IMPORTANT:
192+
* osSystickHandler is called in the core SysTick_Handler definition
193+
* and is defined as weak.
194+
* For CMSIS-RTOSv2: osSystickHandler is defined as xPortSysTickHandler
195+
* For CMSIS-RTOS: osSystickHandler is defined by the cmsis_os and xPortSysTickHandler
196+
* must not be defined to prevent overwriting SysTick_Handler
197+
*/
159198
/* #define xPortSysTickHandler SysTick_Handler */
199+
#if defined(configUSE_CMSIS_RTOS_V2) && (configUSE_CMSIS_RTOS_V2 == 1)
200+
#define xPortSysTickHandler osSystickHandler
201+
#endif
160202

161203
#endif /* FREERTOS_CONFIG_H */
162204

src/cmsis_os.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* @file cmsis_os.c
3+
* @author Frederic Pillon <frederic.pillon@st.com> for STMicroelectronics.
4+
* @brief Include source of FreeRTOS portable layer file to match Arduino library format
5+
*/
6+
#include "FreeRTOS.h"
7+
8+
#if !defined(configUSE_CMSIS_RTOS_V2) || (configUSE_CMSIS_RTOS_V2 == 0)
9+
#include "../portable/CMSIS_RTOS/cmsis_os.c"
10+
#else
11+
#include "../portable/CMSIS_RTOS_V2/cmsis_os1.c"
12+
#include "../portable/CMSIS_RTOS_V2/cmsis_os2.c"
13+
#endif
14+

src/cmsis_os.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#ifndef _ARDUINO_CMSIS_OS_H_
77
#define _ARDUINO_CMSIS_OS_H_
88

9-
#include "FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h"
9+
#include "FreeRTOS.h"
10+
11+
#if !defined(configUSE_CMSIS_RTOS_V2) || (configUSE_CMSIS_RTOS_V2 == 0)
12+
#include "../portable/CMSIS_RTOS/cmsis_os.h"
13+
#else
14+
#include "../portable/CMSIS_RTOS_V2/cmsis_os.h"
15+
#endif
1016

1117
#endif //_ARDUINO_CMSIS_OS_H_

0 commit comments

Comments
 (0)