Page 1 of 1

HardwareTimer library (examples) do not work

Posted: Sun Mar 08, 2020 8:41 am
by jojos998
Hello!

I am trying to use HardwareTimer library which is part of STM32's official core libraries. After following instructions on https://github.com/stm32duino/wiki/wiki ... er-library I was not able to use it.

I have copied the provided examples (Timebase_callback.ino and PWM_FullConfiguration.ino) and none of them works. Even putting flag into callback function

Code: Select all

void Update_IT_callback(HardwareTimer*)
and checking the flag in loop() indicates that callback function is never called by the timer.

I have STM32 Cores 1.8.0. instaled.

Any ideas what could be the reason?

Re: HardwareTimer library (examples) do not work

Posted: Sun Mar 08, 2020 11:24 am
by fpiSTM
Use the official released STM32Examples then example will work.

Re: HardwareTimer library (examples) do not work

Posted: Thu May 14, 2020 12:53 pm
by sale
For me, the blue pill plate works try this
#define pin PB9
void setup()
{
Serial.begin(9600);
TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin), PinMap_PWM);
uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin), PinMap_PWM));
// Instantiate HardwareTimer object. Thanks to 'new' instantiation, HardwareTimer is not destructed when setup() function is finished.
HardwareTimer *MyTim = new HardwareTimer(Instance );
// MyTim->setPWM(channel, pin, 5, 10, NULL, NULL); // No callback required, we can simplify the function call
MyTim->setPWM(channel, pin, 400, 10); // 400 Hertz, 10% dutycycle
}
void loop()
{
}
But I don't know how to call setPWM in loop. If anyone can help me with a simple example of how to call PWM in loop.
I want this
void loop{
MyTim->setPWM(channel, pin, 400, 10);
}

Re: HardwareTimer library (examples) do not work

Posted: Thu May 14, 2020 1:06 pm
by stas2z