cancel
Showing results for 
Search instead for 
Did you mean: 

How to use FreeRTOS™ with STM32N6

B.Montanari
ST Employee

Summary

This article helps you set up a project for the STM32N6 microcontroller using the X-CUBE-FREERTOS middleware. 

Introduction

This article focuses on how to use the X-CUBE-FREERTOS software package with the STM32N6. The step-by-step example shows a simple task to blink the LED with FreeRTOS™, while demonstrating the settings needed to ensure proper functionality. The same procedure can be used for the first stage bootloader (FSBL) and for the application.

ST provides other code examples in the official GitHub:
STMicroelectronics/x-cube-freertos: X-CUBE-FREERTOS

Here are the examples currently available:

STM32N6 applications

Short description

FreeRTOS_Mutex

This application demonstrates the use of mutexes to serialize access to a shared resource. readme

FreeRTOS_MPU This application demonstrates the use of the MPU with FreeRTOS™ to control memory/peripheral access for tasks. readme
FreeRTOS_Queues_ThreadFlags_TrustZone This application demonstrates the use of message queues, thread flags with CMSIS_RTOS2 API along with the use of FreeRTOS™ when the TrustZone® feature is enabled (TZEN=1) readme
FreeRTOS_Semaphore_LowPower This application demonstrates the use of FreeRTOS™ tickless low-power mode and semaphores readme

Prerequisites

Before starting, ensure you have:

1. Hardware setup

The hardware used in this article is the STM32N6570-DK. Ensure it is in DEV boot mode to program the code:

BMontanari_0-1747921642972.png

2. Project creation using STM32CubeIDE

The project requires configuring a few peripherals to function properly, including the Green LED, associated with the PO1. The FreeRTOS™ is added using the software package and its extension called X-CUBE-FREERTOS.

2.1. Start the project

Open STM32CubeIDE and create a new STM32 project.

BMontanari_1-1747921642974.png

Start by creating a new project using STM32CubeMX and select [STM32N657X0H3Q]. Select the option to use [Secure domain only]. Select [FSBL] and [Appli].

BMontanari_2-1747921642976.png

2.2 Configure the LED pins for the application

Locate PO1, configure it as GPIO_Output, and label it as GREEN_LED.

BMontanari_3-1747921642985.png

We need to assign the GPIO to be used by the FSBL.

BMontanari_4-1747921642994.png

2.3 Configure the SYS timer

Assign a TIMER for the SYS time base, as the SysTick is used by the FreeRTOS™ kernel. This article uses TIM16, but any free TIMER can be selected.

BMontanari_5-1747921642998.png

 

BMontanari_6-1747921643001.png

2.4 Add X-CUBE-FREERTOS

Click on "Software Packs" and choose [Select Components] and use the latest version of X-CUBE-FREERTOS

BMontanari_7-1747921643003.png

 

BMontanari_8-1747921643005.png

 

Once selected, the package is added to the "Middleware and Software Packs" categories.

Select the [CMSIS RTOS2] and enable the security settings to use security and FPU in the "Config parameters" tab:

BMontanari_9-1747921643015.png

Go to the NVIC_FSBL to ensure that the interrupt priorities are updated, so that the RTOS can manage them:

BMontanari_10-1747921643024.png

2.5 Code generation and editing

Use Alt+K or [Project]  [Generate Code] to generate the code and edit the defaultTask to be a simple Blink task, created in the app_freertos.c file:

/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN defaultTask */
  /* Infinite loop */
  for(;;)
  {
    osDelay(250);
    HAL_GPIO_TogglePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin);
  }
  /* USER CODE END defaultTask */
}

Open the main.c file and add the functions to call the FreeRTOS:

/* USER CODE BEGIN Includes */
#include "app_freertos.h"
/* USER CODE END Includes */
  /* USER CODE BEGIN 2 */
  /* Init Scheduler */
  osKernelInitialize();
  MX_FREERTOS_Init();
  /* Start scheduler */
  osKernelStart();
  /* USER CODE END 2 */

3. Build and test

Ensure that the board is in DEV boot mode and enter debug mode:

BMontanari_11-1747921643027.png

The same debug features are available, which means it is possible to use the FreeRTOS view list, such as [FreeRTOS Task List]:

BMontanari_12-1747921643029.png

By pausing the debug, the list updates, allowing us to see the states of defaultTask and IDLE tasks:

BMontanari_13-1747921643036.png

Conclusion

By following these steps, you have successfully set up a project for the STM32N6 microcontroller with FreeRTOS™. For a deeper understanding of different settings and their outcomes, consider reviewing the available documentation provided below. 

Related links

 

Version history
Last update:
‎2025-05-22 12:30 PM
Updated by: