You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement HardwareTimer library for Timer management #146
This issue is to open discussion around Timer management in order to provide useful API.
Current implementation is limited to support basic Arduino function.
Any help/comment are welcome.
@franciscogimeno2000 simply because not ported for stm32. Ex Flexitimer uses direct register acces but this is not the same for stm32.
Goal of this issue is to collect requirements/proposal/API examples... to implement timers management useful for community.
Any contributions are welcom 😉
I have a NUCLEO F1 and F4 and spent the weekend trying to use timer.h / timer.c with them. It was a struggle.
For example (I'm going to truncate my code, and I don't have to use timer_enable_clock(_timer.handle); because I tried, and as far as I can tell it is called by these Inits), this does not work:
In the first example I got: 0, 0, 0
In the second example I got: 28, 1, 84000000
From looking through the code, the TimerPulseInit actually assigns a timer:
obj->timer = TIMER_SERVO;
Whereas TimerHandleInit does not assign a timer.
In fact, I couldn't figure out for the life of me how to assign a specific timer to either of these functions, however I tried _timer.timer = TIM2; and it worked:
This would greatly simplify everything. I think this is almost there, and the efforts to simplify the setup are good so far... just needs a bit of polish.
Hi @Astroghost-Francois,
Yes, it will be possible to use interrupts on HardwareTimer library (through dedicated API from HardwareTimer library) : on update event (timer rollover) as well as compare match event corresponding to one of the channel.
I installed all latest libs/cores but i dont know how to enable the HardwareTimer: 'HardwareTimer' was not declared in this scope
code i used:
HAL_TIM_MODULE_ENABLED
#if defined(LED_BUILTIN)
#define pin LED_BUILTIN
#else
#define pin PA1
#endif
void setup()
{
// no need to configure pin, it will be done by HardwareTimer configuration
// pinMode(pin, OUTPUT);
// Automatically retrieve TIM instance and channel associated to pin
// This is used to be compatible with all STM32 series automatically.
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);
// Configure and start PWM
// MyTim->setPWM(channel, pin, 5, 10, NULL, NULL); // No callback required, we can simplify the function call
MyTim->setPWM(channel, pin, 5, 10); // 5 Hertz, 10% dutycycle
}
void loop()
{
/* Nothing to do all is done by hardware. Even no interrupt required. */
}
i'm new with the st's core and not familiar with the HAL configs. I tried diffent stuff but i dont understand how to get it to work. How can i enable this lib?
On Sun, Aug 4, 2019 at 9:32 AM KJansun ***@***.***> wrote:
I installed all latest libs/cores but i dont know how to enable the
HardwareTimer:
'HardwareTimer' was not declared in this scope
code i found:
`HAL_TIM_MODULE_ENABLED
#if defined(LED_BUILTIN)
#define pin LED_BUILTIN
#else
#define pin PA1
#endif
void setup()
{
// no need to configure pin, it will be done by HardwareTimer configuration
// pinMode(pin, OUTPUT);
// Automatically retrieve TIM instance and channel associated to pin
// This is used to be compatible with all STM32 series automatically.
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);
// Configure and start PWM
// MyTim->setPWM(channel, pin, 5, 10, NULL, NULL); // No callback
required, we can simplify the function call
MyTim->setPWM(channel, pin, 5, 10); // 5 Hertz, 10% dutycycle
}
void loop()
{
/* Nothing to do all is done by hardware. Even no interrupt required. */
}`
i'm new with the st's core and not familiar with the HAL configs. I tried
diffent stuff but i dont understand to get it to work. How can i enable
this lib?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#146?email_source=notifications&email_token=AF6R4XQOFA3GH63JHULEZGTQC2HZNA5CNFSM4ECSN3NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3P5CLI#issuecomment-517984557>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF6R4XXCRWO4EIYN25VOJFDQC2HZNANCNFSM4ECSN3NA>
.
You have to install the github version of the core & then apply this PR. The last release 1.6.1 will NOT include these changes. …
On Sun, Aug 4, 2019 at 9:32 AM KJansun @.***> wrote: I installed all latest libs/cores but i dont know how to enable the HardwareTimer: 'HardwareTimer' was not declared in this scope code i found: HAL_TIM_MODULE_ENABLED #if defined(LED_BUILTIN) #define pin LED_BUILTIN #else #define pin PA1 #endif void setup() { // no need to configure pin, it will be done by HardwareTimer configuration // pinMode(pin, OUTPUT); // Automatically retrieve TIM instance and channel associated to pin // This is used to be compatible with all STM32 series automatically. 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); // Configure and start PWM // MyTim->setPWM(channel, pin, 5, 10, NULL, NULL); // No callback required, we can simplify the function call MyTim->setPWM(channel, pin, 5, 10); // 5 Hertz, 10% dutycycle } void loop() { /* Nothing to do all is done by hardware. Even no interrupt required. */ } i'm new with the st's core and not familiar with the HAL configs. I tried diffent stuff but i dont understand to get it to work. How can i enable this lib? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#146?email_source=notifications&email_token=AF6R4XQOFA3GH63JHULEZGTQC2HZNA5CNFSM4ECSN3NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3P5CLI#issuecomment-517984557>, or mute the thread https://github.com/notifications/unsubscribe-auth/AF6R4XXCRWO4EIYN25VOJFDQC2HZNANCNFSM4ECSN3NA .
Activity
Adminius commentedon Nov 7, 2017
I need this feature:
https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/libraries/A_STM32_Examples/examples/Maple/TimerInterrupts/TimerInterrupts.ino#L35
Something like this, but user friendly: https://github.com/adafruit/Adafruit_ZeroTimer/
Edit @fpistm: Add #104 request here.
romainreignier commentedon Nov 7, 2017
On AVR, I usually use this library, the API is simple enough: https://www.pjrc.com/teensy/td_libs_TimerOne.html
But it only allows to use timers for interrupt callback. You cannot configure a timer as quadrature encoder counter from it for example.
Adminius commentedon Nov 7, 2017
Timer1 and Timer3 are good libs!
This one too: https://github.com/wimleers/flexitimer2
Adminius commentedon Nov 7, 2017
My requirements:
franciscogimeno2000 commentedon Nov 23, 2017
Someone knows why libraries do not work
Timer1 ... 2 ... flexitimer2 in board STMF303 - F303K8
fpistm commentedon Nov 23, 2017
@franciscogimeno2000 simply because not ported for stm32. Ex Flexitimer uses direct register acces but this is not the same for stm32.
Goal of this issue is to collect requirements/proposal/API examples... to implement timers management useful for community.
Any contributions are welcom 😉
franciscogimeno2000 commentedon Nov 24, 2017
OK, you have some example of using a basic timer.?
straccio commentedon Nov 29, 2017
For my projects i usually use particle boards, the are also based on STM32.
Take a look on their Software Timer https://docs.particle.io/reference/firmware/photon/#software-timers
They use Free RTOS, also available for more stm32 boards, but if you don't want use Free RTOS can you use the same interface for class.
PS: remember to use also std::function as callback.
marcdepape commentedon Apr 9, 2018
I have a NUCLEO F1 and F4 and spent the weekend trying to use timer.h / timer.c with them. It was a struggle.
For example (I'm going to truncate my code, and I don't have to use
timer_enable_clock(_timer.handle);because I tried, and as far as I can tell it is called by these Inits), this does not work:stimer_t _timer;TimerHandleInit(&_timer, 100000, 384);attachIntHandle(&_timer, handle_clock);Yet, this does:
stimer_t _timer;TimerPulseInit(&_timer, 500, 40000, pulse_clock);TimerHandleInit(&_timer, 100000, 384);In my callback I blinked an led and I used the following to debug after initializing:
Serial.println(getTimerIrq(_timer.handle.Instance)); Serial.println(getTimerClkSrc(_timer.handle.Instance)); Serial.println(getTimerClkFreq(_timer.handle.Instance));In the first example I got: 0, 0, 0
In the second example I got: 28, 1, 84000000
From looking through the code, the TimerPulseInit actually assigns a timer:
obj->timer = TIMER_SERVO;Whereas TimerHandleInit does not assign a timer.
In fact, I couldn't figure out for the life of me how to assign a specific timer to either of these functions, however I tried
_timer.timer = TIM2;and it worked:stimer_t _timer;_timer.timer = TIM2;TimerHandleInit(&_timer, 100000, 384);attachIntHandle(&_timer, handle_clock);Can I suggest the following:
stimer_t _timer(TIM8);void TimerHandleInit(stimer_t *obj, uint16_t period, uint16_t prescaler, void (*irqHandle)(stimer_t *))This would greatly simplify everything. I think this is almost there, and the efforts to simplify the setup are good so far... just needs a bit of polish.
fpistm commentedon Apr 11, 2018
Thanks for the feedback @marcdepape.
I will review all inputs.
iotlearner0level commentedon Apr 17, 2018
hello is this implimented already?
http://docs.leaflabs.com/static.leaflabs.com/pub/leaflabs/maple-docs/latest/lang/api/hardwaretimer.html
18 remaining items
Astroghost-Francois commentedon Jul 11, 2019
Hi ,
will we be able to use arduino timers interrupt commands after ?
François
ABOSTM commentedon Jul 12, 2019
Hi @Astroghost-Francois,
Yes, it will be possible to use interrupts on HardwareTimer library (through dedicated API from HardwareTimer library) : on update event (timer rollover) as well as compare match event corresponding to one of the channel.
fpistm commentedon Jul 26, 2019
Hi all,
@ABOSTM do the PR of the HarwareTimer implementation.
Do not hesitate to give us your feedback.
Thanks
KJansun commentedon Aug 4, 2019
I installed all latest libs/cores but i dont know how to enable the HardwareTimer:
'HardwareTimer' was not declared in this scopecode i used:
i'm new with the st's core and not familiar with the HAL configs. I tried diffent stuff but i dont understand how to get it to work. How can i enable this lib?
BennehBoy commentedon Aug 4, 2019
KJansun commentedon Aug 5, 2019
Ok, thanks
HardwareTimer implementation (#576)
MacLeod-D commentedon Feb 4, 2020
Hello,
I am using Arduino-IDE and STM32F407 Black Board and STM32GENERIC board definition.
Here is my code to use timers:
output:
Using digitalWrite - not GPIO - it should work on most STM32 boards.
fpistm commentedon Feb 5, 2020
Hi @MacLeod-D
Don't know what did you expect?
Here this is for the STM32 core not the STM32GENERIC .
use the forum which is used for primary support.