[DONE]32bit Timers on STM32F4

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
talsit
Posts: 24
Joined: Wed Oct 10, 2012 10:09 am

[DONE]32bit Timers on STM32F4

Post by talsit »

Hi there!

TIM2/5 are both 32bit timers, but, from what I can see, they can't be uses as that, just as 16bit, since there's quite a few places where parameters are cast into uint16_t.

Is there any reason I can't modify code to allow the full 32bit range?

Thanks.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: 32bit Timers on STM32F4

Post by Giovanni »

Hi,

You could, the problem is that TIM2 an TIM5 are not 32bits on all devices so the driver supports them only in 16bits mode.

It could be improved to support both modes but changes would be extensive. This would impact the GPT, ICU and PWM drivers.

Giovanni
talsit
Posts: 24
Joined: Wed Oct 10, 2012 10:09 am

Re: 32bit Timers on STM32F4

Post by talsit »

The only thing I can see from allowing them to be 32bit is (at least for the STM32F4 port), that gpt_lld_change_interval() casts the value to a uint16_t.

What I'm really proposing is changing gptcnt_t to be uint32_t instead of uint16_t.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: 32bit Timers on STM32F4

Post by Giovanni »

You could give it a try, that cast is not even strictly required.

Giovanni
talsit
Posts: 24
Joined: Wed Oct 10, 2012 10:09 am

Re: 32bit Timers on STM32F4

Post by talsit »

I did remove the cast. Well, I now cast as a gptcnt_t instead of uint16_t, and I also changed the typedef of gptcnt_t to be a uint32_t. That actually makes it all work nice.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: 32bit Timers on STM32F4

Post by Giovanni »

Hi,

Please post a patch if you can. I think that differences among 16 an 32 bit times should be handled somehow, using assertions for example.

Giovanni
talsit
Posts: 24
Joined: Wed Oct 10, 2012 10:09 am

Re: 32bit Timers on STM32F4

Post by talsit »

I've attached the patch, which is only 2 lines really.
It may be possible to move the typedef to the config file, would that makes sense? Or maybe through some #ifdefs.
But yes, my timers are now 32-bit compatible.
Attachments
gpt_lld.h.patch.zip
(485 Bytes) Downloaded 437 times
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [TODO]32bit Timers on STM32F4

Post by Giovanni »

Hi,

Patch merged, it will be in 2.6.1.

Giovanni
talsit
Posts: 24
Joined: Wed Oct 10, 2012 10:09 am

Re: [DONE]32bit Timers on STM32F4

Post by talsit »

Awesome, thanks!
Post Reply