Introduction
FreeRTOS is supplied as standard C source files built along with the other C files in your project. This repository contains a port of FreeRTOS kernel for Infineon MCUs based on Arm® Cortex®-M0 (CM0), Cortex®-M0+ (CM0P), Cortex®-M4 (CM4), Cortex®-M33 (CM33), Cortex®-M55 (CM55), Cortex®-R4 (CR4) and Cortex®-M7 (CM7) cores.
- Note
- Cortex® R4 (CR4) is currently supported only on GCC_ARM
Additional information about using this library in ModusToolbox™ software including a Quick Start guide can be found in the library's README.md file.
Quick Start Guide
FreeRTOS default flow (non TrustZone)
Description
The quick start guide provides steps to create a simple blinking LED project with a single task using FreeRTOS.
STEP1: Projects preparation.
- Create a ModusToolbox™ application.
- Include the FreeRTOS middleware into the project using the ModusToolbox™ Library Manager.
- Note
- ModusToolbox™ library manager automatically pulls the dependent libraries (clib-support, abstraction-rtos) once the FreeRTOS library is selected.
- Add
FREERTOS
to the COMPONENTS
variable defined in the ModusToolbox™ application Makefile:
- Copy the FreeRTOSConfig.h file from the **mtb_shared/freertos/release-vX.Y.Z/Source/portable/COMPONENT_(CORE)* folder to your project, where (CORE) is the target Arm® Cortex®-M CPU core (CM0, CM0P, CM4, CM33, CM55, CR4 or CM7).
- Open the copied FreeRTOSConfig.h file and remove the
#warning This is a template.
line. See Configuration Consideration section of the README.md file. - Warning
- Ensure that configENABLE_TRUSTZONE is set to 0 and configRUN_FREERTOS_SECURE_ONLY to 1 in case if you run on secure core only configuration like for PSOC Control C3 MCU devices
STEP2: Project sources update.
- Include the required headers.
#include "FreeRTOS.h"
#include "task.h"
- Specify LED port and other defines.
#define BLINKY_TASK_NAME ("Blinky")
#define BLINKY_TASK_STACK_SIZE (configMINIMAL_STACK_SIZE)
#define BLINKY_TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#define USER_LED_TOGGLE_PERIOD_MS 100u
#define LED_GPIO (CYBSP_USER_LED)
- Create function to toggle the LED.
void blinky_task(void * arg)
{
(void) arg;
for(;;)
{
Cy_GPIO_Inv(CYBSP_USER_LED_PORT, CYBSP_USER_LED_PIN);
vTaskDelay(USER_LED_TOGGLE_PERIOD_MS);
}
}
- Create task for LED toggling and start scheduler.
int main(void)
{
BaseType_t retval;
cy_rslt_t result;
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
__enable_irq();
retval = xTaskCreate(blinky_task, BLINKY_TASK_NAME, BLINKY_TASK_STACK_SIZE, NULL, BLINKY_TASK_PRIORITY, NULL );
if (pdPASS == retval)
{
vTaskStartScheduler();
}
for (;;)
{
}
}
STEP3: Build and Program Application.
- Observe the LED blinking on the kit.
FreeRTOS with TrustZone (only CM33 core) flow
Description
ARM® introduced TrustZone to the Cortex-M® series of microcontrollers with the ARMv8-M architecture. TrustZone is an security extension that enables two security domains within a single processor. The quick start guide provides steps to create a simple application (consist of two independent projects - Secure and nonSecure). FreeRTOS run on nonSecure-side application with two tasks, witch will be calling Secure-side APIs to get data from Secure project.
STEP1: Create a ModusToolbox™ application.
Create a ModusToolbox™ PSoC Edge PSOC_Edge_Hello_World
application for KIT_PSE84_EVAL_EPC2
.
STEP2: nonSecure project source update.
- Include the FreeRTOS and Retarget_IO (could be already added) middleware using the ModusToolbox™ Library Manager.
- Copy the FreeRTOSConfig.h file from the mtb_shared/freertos/release-vX.Y.Z/Source/portable/COMPONENT_CM33 folder to your nonSecure project root.
- Open the copied FreeRTOSConfig.h file and remove the
#warning This is a template.
line.
- Add
FREERTOS
and FREERTOS_TZ
to the COMPONENTS
variable defined in the ModusToolbox™ nonSecure application Makefile: COMPONENTS += FREERTOS FREERTOS_TZ
- Include the required headers in the main.c.
#include "FreeRTOS.h"
#include "task.h"
- Specify tasks defines.
#define FIRST_TASK_NAME ("First")
#define FIRST_TASK_STACK_SIZE 4096
#define FIRST_TASK_PRIORITY 1
#define FIRST_TASK_DELAY 300
#define SECOND_TASK_NAME ("Second")
#define SECOND_TASK_STACK_SIZE 4096
#define SECOND_TASK_PRIORITY 1
#define SECOND_TASK_DELAY 700
- Specify initial variable values.
int first_val = 0;
int second_val = 3;
- Define function from Secure project.
int nsc_1_func(int value);
int nsc_2_func(int value);
- Create two independent functions with different NSC API calls.
void first_task(void *pvParameters)
{
(void) pvParameters;
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
for(;;)
{
vTaskDelay(FIRST_TASK_DELAY);
first_val = nsc_1_func(first_val);
printf("First veneer -> %d!\r\n", first_val);
}
}
void second_task(void *pvParameters)
{
(void) pvParameters;
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
for(;;)
{
vTaskDelay(SECOND_TASK_DELAY);
second_val = nsc_2_func(second_val);
printf("Second veneer -> %d!\r\n", second_val);
}
}
- Note
portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
will create Secure stack for nonSecure task with NSC call. Need to be added in ech task.
- Create two tasks and start scheduler.
int main(void)
{
cy_rslt_t result;
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
__enable_irq();
init_retarget_io();
result = xTaskCreate(first_task, FIRST_TASK_NAME, FIRST_TASK_STACK_SIZE, NULL, FIRST_TASK_PRIORITY, NULL );
if (result != pdPASS)
{
CY_ASSERT(0);
}
result = xTaskCreate(second_task, SECOND_TASK_NAME, SECOND_TASK_STACK_SIZE, NULL, SECOND_TASK_PRIORITY, NULL );
if (result != pdPASS)
{
CY_ASSERT(0);
}
vTaskStartScheduler();
for (;;)
{
}
}
- Note
- Task creation could be added before main loop and call of the Cy_SysEnableCM55
STEP3: Secure project source update.
- Copy the mtb_shared/freertos/release-vX.Y.Z/Source/COMPONENT_FREERTOS_TZ/COMPONENT_SECURE_DEVICE/TOOLCHAIN_xxx folder into your Secure project root.
- Copy the FreeRTOSConfig.h file from the mtb_shared/freertos/release-vX.Y.Z/Source/portable/COMPONENT_CM33 folder to your Secure project root.
- Open the copied FreeRTOSConfig.h file and remove the
#warning This is a template.
line. See Configuration Consideration section of the README.md file.
- Create two functions with NSC Secure_attributes
int __attribute__((cmse_nonsecure_entry)) nsc_1_func(int value)
{
return value + 3;
}
int __attribute__((cmse_nonsecure_entry)) nsc_2_func(int value)
{
return value * 2;
}
STEP4: Build and Program Application.
- Observe the async digits from the kit UART output in any COM-port terminal.
FreeRTOS API reference
See FreeRTOS API reference
More Information
For more information, refer to the links in the README.md