Skip to content

FreeRTOS v10.0.1 modified by ST #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ This is a port of FreeRTOS for STM32 as Arduino libraries.
For more information about FreeRTOS, visit the [FreeRTOS Web Site](http://www.freertos.org/ "FreeRTOS").
Also, See the very useful [Getting Started](http://www.freertos.org/FreeRTOS-quick-start-guide.html "Quick Start Guide") page.

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).
This library provides 2 FreeRTOS versions:
* [9.0.0](http://www.freertos.org/FreeRTOS-V9.html)
* [10.0.1](http://www.freertos.org/FreeRTOS-V10.html)

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

These are the same provided with the [STM32Cube MCU Packages](http://www.st.com/en/embedded-software/stm32cube-mcu-packages.html)

## Configuration

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

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

Or add extra FreeRTOS configuration to the default at sketch level by adding an extra configuration in a file named `STM32FreeRTOSConfig_extra.h`.

Heap allocation schemes are provided by FreeRTOS, see [Memory allocation implementations included in the RTOS source](https://www.freertos.org/a00111.html).
To extend those schemes a thread-safe heap allocation using C runtime (Newlib) has been added based on Dave Nadler work:

http://www.nadler.com/embedded/newlibAndFreeRTOS.html

By default, the `heap_useNewlib.c` is used. It can be changed thanks a define in the configuration file:
```
/* Define memory allocation implementations to use:
Expand All @@ -31,24 +37,51 @@ By default, the `heap_useNewlib.c` is used. It can be changed thanks a define in
*/
```

Since v10.0.1, CMSIS-RTOSv2 can be used instead of default CMSIS-RTOS.

`configUSE_CMSIS_RTOS_V2` has to be defined and set to `1` to use
CMSIS-RTOSv2.


## Limitations

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

## Files & Configuration

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

## Test results (using [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32))

### STM32FreeRTOS v9.0.x
| Board | AnalogRead_DigitalRead | Blink_AnalogRead | frBlink | frBlinkPrint | frJitter | frLiuLayland |
| --- | :---: | :---: | :---: | :---: | :---: | :---: |
| [Nucleo F091RC](http://www.st.com/en/evaluation-tools/nucleo-f091rc.html) | PASSED | PASSED | PASSED | PASSED | PASSED | FAILED |
| [Nucleo F103RB](http://www.st.com/en/evaluation-tools/nucleo-f103rb.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
| [Nucleo F303RE](http://www.st.com/en/evaluation-tools/nucleo-f303re.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
| [Nucleo F429ZI](http://www.st.com/en/evaluation-tools/nucleo-f429zi.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
| [STM32F746G-DISCOVERY](http://www.st.com/en/evaluation-tools/32f746gdiscovery.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
| [Nucleo L053R8](http://www.st.com/en/evaluation-tools/nucleo-l053r8.html) | PASSED | PASSED | PASSED | PASSED | PASSED | FAILED |
| [Nucleo L053R8](http://www.st.com/en/evaluation-tools/nucleo-l053r8.html) | PASSED* | PASSED* | PASSED* | PASSED* | PASSED* | FAILED |
| [Nucleo L152RE](http://www.st.com/en/evaluation-tools/nucleo-l152re.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |
| [B-L475E-IOT01A](http://www.st.com/en/evaluation-tools/b-l475e-iot01a.html) | PASSED | PASSED | PASSED | PASSED | PASSED | PASSED |

### STM32FreeRTOS v10.0.x
| Board | AnalogRead_DigitalRead | frBlinkPrint | frLiuLayland | frBlink (CMSIS-RTOSv2) | Blinky (CMSIS-RTOSv2) |
| --- | :---: | :---: | :---: | :---: | :---: |
| [Nucleo F091RC](http://www.st.com/en/evaluation-tools/nucleo-f091rc.html) | PASSED | PASSED | FAILED | PASSED | PASSED |
| [Nucleo F103RB](http://www.st.com/en/evaluation-tools/nucleo-f103rb.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
| [Nucleo F303RE](http://www.st.com/en/evaluation-tools/nucleo-f303re.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
| [Nucleo F429ZI](http://www.st.com/en/evaluation-tools/nucleo-f429zi.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
| [STM32F746G-DISCOVERY](http://www.st.com/en/evaluation-tools/32f746gdiscovery.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
| [Nucleo-G071RB](https://www.st.com/en/evaluation-tools/nucleo-g071rb.html) | PASSED | PASSED | FAILED | PASSED | PASSED |
| [Nucleo H743ZI](https://www.st.com/en/evaluation-tools/nucleo-h743zi.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
| [Nucleo L053R8](http://www.st.com/en/evaluation-tools/nucleo-l053r8.html) | PASSED* | PASSED* | FAILED | PASSED | PASSED |
| [Nucleo L152RE](http://www.st.com/en/evaluation-tools/nucleo-l152re.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
| [B-L475E-IOT01A](http://www.st.com/en/evaluation-tools/b-l475e-iot01a.html) | PASSED | PASSED | PASSED | PASSED | PASSED |
| [P-Nucleo-WB55RG](https://www.st.com/en/evaluation-tools/p-nucleo-wb55.html) | PASSED | PASSED | FAILED | PASSED | PASSED |

\* PASSED with `configUSE_NEWLIB_REENTRANT` set to 0 due to small RAM.
169 changes: 169 additions & 0 deletions examples/CMSIS-RTOSv2/Blinky/Blinky.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/* --------------------------------------------------------------------------
* Original code from:
* https://github.com/ARM-software/CMSIS-FreeRTOS/tree/develop/CMSIS/RTOS2/FreeRTOS/Examples/Blinky
*
* Copyright (c) 2013-2017 ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Original name: Blinky.c
* OriginalPurpose: RTOS2 example program
************************************************
* Abstract.txt:
* The Blinky project is a simple CMSIS RTOS2 Kernel based example
* for a simulated Cortex-M3 device.
* The example simulates the step-motor driver. Four phase variables are
* simulating the activation of the four output driver stages. The state
* changes are output on the Watch window variable g_phases:
* - phase A
* - phase B
* - phase C
* - phase D
*
* This example simulates Half step driver mode and CW rotation direction.
*
* The Blinky example program is available for one target:
*
* Simulation: configured for a simulated on-chip Flash
************************************************
* Updated to STM32FreeRTOS example
*---------------------------------------------------------------------------*/

#include <STM32FreeRTOS.h>

osThreadId_t tid_phaseA; /* Thread id of thread: phase_a */
osThreadId_t tid_phaseB; /* Thread id of thread: phase_b */
osThreadId_t tid_phaseC; /* Thread id of thread: phase_c */
osThreadId_t tid_phaseD; /* Thread id of thread: phase_d */
osThreadId_t tid_clock; /* Thread id of thread: clock */

struct phases_t {
int_fast8_t phaseA;
int_fast8_t phaseB;
int_fast8_t phaseC;
int_fast8_t phaseD;
} g_phases;


/*----------------------------------------------------------------------------
* Function 'signal_func' called from multiple threads
*---------------------------------------------------------------------------*/
void signal_func (osThreadId_t tid) {
osThreadFlagsSet(tid_clock, 0x0100); /* set signal to clock thread */
osDelay(500); /* delay 500ms */
osThreadFlagsSet(tid_clock, 0x0100); /* set signal to clock thread */
osDelay(500); /* delay 500ms */
osThreadFlagsSet(tid, 0x0001); /* set signal to thread 'thread' */
osDelay(500); /* delay 500ms */
}

/*----------------------------------------------------------------------------
* Thread 1 'phaseA': Phase A output
*---------------------------------------------------------------------------*/
void phaseA (void */*argument*/) {
for (;;) {
osThreadFlagsWait(0x0001, osFlagsWaitAny ,osWaitForever); /* wait for an event flag 0x0001 */
g_phases.phaseA = 1;
digitalToggle(LED_BUILTIN);
signal_func(tid_phaseB); /* call common signal function */
g_phases.phaseA = 0;
}
}

/*----------------------------------------------------------------------------
* Thread 2 'phaseB': Phase B output
*---------------------------------------------------------------------------*/
void phaseB (void */*argument*/) {
for (;;) {
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0001 */
g_phases.phaseB = 1;
digitalToggle(LED_BUILTIN);
signal_func(tid_phaseC); /* call common signal function */
g_phases.phaseB = 0;
}
}

/*----------------------------------------------------------------------------
* Thread 3 'phaseC': Phase C output
*---------------------------------------------------------------------------*/
void phaseC (void */*argument*/) {
for (;;) {
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0001 */
g_phases.phaseC = 1;
digitalToggle(LED_BUILTIN);
signal_func(tid_phaseD); /* call common signal function */
g_phases.phaseC = 0;
}
}

/*----------------------------------------------------------------------------
* Thread 4 'phaseD': Phase D output
*---------------------------------------------------------------------------*/
void phaseD (void */*argument*/) {
for (;;) {
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0001 */
g_phases.phaseD = 1;
digitalToggle(LED_BUILTIN);
signal_func(tid_phaseA); /* call common signal function */
g_phases.phaseD = 0;
}
}

/*----------------------------------------------------------------------------
* Thread 5 'clock': Signal Clock
*---------------------------------------------------------------------------*/
void clock (void */*argument*/) {
for (;;) {
osThreadFlagsWait(0x0100, osFlagsWaitAny, osWaitForever); /* wait for an event flag 0x0100 */
osDelay(80); /* delay 80ms */
}
}

/*----------------------------------------------------------------------------
* Main: Initialize and start the application
*---------------------------------------------------------------------------*/
void app_main (void */*argument*/) {

tid_phaseA = osThreadNew(phaseA, NULL, NULL);
tid_phaseB = osThreadNew(phaseB, NULL, NULL);
tid_phaseC = osThreadNew(phaseC, NULL, NULL);
tid_phaseD = osThreadNew(phaseD, NULL, NULL);
tid_clock = osThreadNew(clock, NULL, NULL);

osThreadFlagsSet(tid_phaseA, 0x0001); /* set signal to phaseA thread */

osDelay(osWaitForever);
while(1);
}

/*----------------------------------------------------------------------------
* Main: Initialize and start the RTOS2 Kernel
*---------------------------------------------------------------------------*/
void setup() {
pinMode(LED_BUILTIN, OUTPUT);

osKernelInitialize(); // Initialize CMSIS-RTOS
osThreadNew(app_main, NULL, NULL); // Create application main thread
if (osKernelGetState() == osKernelReady) {
osKernelStart(); // Start thread execution
}

while(1);
}

//------------------------------------------------------------------------------
// loop must never block
void loop() {
}
1 change: 1 addition & 0 deletions examples/CMSIS-RTOSv2/Blinky/STM32FreeRTOSConfig_extra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define configUSE_CMSIS_RTOS_V2 1
1 change: 1 addition & 0 deletions examples/CMSIS-RTOSv2/frBlink/STM32FreeRTOSConfig_extra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define configUSE_CMSIS_RTOS_V2 1
60 changes: 60 additions & 0 deletions examples/CMSIS-RTOSv2/frBlink/frBlink.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* --------------------------------------------------------------------------
Simple LED blink example using CMS-RTOSv2
---------------------------------------------------------------------------*/

#include <STM32FreeRTOS.h>

osThreadId_t tid_ledOn; /* Thread id of thread: ledOn */
osThreadId_t tid_ledOff; /* Thread id of thread: ledOff */

//Thread 1
void ledOn(void */*argument*/) {
for (;;) {
digitalToggle(LED_BUILTIN);
osThreadFlagsSet(tid_ledOff, 0x0001);
//signal ledOffthread
osDelay(500);
}
}

// Thread 2
void ledOff(void */*argument*/) {
for (;;) {
// wait for signal from ledOnthread
osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever) ;
osDelay(1000);
digitalToggle(LED_BUILTIN);
}
}

/*----------------------------------------------------------------------------
Main: Initialize and start the application
---------------------------------------------------------------------------*/
void app_main (void */*argument*/) {

tid_ledOn = osThreadNew(ledOn, NULL, NULL);
tid_ledOff = osThreadNew(ledOff, NULL, NULL);

osDelay(osWaitForever);
while (1);
}

/*----------------------------------------------------------------------------
Main: Initialize and start the RTOS2 Kernel
---------------------------------------------------------------------------*/
void setup() {
pinMode(LED_BUILTIN, OUTPUT);

osKernelInitialize(); // Initialize CMSIS-RTOS
osThreadNew(app_main, NULL, NULL); // Create application main thread
if (osKernelGetState() == osKernelReady) {
osKernelStart(); // Start thread execution
}

while (1);
}

//------------------------------------------------------------------------------
// loop must never block
void loop() {
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "STM32duino FreeRTOS",
"version": "9.0.4",
"version": "10.0.1",
"keywords": "rtos, timing, thread, task, mutex, semaphore",
"description": "Real Time Operating System implemented for STM32",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino FreeRTOS
version=9.0.4
version=10.0.1
author=Richard Barry <[email protected]>
maintainer=stm32duino
sentence=Real Time Operating System implemented for STM32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*---------------------------------------------------------------------------*/

/**
******************************************************************************
* @file cmsis_os.c
* @author MCD Application Team
* @date 13-July-2017
* @brief CMSIS-RTOS API implementation for FreeRTOS V9.0.0
******************************************************************************
* @attention
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/

#include <string.h>
#include "cmsis_os.h"

Expand Down Expand Up @@ -991,10 +948,7 @@ void *osPoolAlloc (osPoolId pool_id)
}

for (i = 0; i < pool_id->pool_sz; i++) {
index = pool_id->currentIndex + i;
if (index >= pool_id->pool_sz) {
index = 0;
}
index = (pool_id->currentIndex + i) % pool_id->pool_sz;

if (pool_id->markers[index] == 0) {
pool_id->markers[index] = 1;
Expand Down
Loading