cancel
Showing results for 
Search instead for 
Did you mean: 

Linker Errors when enabling CMSIS RTOS v2 and TrustZone

NickO
Associate III

I have started a new project using STM32H573. This is using the following:

  • Cube MX 6.16
  • Cube IDE 2.0 - Build: 26820_20251114_1348 (UTC)

The project has secure zone enabled. I have written bare metal code and shown I can run/debug code in the non-secure environment without issues, and I can invoke non-secure callable functions etc.

My problem comes when I add Free RTOS and enable CMSIS RTOS v2 to the non-secure side.

When I build, I get linker errors (see below).

When I search the forums, there have been similar issues raised, but most are quite old posts or seem overly complex (which always worries me)

``

C:/Users/531023/git/TEML20/Monitor/NonSecure/Debug/../Core/Src/app_freertos.c:86:(.text.MX_FREERTOS_Init+0xa): undefined reference to `osThreadNew'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/app_freertos.o: in function `StartDefaultTask':
C:/Users/531023/git/TEML20/Monitor/NonSecure/Debug/../Core/Src/app_freertos.c:110:(.text.StartDefaultTask+0xa): undefined reference to `osDelay'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Core/Src/main.o: in function `main':
C:/Users/531023/git/TEML20/Monitor/NonSecure/Debug/../Core/Src/main.c:96:(.text.main+0x10): undefined reference to `osKernelInitialize'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/531023/git/TEML20/Monitor/NonSecure/Debug/../Core/Src/main.c:101:(.text.main+0x18): undefined reference to `osKernelStart'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:91: Monitor_NonSecure.elf] Error 1
"make -j16 all" terminated with exit code 2. Build might be incomplete.

 I also get the following warning (which is likely related):

Invalid project path: Missing project folder or file: \Monitor_NonSecure\RTOS2 for Source path. Monitor_NonSecure pathentry Path Entry Problem

 

5 REPLIES 5
NickO
Associate III

Now I am getting this (and I don't know what I changed):

C:/Users/531023/git/TEML20/Monitor/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33/non_secure/port.c:1133:(.text.vPortSVCHandler_C+0x38): undefined reference to `SecureContext_AllocateContext'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/531023/git/TEML20/Monitor/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33/non_secure/port.c:1138:(.text.vPortSVCHandler_C+0x5e): undefined reference to `SecureContext_LoadContext'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/531023/git/TEML20/Monitor/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33/non_secure/port.c:1149:(.text.vPortSVCHandler_C+0x76): undefined reference to `SecureContext_FreeContext'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/531023/git/TEML20/Monitor/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33/non_secure/port.c:1158:(.text.vPortSVCHandler_C+0x7c): undefined reference to `SecureInit_DePrioritizeNSExceptions'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/531023/git/TEML20/Monitor/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33/non_secure/port.c:1161:(.text.vPortSVCHandler_C+0x80): undefined reference to `SecureContext_Init'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Middlewares/RTOS2/CMSIS/RTOS2/Core/TZ_Non_Secure/portasm.o: in function `PendSV_Handler':
C:/Users/531023/git/TEML20/Monitor/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33/non_secure/portasm.c:433:(.text.PendSV_Handler+0x10): undefined reference to `SecureContext_SaveContext'
C:/ST/STM32CubeIDE_1.18.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.100.202509120712/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: C:/Users/531023/git/TEML20/Monitor/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33/non_secure/portasm.c:433:(.text.PendSV_Handler+0x5e): undefined reference to `SecureContext_LoadContext'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:94: Monitor_NonSecure.elf] Error 1

 

 

Souhaib MAZHOUD
ST Employee

Hello @NickO 

Could you please attach your ioc, in order to further investigate the issue?

KR, Souhaib

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thank you for replying. Please see attached.

Some success! 

I added X-CUBE_FREERTOS to the secure M33S project as well, and it now links.

I also had to assign a spare timer to the Timebase for the Secure side (SYS_S->Timebase Source) for the scheduler to run.

Is this intended behaviour?

If so, I think I am missing a detail somewhere. I assumed only the non-secure side needed to reference the RTOS, but I seem to be mistaken (or there is a bug). I can see my thread is running in non-secure mode which is at least reassuring.

Updated .ioc file attached

Hello @NickO 

Yes, the compilation error you are facing are caused by the fact that X-Cube-FREERTOS is not selected for the secure project. Therefore, some dependencies are not generated and will lead to those errors.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.