2021-09-09 06:22 AM
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?
2021-09-09 09:14 AM
Hello @PYada.1
In your description you do not detail how you moved from standalone application to application run by SBSFU.
For instance, did you change the interrupt vector address to match the one used in new location of the application ?
Best regards
Jocelyn
2021-09-09 09:58 PM
@Jocelyn RICARD I am using GPIO toggle example provided in SBSFU. which is working fine standalone without FreeRTOS. DO I Need to change anything in bootloader if regarding systick or FreeRTOS?
2021-09-09 11:18 PM
Hello,@PYada.1
" SBSFU Application is not working".
Are you sure all the resources ( Timer? ) used by your FreeRTOS as been assigned to NS world ?
Please deactivate security protection and try to debug to get details about the issue.
Best regards,
Frantz
2021-09-13 12:17 AM
@Frantz LEFRERE , After debugging found that TIme6 is not generating interrupts, although it's init and start API return pass. I have tried another timer as well but it results same.
For the application with bootloader, do we need to change the timer configuration?
2021-09-14 05:18 AM
@PYada.1, please insure this timer is configured as a non-secure and is properly started.
2021-09-16 12:50 AM
@Frantz LEFRERE ,
I have done the following changes for the timer test.
In stm32l5xx_hal_conf.h file uncommented HAL_TIM_MODULE_ENABLED file.
Add FOllowing API in Nonsecure application main.c and called it after HAL_Init().
HAL_StatusTypeDef test_timer()
{
uint32_t TickPriority = TICK_INT_PRIORITY;
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock = 0;
uint32_t uwPrescalerValue = 0;
uint32_t pFLatency;
/*Configure the TIM6 IRQ priority */
HAL_NVIC_SetPriority(TIM6_IRQn, TickPriority ,0);
/* Enable the TIM6 global Interrupt */
HAL_NVIC_EnableIRQ(TIM6_IRQn);
/* Enable TIM6 clock */
__HAL_RCC_TIM6_CLK_ENABLE();
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* Compute TIM6 clock */
uwTimclock = HAL_RCC_GetPCLK1Freq();
/* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
/* Initialize TIM6 */
htim6.Instance = TIM6;
/* Initialize TIMx peripheral as follow:
+ Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
+ ClockDivision = 0
+ Counter direction = Up
*/
htim6.Init.Period = (1000000U / 1000U) - 1U;
htim6.Init.Prescaler = uwPrescalerValue;
htim6.Init.ClockDivision = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_Base_Init(&htim6) == HAL_OK)
{
/* Start the TIM time Base generation in interrupt mode */
return HAL_TIM_Base_Start_IT(&htim6);
}
else
{
printf("Fail to init Timer \r\n");
}
/* Return function status */
return HAL_ERROR;
}
Also, Add the following API in the stm32l5xx_it.c file
void TIM6_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_IRQn 0 */
/* USER CODE END TIM6_IRQn 0 */
HAL_TIM_IRQHandler(&htim6);
/* USER CODE BEGIN TIM6_IRQn 1 */
/* USER CODE END TIM6_IRQn 1 */
}
The callback is also written in the main.c file as following
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM6) {
u32counter++;
}
/* USER CODE BEGIN Callback 1 */
/* USER CODE END Callback 1 */
}
All above modifications are done in a nonsecure application
Am I missing or missconfiguring anything?
2021-09-16 01:38 AM
please have a look in the different code example from Cube firmware :
STM32Cube_FW_L5_V1.4.0\Projects\NUCLEO-L552ZE-Q\Applications\FreeRTOS
This would help you to find your issue.
2021-09-17 05:42 AM
Hello @Frantz LEFRERE , without freertos also I am not able to get timer interrupt in non-secure application. What specific configuration is required to use timer in nonsecure mode.
2021-09-17 09:52 PM
>What specific configuration is required to use timer in nonsecure mode
Don't know your specifics, but perhaps something here will help...
FreeRTOS and SE would both need SVC_Handler and FreeRTOS needs to be privileged. Refer https://www.freertos.org/FreeRTOS-MPU-memory-protection-unit.html.
Start with a clean project.
Stock HAL_Init will configure the SysTick.
Get your FreeRTOS working.
Stock starting the FreeRTOS kernel will configure, start its timer and enable interrupts.
Then add your SBSFU to that.
There will be notes in the link and in your SBSFU docs about configuring the MPU.
Get your reset reason, initialise the SE and check/apply security protections early in main, before starting the FreeRTOS kernel.
Initialise the SFU and start the SB state machine from one of your tasks.