I’m working with an STM32 Nucleo board and trying to get timer interrupts working. I have a breakpoint set in the ISR but it’s never being reached. I’m finding it difficult to understand the HAL documentation but I’ve been trying for weeks and I can’t get this simple program to work. Is there anything that is standing out as obviously incorrect?
#include <stdint.h>
#include "stm32f7xx_hal_def.h"
#include "stm32f7xx_hal_cortex.h"
#include "stm32f7xx_hal.h"
#include "stm32f7xx.h"
#include "stm32f7xx_hal_conf.h"
#include "stm32f722xx.h"
#include "stm32f7xx_hal_dma.h"
#include "stm32f7xx_hal_rcc_ex.h"
#include "stm32f7xx_hal_tim.h"
#define LED_PIN GPIO_PIN_7
#define LED_PORT GPIOB
TIM_HandleTypeDef htim;
void main(void) {
HAL_StatusTypeDef h = HAL_Init();
__HAL_RCC_TIM2_CLK_ENABLE();
htim.Instance = TIM2;
htim.Init.Prescaler = SystemCoreClock / 1000 - 1;
htim.Init.Period = 1000;
htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim.Init.CounterMode = TIM_COUNTERMODE_UP;
HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
HAL_TIM_Base_MspInit(&htim);
HAL_TIM_Base_Init(&htim);
HAL_TIM_RegisterCallback(&htim, HAL_TIM_PERIOD_ELAPSED_CB_ID, HAL_TIM_PeriodElapsedCallback);
HAL_TIM_Base_Start_IT(&htim);
while(1) {}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
int i = 1;
}
I’ve tried all sorts of examples from various forum answers and the HAL documentation
New contributor
bongoman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.