2015-05-12 01:27 AM
Hi, I'm fairly new to STM32 and, since I have to learn it from zero, I'm dealing with HAL which I'm told it's the future.
Well, maybe it will, but by now I'm having a hard time dealing with it. Docs are ok, but I can find almost no example except for the very basic GPIO/blinky. I'm now trying to experiment a little bit with timers but my compiler (Eclipse-gnu gcc) is not able to find a few macro. This is my init code:
TIM_HandleTypeDef TIM_Handle;
__TIM3_CLK_ENABLE();
// timer
TIM_Handle.Init.Prescaler = 671 ;
TIM_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
TIM_Handle.Init.Period = 62499;
TIM_Handle.Instance = TIM3;
// Enable TIMER 3. Same timer whose clocks we enabled
HAL_TIM_Base_Init(&TIM_Handle);
// Init timer
HAL_TIM_Base_Start_IT(&TIM_Handle);
// start timer interrupts
// we also need to setup interrupt to handle timer 3 request:
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 1);
// 0 is the highest priority
HAL_NVIC_EnableIRQ(TIM3_IRQn);
And this is the handler:
// IRQ HANDLER FOR TIMER 3
void
TIM3_IRQHandler(
void
)
{
if
(__HAL_TIM_GET_FLAG(&T3_Handle, TIM_FLAG_UPDATE) != RESET)
//In case other interrupts are also running
{
if
(__HAL_TIM_GET_ITSTATUS(&T3_Handle, TIM_IT_UPDATE) != RESET)
{
__HAL_TIM_CLEAR_FLAG(&T3_Handle, TIM_FLAG_UPDATE);
// some led blinking code here...
}
}
}
And I'm getting these errors/warnings:
- Symbol 'T3_Handle' could not be resolved - implicit declaration of function '__HAL_TIM_GET_ITSTATUS'
I'm icluding these:
1.
#include ''stm32f4xx.h''
2.
#include ''stm32f4xx_hal.h''
I've also removed the check from ''exclude resource from build'' on
stm32f4xx_hal_tim.c
On my
stm32f4xx_hal_conf.h I have
#define HAL_TIM_MODULE_ENABLED uncommented...
I can find the needed definition inside stm32f4xx_hal_tim.c so why am I unable to compile it?
Oh... if you have some link of HAL examples/tutorials please share.
Thank you very much for your help.
#stm32 #hal #timers
2015-05-12 12:25 PM
Solved. In case someone is interested this is the right code to use:
// IRQ HANDLER FOR TIMER 3
void
TIM3_IRQHandler(
void
)
{
if
(__HAL_TIM_GET_FLAG(&TIM_Handle, TIM_IT_UPDATE) != RESET)
//In case other interrupts are also running
{
if
(__HAL_TIM_GET_IT_SOURCE(&TIM_Handle, TIM_IT_UPDATE) != RESET)
{
__HAL_TIM_CLEAR_IT(&TIM_Handle, TIM_IT_UPDATE);
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);
}
}
}