Timers in Daisy Seed

Hello :slight_smile: I’m trying to use the timer callback with 500ms period in my project but while debugging I can see that the callback is not entered. Here’s declaration of timer and led variable:

TimerHandle tim;
bool led_state;

Here’s initialization of the timer:

    TimerHandle::Config config;
    config.dir = TimerHandle::Config::CounterDir::UP;
    config.enable_irq = true;
    config.period = 9999;
    config.periph = TimerHandle::Config::Peripheral::TIM_2;

    tim.SetCallback(timerCallback, nullptr);

Here’s the callback function:

void timerCallback(void* data)
    led_state = !led_state;

Thanks for any support :smiley:

Welcome to Daisy Forum.

Suggestion: if you want someone to debug your code, provide code which is reduced to only the essentials demonstrating your problem.

Thx for suggestion, I’ve edited my post

I’m sorry, I wasn’t clear. I meant, code which can be compiled and debugged, as is.

Try using another timer peripheral than TIM_2. libDaisy’s system support code already uses TIM_2 for a high resolution tick timer – anytime you call System::Delay() or System::GetUs() etc that’s using TIM_2 so it can’t be reused for something else.

Try using TIM_5 instead, it’s another 32-bit timer. TimerHandle doesn’t have support for all of the timers on the STM32 and that’s the only other one libDaisy supports currently that’s 32-bit, the others are only 16-bit so you need to be more careful about how you manage the prescaler/period.


I tried and it works on TIM_5 :smiley: huge thanks!

1 Like