New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement HardwareTimer library for Timer management #146

Open
fpistm opened this Issue Nov 7, 2017 · 12 comments

Comments

7 participants
@fpistm
Member

fpistm commented Nov 7, 2017

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.

@Adminius

This comment has been minimized.

Show comment
Hide comment
Contributor

Adminius commented Nov 7, 2017

@romainreignier

This comment has been minimized.

Show comment
Hide comment
@romainreignier

romainreignier 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.

romainreignier commented 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

This comment has been minimized.

Show comment
Hide comment
@Adminius

Adminius Nov 7, 2017

Contributor

Timer1 and Timer3 are good libs!
This one too: https://github.com/wimleers/flexitimer2

Contributor

Adminius commented Nov 7, 2017

Timer1 and Timer3 are good libs!
This one too: https://github.com/wimleers/flexitimer2

@Adminius

This comment has been minimized.

Show comment
Hide comment
@Adminius

Adminius Nov 7, 2017

Contributor

My requirements:

  1. Interrupt driven function call with resolution: 1us, 1ms, 1s.
  2. better PWM generation: flexible PWM frequency, flexible counter, up-up/up-down (e.g. https://github.com/Adminius/Dimmer32u4)
Contributor

Adminius commented Nov 7, 2017

My requirements:

  1. Interrupt driven function call with resolution: 1us, 1ms, 1s.
  2. better PWM generation: flexible PWM frequency, flexible counter, up-up/up-down (e.g. https://github.com/Adminius/Dimmer32u4)
@franciscogimeno2000

This comment has been minimized.

Show comment
Hide comment
@franciscogimeno2000

franciscogimeno2000 Nov 23, 2017

Someone knows why libraries do not work
Timer1 ... 2 ... flexitimer2 in board STMF303 - F303K8

franciscogimeno2000 commented Nov 23, 2017

Someone knows why libraries do not work
Timer1 ... 2 ... flexitimer2 in board STMF303 - F303K8

@fpistm

This comment has been minimized.

Show comment
Hide comment
@fpistm

fpistm Nov 23, 2017

Member

@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 😉

Member

fpistm commented 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

This comment has been minimized.

Show comment
Hide comment
@franciscogimeno2000

franciscogimeno2000 Nov 24, 2017

OK, you have some example of using a basic timer.?

franciscogimeno2000 commented Nov 24, 2017

OK, you have some example of using a basic timer.?

@straccio

This comment has been minimized.

Show comment
Hide comment
@straccio

straccio Nov 29, 2017

Contributor

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.

Contributor

straccio commented 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

This comment has been minimized.

Show comment
Hide comment
@marcdepape

marcdepape 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:

  1. You should be able to assign a timer when you declare your stimer_t obj:

stimer_t _timer(TIM8);

  1. You should be able to assign a callback to TimerHandleInit:

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.

marcdepape commented 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:

  1. You should be able to assign a timer when you declare your stimer_t obj:

stimer_t _timer(TIM8);

  1. You should be able to assign a callback to TimerHandleInit:

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 fpistm removed the on going label Apr 11, 2018

@fpistm

This comment has been minimized.

Show comment
Hide comment
@fpistm

fpistm Apr 11, 2018

Member

Thanks for the feedback @marcdepape.
I will review all inputs.

Member

fpistm commented Apr 11, 2018

Thanks for the feedback @marcdepape.
I will review all inputs.

@iotlearner0level

This comment has been minimized.

Show comment
Hide comment
@fpistm

This comment has been minimized.

Show comment
Hide comment
@fpistm

fpistm Apr 17, 2018

Member

Currently not.
Time is missing, this is in the task list... this will come.

Member

fpistm commented Apr 17, 2018

Currently not.
Time is missing, this is in the task list... this will come.

@fpistm fpistm changed the title from Timer management to Implement HardwareTimer library for Timer management Sep 19, 2018

@fpistm fpistm moved this from To do to In progress in STM32 core based on ST HAL Oct 1, 2018

@fpistm fpistm added the on going label Oct 1, 2018

@fpistm fpistm self-assigned this Oct 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment