Skip to main content
4tschabos
Associate II
January 25, 2017
Question

STM32F303K8 timer interrupt hangs

  • January 25, 2017
  • 4 replies
  • 1093 views
Posted on January 25, 2017 at 11:07

Hi,

I try to implement a timer with interrupt routine, but it always hangs after the timer is activated. This can be seen if I use the debugger over SWD: when I execute the next command after TIM_Cmd(TIM2, ENABLE); there is no more response from the uC. Does someone have an idea?

My code:

/**

******************************************************************************

* @file main.c

* @author Ac6

* @version V1.0

* @date 01-December-2013

* @brief Default main function.

******************************************************************************

*/

#include 'stm32f30x.h'

//#include 'USART_DMA.h'

//#include 'FOC.h'

int main(void)

{

SystemInit();

//USART init

//init_usart(57600);

//send_usart_data('Go!');

//FOC init

//initTimerFOC();

initTimer();

//LED init

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;

GPIO_Init(GPIOA, &GPIO_InitStructure);

while(1) {

GPIO_ResetBits(GPIOA, GPIO_Pin_6);

for(int i=0;i<100000;i++);

GPIO_SetBits(GPIOA, GPIO_Pin_6);

for(int i=0;i<100000;i++);

//send_usart_data('X');

}

}

void TIM2_IRQHandler(void) {

if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {

TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

}

}

void initTimer() {

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

NVIC_InitTypeDef NVIC_InitStructure;

NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_Init(&NVIC_InitStructure);

TIM_TimeBaseInitTypeDef TIM2Init;

TIM2Init.TIM_Prescaler = 10;

TIM2Init.TIM_Period = 2000;

TIM2Init.TIM_ClockDivision = TIM_CKD_DIV1;

TIM2Init.TIM_CounterMode = TIM_CounterMode_Up;

TIM2Init.TIM_RepetitionCounter = 0;

TIM_TimeBaseInit(TIM2, &TIM2Init);

TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

//Timer

TIM_Cmd(TIM2, ENABLE);

}
    This topic has been closed for replies.

    4 replies

    waclawek.jan
    Super User
    January 25, 2017
    Posted on January 25, 2017 at 11:22

    And what happens when you properly initialize the timer init struct?

    JW

    4tschabos
    4tschabosAuthor
    Associate II
    January 25, 2017
    Posted on January 25, 2017 at 11:23

    The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6mM&d=%2Fa%2F0X0000000bvE%2FHd5BkjSuK2WLXos7lPJ9XIZ6aNAWku9NjGFfWJSXM24&asPdf=false
    gbm
    Lead III
    January 25, 2017
    Posted on January 25, 2017 at 12:10

    I noticed you are using AC6. If the project was generated by hand (not by CubeMX), the startup file does not contain a populated interrupt vector table, so your routine is actually never called.

    My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
    4tschabos
    4tschabosAuthor
    Associate II
    January 25, 2017
    Posted on January 25, 2017 at 12:13

    Ok, so you recommend to use CubeMX to generate the startup and system code and then build the project on top of it?

    gbm
    Lead III
    January 25, 2017
    Posted on January 25, 2017 at 13:09

    Looks like a good idea. Projects generated by AC6 are far from being complete. Atollic, Keil and others generate complete empty projects with usable startup files and ready-to-use headers with a few mouse clicks.

    My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice