Interrupt caused by timer problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,
I'm trying to set interrupt caused by counter overflow. I would like to do this without sdk, only using the standard library and registers. Unfortunatelly after first jump into interrupt body, the program hangs in function hard fault exception handler. Does it mean the sdk is blocking my configuration? I tried configure the interrupt with 3 different timers(tim1, tim2, tim9) and program always hangs in the same function.

Best regards,

pelka

0 Likes
6 Replies
Anonymous
Not applicable

I assume you might not be clearing the Interrupt Flag once it enters the ISR,

Can you please share your code, if it doesnot solve the problem.

0 Likes
Anonymous
Not applicable

     Unfortunatelly im clearing the interrupt flag every function's enter. Of course i can sheare the code. It is typical implementation.

// Clock - RCC_Config()

RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2, ENABLE );

//Nvic - NVIC_Config

NVIC_InitTypeDef nvicTim2Struct;

NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

nvicTim2Struct.NVIC_IRQChannel= TIM2_IRQn;

nvicTim2Struct.NVIC_IRQChannelPreemptionPriority = 14;

nvicTim2Struct.NVIC_IRQChannelSubPriority= 14;

nvicTim2Struct.NVIC_IRQChannelCmd= ENABLE;

NVIC_Init( &nvicTim2Struct );

//TIM - TIM_Config

TIM_TimeBaseInitTypeDef tim2Structure;

tim2Structure.TIM_Prescaler = 13000;

tim2Structure.TIM_Period= 10000;

tim2Structure.TIM_ClockDivision= TIM_CKD_DIV1;

tim2Structure.TIM_RepetitionCounter= 0;

tim2Structure.TIM_CounterMode= TIM_CounterMode_Up;

TIM_TimeBaseInit (TIM2, &tim2Structure);

TIM_ITConfig (TIM2, TIM_IT_Update, ENABLE);

TIM_Cmd (TIM2, ENABLE);

Higher are the configuration functions, and lower main. Rest of clock configuration and the vectors's interrupt start address is already in sdk

void application_start( )

{

  int cnt = 0;

  wiced_init();

  RCC_Config();

  NVIC_Config();

  TIM_Config();

  while(1){

  wiced_rtos_delay_milliseconds( 2000 );

  cnt++;

  }

}

void TIM2_irq( void ){

  NVIC_ClearPendingIRQ(TIM2_IRQn);

  printf("irq");

}

0 Likes
Anonymous
Not applicable

Hi

I am seeing some difference in my configuration and yours anyway I'm posting my code, if you want you can use this but this is TIM4

define APB1_CLOCK_FREQUENCY_MHZ80 // CORRECT THIS AS PER YOUR CLOCK

void TIM4_irq()

{

if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
{
TIM_Cmd(TIM4, DISABLE);
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}

}

void timer_init(uint32_t usec_val)

{

uint32_t prd_val = (usec_val * APB1_CLOCK_FREQUENCY_MHZ);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

TIM_TimeBaseInitTypeDef timerInitStructure;
timerInitStructure.TIM_Prescaler = 0;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = prd_val;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM4, &timerInitStructure);

TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
NVIC_InitTypeDef nvicStructure;
nvicStructure.NVIC_IRQChannel = TIM4_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
nvicStructure.NVIC_IRQChannelSubPriority = 0x0F;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
TIM_Cmd(TIM4, ENABLE);

}

0 Likes
Anonymous
Not applicable

Thank you for your response. The difference between my configuration and yours is only changing the clearing function from interrupt. I tried this function too before. It didnt change the error. Really dont know why the error is still showing me but i tried something else. I used the rtos. from wiced. I implemented only one function. It calls wiced_rtos_register_timed_event. The example of using it is in the apsta's snip. I'm closing the topic

0 Likes

You could NOT call the printf in your ISR !

0 Likes
Anonymous
Not applicable

I tried without printf too. Always is the same problem. Program hangs after jump into interrupt body. Does not matter what is in the irq.

0 Likes