How to enable interrupt function in sw4stm32

Hamid picture Hamid · Jun 29, 2016 · Viewed 9.8k times · Source

I use SW4STM32 toolchain,I want to bliking led using timer2 when overflow, in STM32103RET, here is my functions to turn led on and of.

void TurnOnLed(){
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_10,GPIO_PIN_SET);
}

void TurnOffLed()
{
    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_10,GPIO_PIN_RESET);
}

the timer2 initilizing has been set by stm32 cube mx, but i do not know which function called when timer2 overflows?

Answer

imbearr picture imbearr · Jul 1, 2016

You need to start your timer by function

HAL_TIM_Base_Start_IT(&htimX);

And for the firs time implement you callback function named HAL_TIM_PeriodElapsedCallback:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if (htim->Instance == TIMx) {
    }
}

If you don't know anything about HAL_Driver you may found a lot of information from:

  1. STM32F0xx HAL_Driver description or for another family just search for HAL Driver on st.com
  2. You can see examples of HAL Driver usage (as you use CubeMX, so you can found it in C:/Users/%USERNAME%/STM32Cube/Repository/ directory)
  3. Just open stm32f?xx_hal_tim.c and see what functions are present, see their comments to uderstand what tey are doing. And see what functions are called from HAL_TIM_IRQHandler to know how are named callbacks.