on 2025-05-22 12:30 PM
This article helps you set up a project for the STM32N6 microcontroller using the X-CUBE-FREERTOS middleware.
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 |
Before starting, ensure you have:
The hardware used in this article is the STM32N6570-DK. Ensure it is in DEV boot mode to program the code:
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.
Open STM32CubeIDE and create a new STM32 project.
Start by creating a new project using STM32CubeMX and select [STM32N657X0H3Q]. Select the option to use [Secure domain only]. Select [FSBL] and [Appli].
Locate PO1, configure it as GPIO_Output, and label it as GREEN_LED.
We need to assign the GPIO to be used by the FSBL.
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.
Click on "Software Packs" and choose [Select Components] and use the latest version of X-CUBE-FREERTOS
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:
Go to the NVIC_FSBL to ensure that the interrupt priorities are updated, so that the RTOS can manage them:
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 */
Ensure that the board is in DEV boot mode and enter debug mode:
The same debug features are available, which means it is possible to use the FreeRTOS view list, such as [FreeRTOS Task List]:
By pausing the debug, the list updates, allowing us to see the states of defaultTask and IDLE tasks:
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.