cancel
Showing results for 
Search instead for 
Did you mean: 

Stuck in application startup code

krishr
Associate III

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.

 

 

5 REPLIES 5
SofLit
ST Employee

Hello,

Please use <\> button to insert your code.

Thank you fir your understanding.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Under normal startup conditions the MCU doesn't have interrupts disabled.

Systick and other time outs won't work with interrupts disabled.

Check you aren't dying in a while(1) loop in Error_Handler() or HardFault_Handler()

Make sure SCB->VTOR is set correctly in SystemInit()

TIM interrupt for Update when CNT == 0

There's a pointer in RAM for the stack, or you want the Stack Pointer at the TOP on memory, and moving DOWNWARD?

__set_MSP(*(__IO uint32_t*)0x24000000); // ??

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Will do hereafter. Thanks!

Thanks for your reply. Sorry, the MSP assignment was incorrect when i pasted the code here.. I have updated the code This code works on rest of the devices and is seen failing only on 1 board so far. It is not dying in a while(1) loop in error or hard fault handlers. A variable is set to 0 and we wait in a while loop  for the variable to set . And the interrupt is not received. The interrupts are re-enabled in line 86 .

Pavel A.
Evangelist III

This code works on rest of the devices and is seen failing only on 1 board

So dispose of this one board responsibly, or just trash it?