2021-12-14 05:34 AM
I am using STM32L562-DK for my development, I am using SBSFU.
In bootloader, I want to use timer 7 as an interrupt. I am configuring it as following
TIM_HandleTypeDef htim7;
void TIM7_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_IRQn 0 */
/* USER CODE END TIM6_IRQn 0 */
HAL_TIM_IRQHandler(&htim7);
/* USER CODE BEGIN TIM7_IRQn 1 */
/* USER CODE END TIM7_IRQn 1 */
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM7) {
printf("\r\n TIM7 Callback");
}
/* USER CODE BEGIN Callback 1 */
/* USER CODE END Callback 1 */
}
HAL_StatusTypeDef Boot_StartWatchdgFeedTimer(void)
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock = 0;
uint32_t uwPrescalerValue = 0;
uint32_t pFLatency;
/*Configure the TIM7 IRQ priority */
HAL_NVIC_SetPriority(TIM7_IRQn, 0 ,0);
/* Enable the TIM7 global Interrupt */
HAL_NVIC_EnableIRQ(TIM7_IRQn);
/* Enable TIM7 clock */
__HAL_RCC_TIM7_CLK_ENABLE();
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* Compute TIM7 clock */
uwTimclock = HAL_RCC_GetPCLK1Freq();
/* Compute the prescaler value to have TIM7 counter clock equal to 1MHz */
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
printf("\r\n uwTimclock = %d\r\n",uwTimclock);
printf("\r\n uwPrescalerValue = %d",uwPrescalerValue);
/* Initialize TIM7 */
htim7.Instance = TIM7;
/* Initialize TIMx peripheral as follow:
+ Period = [(TIM7CLK/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
*/
htim7.Init.Period = (1000000U / 1000U) - 1U;
htim7.Init.Prescaler = uwPrescalerValue;
htim7.Init.ClockDivision = 0;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_Base_Init(&htim7) == HAL_OK)
{
/* Start the TIM time Base generation in interrupt mode */
printf("\r\nTImer Start Ret valur\n");
int ret = HAL_TIM_Base_Start_IT(&htim7);
printf("\r\nTImer Start Ret value = %d\r\n",ret);
return ret;
}
/* Return function status */
return HAL_ERROR;
}
My code is hanging after executing HAL_TIM_Base_Start_IT() API, I have declared void TIM7_IRQHandler(void) in boot_hal.h, and all above APIs are written in boot_hal.c.
Is there any specific configuration required to use tim7 as an interrupt in the bootloader?
I have tried with timer 6, code is not hung HAL_TIM_Base_Start_IT() with timer 6 but the interrupt was not generated.
@Frantz LEFRERE , Can you please help me regarding it?
2021-12-14 06:09 AM
You need to initialize htim7. In particular, the State and Lock variables. Zero-initializing it will do this correctly.
Debug the code. Run it, hit paus when it "hangs" and see where execution is.
You're using printf in the interrupt and in the main loop. Might not work out well depending on your implementation of printf.
2021-12-14 07:04 AM
Thanks @TDK , After calling __HAL_TIM_ENABLE_IT() API in HAL_TIM_Base_Start_IT(), Board hangs, I have tried with LED toggle instead of print, the result is same.
Why with TIM6 interrupt is not generating? Am I missing any configuration?
2021-12-14 07:10 AM
No error seen in you code.
I take your code and paste it in the SBSFU_Boot code activate the HAL TIM and it was working fine. TIM7_IRQHandler is called.
Please insure you properly set the SECBOOTADD0 = 0x180030
2021-12-14 07:20 AM
2021-12-14 09:05 PM
Can you please let me know in which file you have pasted code and in which file you have called Boot_StartWatchdgFeedTimer() API?
Activating the HAL TIM means uncomment "HAL_TIM_MODULE_ENABLED" in stm32l5xx_hal_conf.h or anything else?
In my case, SECBOOTADD0 = 0x180052, with this configuration everything working fine except the timer.
2021-12-14 10:34 PM
For a quick and dirty test I put everything in boot_hal.c and add this call :
int32_t boot_platform_init(void)
{
...
TFM_LL_SECU_ApplyRunTimeProtections();
/* Check static protections */
Boot_StartWatchdgFeedTimer();
while(1);
...
I only uncomment "HAL_TIM_MODULE_ENABLED"
2021-12-14 10:48 PM
With same code and same configuration My code is stuck in SetSysClock() clock in following while loop
while ((RCC->CR & RCC_CR_PLLRDY) != RCC_CR_PLLRDY)
{
}
2021-12-14 10:53 PM
SystemInit->SetSysClock is executed before the code added. I don't understand how adding TIM7 init would impact this. Please double check
2021-12-14 10:56 PM
Even If I am calling this API at end of boot_platform_init() , result is same