Stuck in application startup code
I am facing an issue on one of our stm32f4 boards. We have a custom bootloader , which boots up the app as below
__disable_irq();
HAL_RCC_DeInit();
__HAL_RCC_AHB1_FORCE_RESET();
__HAL_RCC_AHB1_RELEASE_RESET();
__HAL_RCC_AHB2_FORCE_RESET();
__HAL_RCC_AHB2_RELEASE_RESET();
__HAL_RCC_AHB4_FORCE_RESET();
__HAL_RCC_AHB4_RELEASE_RESET();
__HAL_RCC_APB3_FORCE_RESET();
__HAL_RCC_APB3_RELEASE_RESET();
__HAL_RCC_APB1L_FORCE_RESET();
__HAL_RCC_APB1L_RELEASE_RESET();
__HAL_RCC_APB1H_FORCE_RESET();
__HAL_RCC_APB1H_RELEASE_RESET();
__HAL_RCC_APB2_FORCE_RESET();
__HAL_RCC_APB2_RELEASE_RESET();
__HAL_RCC_APB4_FORCE_RESET();
__HAL_RCC_APB4_RELEASE_RESET();
__set_MSP(*(__IO uint32_t*)0x8050000);
JumpToApp();
/****** end of bl ********/
and in the startup code of app ,
SCB->VTOR = 0x8050000;
__DSB();
__ISB();
Then following is done
Switch on PLL
..
some flash and ram tests
..
Start HSE clock and Enable clock security
..
Then Timer 5 is configured to measure the clock period
RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
/* Connect internally TIM5_CH4 Input Capture to LSE */
TIM5->OR &= ~TIM_OR_TI4_RMP;
TIM5->OR |= TIM_OR_TI4_RMP_1;
/* Configure time base */
TIM5->PSC = 0x0000u;
TIM5->EGR |= TIM_EGR_UG;
/* Configure TIM5 time base */
TIM5->CR1 &= ~TIM_CR1_DIR;
TIM5->CR1 &= ~TIM_CR1_CMS;
TIM5->CR1 &= ~TIM_CR1_CKD;
TIM5->ARR = 0xFFFF;
TIM5->PSC = 0x0000;
TIM5->EGR |= TIM_EGR_UG;
/* Configure LSI oscillator into TIM5 Chl 4 input */
TIM5->CCER &= ~TIM_CCER_CC4E;
/* Select the Input and set the filter */
TIM5->CCMR2 &= ~TIM_CCMR2_CC4S;
TIM5->CCMR2 |= TIM_CCMR2_CC4S_0; /* CC4 channel is input, IC4 mapped on TI4 */
TIM5->CCMR2 &= ~TIM_CCMR2_IC4F; /* no filter */
TIM5->CCER &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP); /* 00: non-inverted/rising edge */
TIM5->CCER |= TIM_CCER_CC4E; /* enable capture */
TIM5->CCMR2 |= TIM_CCMR2_IC4PSC; /* DIV8 */
NVIC_SetPriority(TIM5_IRQn,0);
NVIC_EnableIRQ(TIM5_IRQn);
/* Enable TIM5 counter */
TIM5->CR1 |= TIM_CR1_CEN;
/* Reset the flags */
TIM5->SR = 0;
/* Enable the CC4 Interrupt Request */
TIM5->DIER |= TIM_DIER_CC4IE; /*!<Capture/Compare 4 interrupt enable */
__enable_irq();
/* now wait for timer 5 interrupt to do the clock measurement check */
variable = 0;
while (variable != 0)
{
//stuck here
}
...
void tim_handler ()
{
if (TIM5->SR & SR_CC4IF)
{
variable = 1;
}
}
!! stuck here
In one of the boards, the tim5 interrupt is not received and it is stuck here. However if the disable irq is commented out in the bootloader, it works fine. Also it works fine if directly the app is run from programmer.
Would appreciate some inputs on what could be happening here.
