AnsweredAssumed Answered

hard fault handler

Question asked by fakhar.bilal on Aug 4, 2013
Latest reply on Nov 21, 2013 by Clive One
hi,

i am working on stm32f407. i am experiencing hard fault handler. 
start:{}
timer();
while(!one_second_timer)
{
     /*my code*/
}
goto start;

and the code for timer is 

void timer(void)
{
     uint16_t PrescalerValue = 0;
     TIM_Cmd(TIM3, DISABLE);
     
     one_sec_timer_interrupt = 0;
     
     
     NVIC_InitTypeDef NVIC_InitStructure;
     /* TIM3 clock enable */
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
     /* Enable the TIM3 gloabal Interrupt */
     NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);
     /* Time base configuration */
     TIM_TimeBaseStructure.TIM_Period = 65535;
     TIM_TimeBaseStructure.TIM_Prescaler = 0;
     TIM_TimeBaseStructure.TIM_ClockDivision = 0;
     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
     
     TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
     
     /* Prescaler configuration */
     TIM_PrescalerConfig(TIM3, PrescalerValue, TIM_PSCReloadMode_Immediate);
     
     /* Output Compare Timing Mode configuration: Channel1 */
     TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
     TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
     TIM_OC1Init(TIM3, &TIM_OCInitStructure);
     TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
     
     /* Output Compare Timing Mode configuration: Channel2 */
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
     TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
     TIM_OC2Init(TIM3, &TIM_OCInitStructure);
     TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Disable);
     
     /* Output Compare Timing Mode configuration: Channel3 */
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = CCR3_Val;
     TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
     TIM_OC3Init(TIM3, &TIM_OCInitStructure);
     TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Disable);
     
      TIM_ITConfig(TIM3, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 ,ENABLE);
     
     TIM_Cmd(TIM3, ENABLE);


}

when i run this code for 20 minutes or more this controller hangs in hard fault handler. there is something wrong in re initializing all the timer code.

1.) how can i reinitialize timer when one second timer interrupt expires? 
2.) what is the reason for controller to go in hard fault handler (after 20 minutes)?
thank you

Outcomes