cancel
Showing results for 
Search instead for 
Did you mean: 

TrustZone and LED blinking in the nonsecure project

fa31
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions
fa31
Associate III

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. 

 

View solution in original post

4 REPLIES 4
STackPointer64
ST Employee

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,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.
miklion-jelik
Associate

@STackPointer64 

I'm sharing soem steps, hope it helps:

  • Don’t call main2() if it already blinks — maybe move its code directly inside main.
  • Make sure HAL is fully initialized only once (not in both main and main2).
  • Check stack size or get mods from happymod app and linker memory settings for nonsecure side.
  • Also make sure your nonsecure code has access to that GPIO — TrustZone might restrict it.
fa31
Associate III

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. 

 

Hello,

I’m glad to hear that you’ve resolved your problem. Best of luck with your project!

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.