Skip to main content
PYada.1
Associate III
December 14, 2021
Question

Not able to start time 7 as interrupt in bootloader

  • December 14, 2021
  • 4 replies
  • 2573 views

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?

This topic has been closed for replies.

4 replies

TDK
Super User
December 14, 2021

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."
PYada.1
PYada.1Author
Associate III
December 14, 2021

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?

TDK
Super User
December 14, 2021
You gotta show your code. Sounds like the timer is already running and starting it causes endless interrupts. Or show TIM register values immediately before enabling the interrupt.
"If you feel a post has answered your question, please click ""Accept as Solution""."
Frantz LEFRERE
ST Employee
December 14, 2021

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 

PYada.1
PYada.1Author
Associate III
December 15, 2021

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.

Frantz LEFRERE
ST Employee
December 15, 2021

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" 

Frantz LEFRERE
ST Employee
December 16, 2021

Please check the NVIC->ITNS register and insure the interrupt properly assigned to secure or non-secure regarding your code.

By default all the IRQ are secure, setting a bit to one, assign the IRQ to non-secure.

You can try to generate example code with CubeMX and check

Usually configuration is done in the TZ_SAU_Setup :

 #if defined (NVIC_INIT_ITNS0) && (NVIC_INIT_ITNS0 == 1U)

  NVIC->ITNS[0] = NVIC_INIT_ITNS0_VAL;

 #endif

 #if defined (NVIC_INIT_ITNS1) && (NVIC_INIT_ITNS1 == 1U)

  NVIC->ITNS[1] = NVIC_INIT_ITNS1_VAL;

 #endif

 #if defined (NVIC_INIT_ITNS2) && (NVIC_INIT_ITNS2 == 1U)

  NVIC->ITNS[2] = NVIC_INIT_ITNS2_VAL;

 #endif

 #if defined (NVIC_INIT_ITNS3) && (NVIC_INIT_ITNS3 == 1U)

  NVIC->ITNS[3] = NVIC_INIT_ITNS3_VAL;

 #endif

Thanks flag define in partition_stm32l552xx.h

PYada.1
PYada.1Author
Associate III
December 16, 2021

Value of NVIC->INTS is as below

 NVIC->ITNS[0] = 00

 NVIC->ITNS[1] = 00

 NVIC->ITNS[2] = 00

 NVIC->ITNS[3] = 00

 NVIC->ITNS[4] = 00

 NVIC->ITNS[5] = 00

 NVIC->ITNS[6] = 00

 NVIC->ITNS[7] = 00

 NVIC->ITNS[8] = 00

 NVIC->ITNS[9] = 00

 NVIC->ITNS[10] = 00

 NVIC->ITNS[11] = 00

 NVIC->ITNS[12] = 00

 NVIC->ITNS[13] = 00

 NVIC->ITNS[14] = 00

 NVIC->ITNS[15] = 00

In my application, if I write the same code It is working, But it is not working in the bootloader.

One thing I have found is that currently, FLASH_AREA_PERSO_SIZE size is 0x900, if I change it to 0x800 interrupt is generated and working. But bootloader is not able to jump into the application after changing FLASH_AREA_PERSO_SIZE macro to 0x900 due to a size issue.

What is the relation between FLASH_AREA_PERSO_SIZE and TIM7 interrupt?

Frantz LEFRERE
ST Employee
December 16, 2021

Modifying the FLASH_AREA_PERSO_SIZE , should modify the boot address please insure you properly align SECBOOTADD0