2025-07-01 11:10 AM
Hi,
I have generated a CubeMX project with trustzone. So, I have a secure and a nonsecure project. The secure project runs, jumps to the nonsecure project and the nonsecure project tries to blink the red. I am using CMakeLists and have included my_app.c file, in the nonsecure project, where my main() function is located.
My my_app.c file:
#include <stdbool.h>
// Auto-generated main from STM32 project
#include "main.h"
#include "stm32wbaxx_hal_gpio.h"
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
main2();
while (true)
{
HAL_GPIO_WritePin(RED_GPIO_Port, RED_Pin, GPIO_PIN_SET);
HAL_Delay(250U);
HAL_GPIO_WritePin(RED_GPIO_Port, RED_Pin, GPIO_PIN_RESET);
HAL_Delay(250U);
}
}
The main2() is the original main generated by CubeMX, but I have renamed it and removed everything else from there, and now it only has the blinking LED code. My main2() function in the nonsecure project main.c file:
int main2(void)
{
HAL_GPIO_WritePin(RED_GPIO_Port, RED_Pin, GPIO_PIN_SET);
HAL_Delay(250U);
HAL_GPIO_WritePin(RED_GPIO_Port, RED_Pin, GPIO_PIN_RESET);
HAL_Delay(250U);
}
When I step into the code, the entry point is the main() function in the my_app.c file. Then I am able to blink the LED in the main2() function but then the code arrives to the while loop in the main() and it crashes.
So, my question is if someone can help me understanding how code through the main.c file can control the LED but the code through my_app.c file cannot?
Thanks!
Solved! Go to Solution.
2025-07-09 4:02 AM
Hi,
Thank you for the suggestions @miklion-jelik and @STackPointer64!
Solved the problem. It was integration of the my_app.c file. I had to make some modifications in the CMakeLists and it fixed the problem. It had nothing to do with the Trustzone configs or HAL initializations or anything.
2025-07-04 2:51 AM
Hello @fa31,
I suggest you watch these two videos, especially the TrustZone Lab, as it explains exactly the example you are trying to create.
Best regards,
2025-07-05 1:56 AM - edited 2025-07-11 11:54 PM
I'm sharing soem steps, hope it helps:
2025-07-09 4:02 AM
Hi,
Thank you for the suggestions @miklion-jelik and @STackPointer64!
Solved the problem. It was integration of the my_app.c file. I had to make some modifications in the CMakeLists and it fixed the problem. It had nothing to do with the Trustzone configs or HAL initializations or anything.
2025-07-09 4:05 AM
Hello,
I’m glad to hear that you’ve resolved your problem. Best of luck with your project!
Best regards,