2013-08-03 04:47 PM
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 isvoid 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 you2013-08-03 07:33 PM
Problem likely with code not presented. Pity this is not a free standing example.
What's the interrupt code doing?What are you doing with CCRx registers?How's the 1 second thing function right now?The TIM could be set up to repeatedly interrupt on a second period, not sure why you even need to reset/reconfigure it to achieve that.What instruction is hard faulting? And what are the registers at that point?Are you violating some memory buffer?2013-11-20 11:00 PM
hello,have solved this problem?
2013-11-21 06:50 AM
hello,have solved this problem?
Does it matter? Hard Faults occur for many reasons, and you usually start by examining the processor state (registers, instruction) at the fault to diagnose why you have a specific problem. I've written dozens of posts on fixing Hard Faults.