Topic : IRQ of TIMER6 never triggered (STM32F107)

Forum : ARM

Original Post
Post Information Post
February 2, 2011 - 5:10pm


I tried to make a program which uses the TIMER6 of the STM32F107.
I uses ST libraries, and I configure correctly (I suppose, by debuging tools) all registers for interruption system use. But I never enter in the void TIM6_IRQHandler(void) interruption loop.

//In main.c :
void TIMER6_Configuration(void)
/* Fills each TIM_TimeBaseInitStruct member with its default value */
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;

/* Set the default configuration */
TIM_TimeBaseInitStruct.TIM_Period = 0xFFFF;
TIM_TimeBaseInitStruct.TIM_Prescaler = 0x017C;
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0x0000;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseInitStruct);

/* Enable TIM6 */

/* Enable TIEMR6 interrupt */

/*Update Interupt (URS bit) Enable */
TIM_UpdateRequestConfig(TIM6, TIM_UpdateSource_Regular);

Anybody can help me or bring a good functionning code example (I didn't found any examples for TIMER using with ST libraries).

Thanks for all your answers!

Post Information Post
February 2, 2011 - 6:16pm

Hello I think you are missing two things which are listed below. The first one I believe is necessary and the second part may be required depending on your application. Just check the part(2) before you including it in your code.

TIM_OCInitTypeDef TIM_OCInitStructure;

/* TIM6 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);


TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Inactive;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

/*Initializes the TIM Channel 1 according to the parameters specified in the TIM_OCInitStruct.*/
TIM_OC1Init(TIM6, &TIM_OCInitStructure);

February 3, 2011 - 9:12am

Hi siddhulokesh, and i thank you for your answer.

First, I already enabled the clock. I just forgot to precize this point in my previous message.

But I'm surprised by your second advice : in ST libraries, I can read in comment :
* @brief Initializes the TIMx Channel1 according to the specified
* parameters in the TIM_OCInitStruct.
* @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
* @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
* that contains the configuration information for the specified TIM peripheral.
* @retval None
In my case, I uses the TIM6. So I didn't care about these functions. Have you got more information about TIM_OC ?

But I note a problem with the NVIC functionning.

void NVIC_Configuration(void)
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

NVIC_InitTypeDef NVIC_InitStructure;

/* Configure TIM6 interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;


When the NVIC_Init is executing (in step by step debugging mode), a processor IRQ (void HardFault_Handler(void)) which contains an infinite loop is set, at this exact instruction line (in the NVIC_Init function, in misc.c):

if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
/* Compute the Corresponding IRQ Priority --------------------------------*/
/* Enable the Selected IRQ Channels --------------------------------------*/
NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
(uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);

At this step, program start the processor IRQ.
But with another NVIC_IRQChannel (for example USART2_IRQn), there is any problem...

Somebody have information about this?
Thanks you all for answers!