Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable interrupt function in sw4stm32

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?

like image 349
Hamid Avatar asked Mar 03 '26 07:03

Hamid


1 Answers

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.
like image 107
imbearr Avatar answered Mar 05 '26 23:03

imbearr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!