Skip to main content
PYada.1
Associate III
September 9, 2021
Question

FreeRTOS with SBSFU is not working

  • September 9, 2021
  • 12 replies
  • 4320 views

I am using the STM32L562E-DK development kit. I have taken reference to NUCLEO-L552ZE-Q and ported it for STM32L562E-DK. Also added External OSPI flash. without FreeRTOS it is working fine.

I have added FreeRTOS in the nonsecure application. For that, I have made the following changes

1) Adopt Middleware folder as provided in "FreeRTOS_ThreadCreation" example of STM32L562E-DK

2) Adopt stm32l5xx_hal_timebase_tim.c

3) Remove SysTick_Handler() definition in stm32l5xx_it.c file.

4) Add void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) API in main

5) Add osKernelInitialize(); and osKernelStart(); in main().

The same changes are working for the GPIO_IOToggle example. I am able to toggle GPIO in the thread. But in the case of the SBSFU Application is not working. Is there any specific change is required in bootloader or application?

@Frantz LEFRERE​ , @Jocelyn RICARD​  Can you please guide me regarding it?

This topic has been closed for replies.

12 replies

PYada.1
PYada.1Author
Associate III
September 21, 2021

Thanks @alister​  for quick response.

>What is the "SysTick->CTRL;" for?

SysTick->CTRL is used to clear over flow flag. I have copied vFreeRtosContextSwitching() code form cmsis_os2.c file's SysTick_Handler() API.

>As you're modifying SysTick_Handler, if it calls HAL_IncTick too, that should fix HAL_Delay.

Yes I am modifying SysTick_Handler() in stm32l5xx_it.c file, It also calls HAL_IncTick() before calling vFreeRtosContextSwitching(). But when HAL_Delay() is called SysTick_Handler() is not triggered, so tick is not incrementing as HAL_IncTick() also will not be called. This cause HAL_Delay() stuck into while loop.

alister
Senior III
September 21, 2021

>But when HAL_Delay() is called SysTick_Handler() is not triggered, so tick is not incrementing

You've said FreeRTOS is working.

Superior FreeRTOS alternatives to HAL_Delay include vTaskDelay or vTaskDelayUntil or block on a notifier or semaphore and code an interrupt to unblock it.

[EDIT] HAL_Delay must be being called from a context the SysTick can't interrupt.

Before discussing solutions, would you like to explain the context HAL_Delay is being called?

PYada.1
PYada.1Author
Associate III
September 21, 2021

>Superior FreeRTOS alternatives to HAL_Delay include vTaskDelay or vTaskDelayUntil or block on a notifier or semaphore and code an interrupt to unblock it.

TaskDelay is working fine as expected.

>would you like to explain the context HAL_Delay is being called?

HAL_Delay() is called in task.

void StartDefaultTask(void *argument)

{

/* USER CODE BEGIN 5 */

(void) argument;

printf("\r\n LED task Started \r\n");

for (;;)

{

      printf("\r\n LED Toggle \r\n");

      /* Insert delay 1000 ms */

      HAL_Delay (GPIO_TOGGLE_DELAY);

}

/* USER CODE END 5 */

}

If I replace HAL_Delay() with osDelay() it works fine and prints a message every 1 second

Jocelyn RICARD
ST Employee
September 22, 2021

Hello @PYada.1​ 

I'm not sure what your are exactly testing.

Systick should only be used by RTOS.

HAL_Delay should use another timer, like TIM6. If you use CubeMX to generate your project, the code for it will be provided automatically.

Best regards

Jocelyn

PYada.1
PYada.1Author
Associate III
September 28, 2021

Thanks @Jocelyn RICARD​ ,

Yes, I have tried to use a timer for systick, but My timer interrupt is not getting triggered as mentioned in the previous discussion. Even without FreeRTOS if I create a timer in the nonsecure application, the interrupt of overflow is not triggered. During debugging I have seen timer is started and its count increased, overflows and started from zero as well. The main issue is "Not getting timer 6 interrupt triggered". I have taken reference from "FreeRTOS_SecureIOToggle_TrustZone" provided in "STM32CubeL5". Is there any specific configuration required to use a timer in the nonsecure application?

Note: Actual issue is not getting timer overflow interrupt in the nonsecure application.

alister
Senior III
September 28, 2021

>Is there any specific configuration required to use a timer in the nonsecure application?

You have boot code. You have an app. The app and possibly the boot code can write an app image into an install slot ready to be installed. Next reset, if it's there, the boot code will authenticate, optionally decrypt, install it to an active slot and execute it. If it isn't there, the boot code will authenticate the app in the active slot and if it looks ok it will execute it.

Nothing's perfectly secure. There are degrees of secure. But adding the nonsecure adjective to the app is only confusing things.

I'm confused.

I'm unsure if you're talking about the app or perhaps the part of the boot code (SBSFU) that ST name the SFU.

I'm wondering if nonsecure is a mistake and you're using MPU for protection and you really mean unprivileged.

Let's keep the language simple.

It doesn't matter if the timer is in your boot code or in your app code.

Disable all your SBU protections.

Get these parts working separately:

  1. Timer
  2. FreeRTOS
  3. Application
  4. Application image
  5. SBSFU without protections installing image
  6. SBSFU without protections executing an already installed image
  7. SBSFU with protections

Suggest use different secret keys for Debug and Release builds for whatever encryption you're using. I.e. a Debug boot code can install/execute a Debug app and a Release boot code can install/execute a Release app. Pass your build config name to your app's post-build script so it knows which key to use.

To get your timer going, there are many references: Community, Google, the reference manual, AN4776, examples (allegedly).