cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to start time 7 as interrupt in bootloader

PYada.1
Associate III

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?

14 REPLIES 14

Is there any MPU protection I need to check?

With TIM6 firmware does not hang but interrupt is not generated. I have checked the counter value of TIM6 which has been increasing, resetting, and starting from 0 again, But the interrupt is not generated.

In TIM6 and TIM7 registers values are the same as below before calling HAL_TIM_Base_Start_IT() API

CR1 = 0 

 CR2 = 0

 DIER = 0 

 SR = 1

 EGR = 0 

@Frantz LEFRERE​ , Have you tested on STM32L562E-DK?

Test done on a Nucleo with the ST delivered code.

I don't think MPU would have an impact but to check put the call with a while(1) loop before TFM_LL_SECU_ApplyRunTimeProtections

Frantz LEFRERE
ST Employee

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

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?

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