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

 

Comments
michaelg643
Associate II

Thanks, this is a really informative article to getting started on FreeRTOS on the N6. It looks like the only supported context for FreeRTOS is in the FSBL (The option for the "Appli" context is grayed out). What is the path forward to getting FreeRTOS available in the Appli context? I would like to be able to use it while having access to all 4.2MB of SRAM on the chip.

 

Disregard the above, I did not see the "Show components for context:" Drop-down, and was only selecting FreeRTOS for FSBL, and NOT the application.

vaira103
Associate II

Do we have any document like this that shows how to use LWIP with FreeRTOS?

I know that LWIP is not part of the STM32N6570-DK, but now that we have FreeRTOS, does anyone know how to manually integrate LWIP?

@B.Montanari 

B.Montanari
ST Employee

Hi @vaira103 

I'll create a tutorial on how to add LwIP and another one on how to have it with FreeRTOS. It might take a few weeks to get it published.

You can find the N6 port for the LWIP here>stm32n6-classic-coremw-apps/Projects/NUCLEO-N657X0-Q/Applications/LwIP at main · STMicroelectronics/stm32n6-classic-coremw-apps , but as you saw, only the NUCLEO has examples. The DK uses a RGMII instead of RMII, so a few changes are needed.

I've made a quick demo (temporarily in a very old repo I have, this will be moved to the hotspot once the articles are completed), running on the FSBL that uses FreeRTOS and LWIP to create a simple server/client application. It is using DHCP and you can configure the server's IP via the UART/VCOM terminal. As this was a simple demo, you'll have to type the IP with the 0s and no ".", for example: 192168001123. The main.h has the TCP SERVER PORT it expects to connect to, the default is 2048. If all goes well, you should see something like this on the terminal

BMontanari_0-1759431285362.png

And like this on your server, I've used an app called "TCPConsole" available on App Store, but any server could be used:

BMontanari_1-1759431352938.png

Hope this helps

 

Version history
Last update:
‎2025-08-01 7:34 AM
Updated by: