Skip to content

Commit fc47e2d

Browse files
authored
Merge pull request #19 from fpistm/10.0.1
FreeRTOS v10.0.1 modified by ST
2 parents 5dc0465 + dc3f0aa commit fc47e2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+10691
-4758
lines changed

README.md

+37-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ This is a port of FreeRTOS for STM32 as Arduino libraries.
55
For more information about FreeRTOS, visit the [FreeRTOS Web Site](http://www.freertos.org/ "FreeRTOS").
66
Also, See the very useful [Getting Started](http://www.freertos.org/FreeRTOS-quick-start-guide.html "Quick Start Guide") page.
77

8-
Current FreeRTOS version used for this library is [9.0.0](http://www.freertos.org/FreeRTOS-V9.html) and has been modified by ST (See st_readme.txt in FreeRTOS Source).
8+
This library provides 2 FreeRTOS versions:
9+
* [9.0.0](http://www.freertos.org/FreeRTOS-V9.html)
10+
* [10.0.1](http://www.freertos.org/FreeRTOS-V10.html)
911

10-
This is the current one provided with the [STM32Cube MCU Packages](http://www.st.com/en/embedded-software/stm32cube-mcu-packages.html)
12+
Both have been modified by ST (See st_readme.txt in FreeRTOS Source).
13+
14+
These are the same provided with the [STM32Cube MCU Packages](http://www.st.com/en/embedded-software/stm32cube-mcu-packages.html)
1115

1216
## Configuration
1317

@@ -17,11 +21,13 @@ This library provides a default FreeRTOS configuration file named `FreeRTOSConfi
1721

1822
User can provide his own FreeRTOS configuration file at sketch level by adding his configuration in a file named `STM32FreeRTOSConfig.h`.
1923

24+
Or add extra FreeRTOS configuration to the default at sketch level by adding an extra configuration in a file named `STM32FreeRTOSConfig_extra.h`.
25+
2026
Heap allocation schemes are provided by FreeRTOS, see [Memory allocation implementations included in the RTOS source](https://www.freertos.org/a00111.html).
2127
To extend those schemes a thread-safe heap allocation using C runtime (Newlib) has been added based on Dave Nadler work:
2228

2329
http://www.nadler.com/embedded/newlibAndFreeRTOS.html
24-
30+
2531
By default, the `heap_useNewlib.c` is used. It can be changed thanks a define in the configuration file:
2632
```
2733
/* Define memory allocation implementations to use:
@@ -31,24 +37,51 @@ By default, the `heap_useNewlib.c` is used. It can be changed thanks a define in
3137
*/
3238
```
3339

40+
Since v10.0.1, CMSIS-RTOSv2 can be used instead of default CMSIS-RTOS.
41+
42+
`configUSE_CMSIS_RTOS_V2` has to be defined and set to `1` to use
43+
CMSIS-RTOSv2.
44+
45+
3446
## Limitations
3547

3648
* MPU: not supported.
49+
* No CMSIS-RTOSv2 support provided. It is provided as example.
3750

3851
## Files & Configuration
3952

4053
* STM32FreeRTOS.h : Must always be #include first. It references required include files.
4154
* STM32FreeRTOSConfig.h : If exist at sketch level, it contains the FreeRTOS configurations.
55+
* STM32FreeRTOSConfig_extra.h : If exist at sketch level, it contains extra FreeRTOS configurations.
4256
* FreeRTOSConfig_Default.h : Contains the default FreeRTOS configurations for this STM32 port if `STM32FreeRTOSConfig.h` doesn't exist.
4357

4458
## Test results (using [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32))
59+
60+
### STM32FreeRTOS v9.0.x
4561
| Board | AnalogRead_DigitalRead | Blink_AnalogRead | frBlink | frBlinkPrint | frJitter | frLiuLayland |
4662
| --- | :---: | :---: | :---: | :---: | :---: | :---: |
4763
| [Nucleo F091RC](http://www.st.com/en/evaluation-tools/nucleo-f091rc.html) | PASSED | PASSED | PASSED | PASSED | PASSED | FAILED |
4864
| [Nucleo F103RB](http://www.st.com/en/evaluation-tools/nucleo-f103rb.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
4965
| [Nucleo F303RE](http://www.st.com/en/evaluation-tools/nucleo-f303re.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
5066
| [Nucleo F429ZI](http://www.st.com/en/evaluation-tools/nucleo-f429zi.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
5167
| [STM32F746G-DISCOVERY](http://www.st.com/en/evaluation-tools/32f746gdiscovery.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
52-
| [Nucleo L053R8](http://www.st.com/en/evaluation-tools/nucleo-l053r8.html) | PASSED | PASSED | PASSED | PASSED | PASSED | FAILED |
68+
| [Nucleo L053R8](http://www.st.com/en/evaluation-tools/nucleo-l053r8.html) | PASSED* | PASSED* | PASSED* | PASSED* | PASSED* | FAILED |
5369
| [Nucleo L152RE](http://www.st.com/en/evaluation-tools/nucleo-l152re.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
5470
| [B-L475E-IOT01A](http://www.st.com/en/evaluation-tools/b-l475e-iot01a.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
71+
72+
### STM32FreeRTOS v10.0.x
73+
| Board | AnalogRead_DigitalRead | frBlinkPrint | frLiuLayland | frBlink (CMSIS-RTOSv2) | Blinky (CMSIS-RTOSv2) |
74+
| --- | :---: | :---: | :---: | :---: | :---: |
75+
| [Nucleo F091RC](http://www.st.com/en/evaluation-tools/nucleo-f091rc.html) | PASSED | PASSED | FAILED | PASSED | PASSED |
76+
| [Nucleo F103RB](http://www.st.com/en/evaluation-tools/nucleo-f103rb.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
77+
| [Nucleo F303RE](http://www.st.com/en/evaluation-tools/nucleo-f303re.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
78+
| [Nucleo F429ZI](http://www.st.com/en/evaluation-tools/nucleo-f429zi.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
79+
| [STM32F746G-DISCOVERY](http://www.st.com/en/evaluation-tools/32f746gdiscovery.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
80+
| [Nucleo-G071RB](https://www.st.com/en/evaluation-tools/nucleo-g071rb.html) | PASSED | PASSED | FAILED | PASSED | PASSED |
81+
| [Nucleo H743ZI](https://www.st.com/en/evaluation-tools/nucleo-h743zi.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
82+
| [Nucleo L053R8](http://www.st.com/en/evaluation-tools/nucleo-l053r8.html) | PASSED* | PASSED* | FAILED | PASSED | PASSED |
83+
| [Nucleo L152RE](http://www.st.com/en/evaluation-tools/nucleo-l152re.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
84+
| [B-L475E-IOT01A](http://www.st.com/en/evaluation-tools/b-l475e-iot01a.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
85+
| [P-Nucleo-WB55RG](https://www.st.com/en/evaluation-tools/p-nucleo-wb55.html) | PASSED | PASSED | FAILED | PASSED | PASSED |
86+
87+
\* PASSED with `configUSE_NEWLIB_REENTRANT` set to 0 due to small RAM.
+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/* --------------------------------------------------------------------------
2+
* Original code from:
3+
* https://github.com/ARM-software/CMSIS-FreeRTOS/tree/develop/CMSIS/RTOS2/FreeRTOS/Examples/Blinky
4+
*
5+
* Copyright (c) 2013-2017 ARM Limited. All rights reserved.
6+
*
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the License); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*
21+
* Original name: Blinky.c
22+
* OriginalPurpose: RTOS2 example program
23+
************************************************
24+
* Abstract.txt:
25+
* The Blinky project is a simple CMSIS RTOS2 Kernel based example
26+
* for a simulated Cortex-M3 device.
27+
* The example simulates the step-motor driver. Four phase variables are
28+
* simulating the activation of the four output driver stages. The state
29+
* changes are output on the Watch window variable g_phases:
30+
* - phase A
31+
* - phase B
32+
* - phase C
33+
* - phase D
34+
*
35+
* This example simulates Half step driver mode and CW rotation direction.
36+
*
37+
* The Blinky example program is available for one target:
38+
*
39+
* Simulation: configured for a simulated on-chip Flash
40+
************************************************
41+
* Updated to STM32FreeRTOS example
42+
*---------------------------------------------------------------------------*/
43+
44+
#include <STM32FreeRTOS.h>
45+
46+
osThreadId_t tid_phaseA; /* Thread id of thread: phase_a */
47+
osThreadId_t tid_phaseB; /* Thread id of thread: phase_b */
48+
osThreadId_t tid_phaseC; /* Thread id of thread: phase_c */
49+
osThreadId_t tid_phaseD; /* Thread id of thread: phase_d */
50+
osThreadId_t tid_clock; /* Thread id of thread: clock */
51+
52+
struct phases_t {
53+
int_fast8_t phaseA;
54+
int_fast8_t phaseB;
55+
int_fast8_t phaseC;
56+
int_fast8_t phaseD;
57+
} g_phases;
58+
59+
60+
/*----------------------------------------------------------------------------
61+
* Function 'signal_func' called from multiple threads
62+
*---------------------------------------------------------------------------*/
63+
void signal_func (osThreadId_t tid) {
64+
osThreadFlagsSet(tid_clock, 0x0100); /* set signal to clock thread */
65+
osDelay(500); /* delay 500ms */
66+
osThreadFlagsSet(tid_clock, 0x0100); /* set signal to clock thread */
67+
osDelay(500); /* delay 500ms */
68+
osThreadFlagsSet(tid, 0x0001); /* set signal to thread 'thread' */
69+
osDelay(500); /* delay 500ms */
70+
}
71+
72+
/*----------------------------------------------------------------------------
73+
* Thread 1 'phaseA': Phase A output
74+
*---------------------------------------------------------------------------*/
75+
void phaseA (void */*argument*/) {
76+
for (;;) {
77+
osThreadFlagsWait(0x0001, osFlagsWaitAny ,osWaitForever); /* wait for an event flag 0x0001 */
78+
g_phases.phaseA = 1;
79+
digitalToggle(LED_BUILTIN);
80+
signal_func(tid_phaseB); /* call common signal function */
81+
g_phases.phaseA = 0;
82+
}
83+
}
84+
85+
/*----------------------------------------------------------------------------
86+
* Thread 2 'phaseB': Phase B output
87+
*---------------------------------------------------------------------------*/
88+
void phaseB (void */*argument*/) {
89+
for (;;) {
90+
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0001 */
91+
g_phases.phaseB = 1;
92+
digitalToggle(LED_BUILTIN);
93+
signal_func(tid_phaseC); /* call common signal function */
94+
g_phases.phaseB = 0;
95+
}
96+
}
97+
98+
/*----------------------------------------------------------------------------
99+
* Thread 3 'phaseC': Phase C output
100+
*---------------------------------------------------------------------------*/
101+
void phaseC (void */*argument*/) {
102+
for (;;) {
103+
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0001 */
104+
g_phases.phaseC = 1;
105+
digitalToggle(LED_BUILTIN);
106+
signal_func(tid_phaseD); /* call common signal function */
107+
g_phases.phaseC = 0;
108+
}
109+
}
110+
111+
/*----------------------------------------------------------------------------
112+
* Thread 4 'phaseD': Phase D output
113+
*---------------------------------------------------------------------------*/
114+
void phaseD (void */*argument*/) {
115+
for (;;) {
116+
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0001 */
117+
g_phases.phaseD = 1;
118+
digitalToggle(LED_BUILTIN);
119+
signal_func(tid_phaseA); /* call common signal function */
120+
g_phases.phaseD = 0;
121+
}
122+
}
123+
124+
/*----------------------------------------------------------------------------
125+
* Thread 5 'clock': Signal Clock
126+
*---------------------------------------------------------------------------*/
127+
void clock (void */*argument*/) {
128+
for (;;) {
129+
osThreadFlagsWait(0x0100, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0100 */
130+
osDelay(80); /* delay 80ms */
131+
}
132+
}
133+
134+
/*----------------------------------------------------------------------------
135+
* Main: Initialize and start the application
136+
*---------------------------------------------------------------------------*/
137+
void app_main (void */*argument*/) {
138+
139+
tid_phaseA = osThreadNew(phaseA, NULL, NULL);
140+
tid_phaseB = osThreadNew(phaseB, NULL, NULL);
141+
tid_phaseC = osThreadNew(phaseC, NULL, NULL);
142+
tid_phaseD = osThreadNew(phaseD, NULL, NULL);
143+
tid_clock = osThreadNew(clock, NULL, NULL);
144+
145+
osThreadFlagsSet(tid_phaseA, 0x0001); /* set signal to phaseA thread */
146+
147+
osDelay(osWaitForever);
148+
while(1);
149+
}
150+
151+
/*----------------------------------------------------------------------------
152+
* Main: Initialize and start the RTOS2 Kernel
153+
*---------------------------------------------------------------------------*/
154+
void setup() {
155+
pinMode(LED_BUILTIN, OUTPUT);
156+
157+
osKernelInitialize(); // Initialize CMSIS-RTOS
158+
osThreadNew(app_main, NULL, NULL); // Create application main thread
159+
if (osKernelGetState() == osKernelReady) {
160+
osKernelStart(); // Start thread execution
161+
}
162+
163+
while(1);
164+
}
165+
166+
//------------------------------------------------------------------------------
167+
// loop must never block
168+
void loop() {
169+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define configUSE_CMSIS_RTOS_V2 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define configUSE_CMSIS_RTOS_V2 1
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* --------------------------------------------------------------------------
2+
Simple LED blink example using CMS-RTOSv2
3+
---------------------------------------------------------------------------*/
4+
5+
#include <STM32FreeRTOS.h>
6+
7+
osThreadId_t tid_ledOn; /* Thread id of thread: ledOn */
8+
osThreadId_t tid_ledOff; /* Thread id of thread: ledOff */
9+
10+
//Thread 1
11+
void ledOn(void */*argument*/) {
12+
for (;;) {
13+
digitalToggle(LED_BUILTIN);
14+
osThreadFlagsSet(tid_ledOff, 0x0001);
15+
//signal ledOffthread
16+
osDelay(500);
17+
}
18+
}
19+
20+
// Thread 2
21+
void ledOff(void */*argument*/) {
22+
for (;;) {
23+
// wait for signal from ledOnthread
24+
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever) ;
25+
osDelay(1000);
26+
digitalToggle(LED_BUILTIN);
27+
}
28+
}
29+
30+
/*----------------------------------------------------------------------------
31+
Main: Initialize and start the application
32+
---------------------------------------------------------------------------*/
33+
void app_main (void */*argument*/) {
34+
35+
tid_ledOn = osThreadNew(ledOn, NULL, NULL);
36+
tid_ledOff = osThreadNew(ledOff, NULL, NULL);
37+
38+
osDelay(osWaitForever);
39+
while (1);
40+
}
41+
42+
/*----------------------------------------------------------------------------
43+
Main: Initialize and start the RTOS2 Kernel
44+
---------------------------------------------------------------------------*/
45+
void setup() {
46+
pinMode(LED_BUILTIN, OUTPUT);
47+
48+
osKernelInitialize(); // Initialize CMSIS-RTOS
49+
osThreadNew(app_main, NULL, NULL); // Create application main thread
50+
if (osKernelGetState() == osKernelReady) {
51+
osKernelStart(); // Start thread execution
52+
}
53+
54+
while (1);
55+
}
56+
57+
//------------------------------------------------------------------------------
58+
// loop must never block
59+
void loop() {
60+
}

library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "STM32duino FreeRTOS",
3-
"version": "9.0.4",
3+
"version": "10.0.1",
44
"keywords": "rtos, timing, thread, task, mutex, semaphore",
55
"description": "Real Time Operating System implemented for STM32",
66
"repository": {

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino FreeRTOS
2-
version=9.0.4
2+
version=10.0.1
33
author=Richard Barry <[email protected]>
44
maintainer=stm32duino
55
sentence=Real Time Operating System implemented for STM32

src/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.c renamed to portable/CMSIS_RTOS/cmsis_os.c

+1-47
Original file line numberDiff line numberDiff line change
@@ -53,49 +53,6 @@
5353
* POSSIBILITY OF SUCH DAMAGE.
5454
*---------------------------------------------------------------------------*/
5555

56-
/**
57-
******************************************************************************
58-
* @file cmsis_os.c
59-
* @author MCD Application Team
60-
* @date 13-July-2017
61-
* @brief CMSIS-RTOS API implementation for FreeRTOS V9.0.0
62-
******************************************************************************
63-
* @attention
64-
*
65-
* Redistribution and use in source and binary forms, with or without
66-
* modification, are permitted, provided that the following conditions are met:
67-
*
68-
* 1. Redistribution of source code must retain the above copyright notice,
69-
* this list of conditions and the following disclaimer.
70-
* 2. Redistributions in binary form must reproduce the above copyright notice,
71-
* this list of conditions and the following disclaimer in the documentation
72-
* and/or other materials provided with the distribution.
73-
* 3. Neither the name of STMicroelectronics nor the names of other
74-
* contributors to this software may be used to endorse or promote products
75-
* derived from this software without specific written permission.
76-
* 4. This software, including modifications and/or derivative works of this
77-
* software, must execute solely and exclusively on microcontroller or
78-
* microprocessor devices manufactured by or for STMicroelectronics.
79-
* 5. Redistribution and use of this software other than as permitted under
80-
* this license is void and will automatically terminate your rights under
81-
* this license.
82-
*
83-
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
84-
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
85-
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
86-
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
87-
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
88-
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
89-
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
90-
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
91-
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
92-
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
93-
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
94-
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95-
*
96-
******************************************************************************
97-
*/
98-
9956
#include <string.h>
10057
#include "cmsis_os.h"
10158

@@ -991,10 +948,7 @@ void *osPoolAlloc (osPoolId pool_id)
991948
}
992949

993950
for (i = 0; i < pool_id->pool_sz; i++) {
994-
index = pool_id->currentIndex + i;
995-
if (index >= pool_id->pool_sz) {
996-
index = 0;
997-
}
951+
index = (pool_id->currentIndex + i) % pool_id->pool_sz;
998952

999953
if (pool_id->markers[index] == 0) {
1000954
pool_id->markers[index] = 1;

0 commit comments

Comments
 (0)