MaJerle / stm32fxxx-hal-libraries

Libraries for STM32F4xx and STM32F7xx built on HAL drivers from ST
MIT License
764 stars 434 forks source link

HAL Button Library unsigned roll-over #9

Closed newbrain closed 8 years ago

newbrain commented 8 years ago

Hi, the HAL based button library contain a subtle (and admittedly rarely triggered) mistake: if (now > (ButtonStruct->StartTime + ButtonStruct->PressDebounceTime)) { and other similar lines will not work correctly when the sum on the right of the > is about to roll over (close to UINT32_MAX, and now has just rolled over. The state change will be missed. Though 2^32 is a large number, it takes only ~49 days to have a roll over, something an embedded system could be expected to stay active. The correct way should be: if ((now - ButtonStruct->StartTime) > ButtonStruct->PressDebounceTime) {

If I am completely off-track, just let me know! Thanks for all your hard work!

MaJerle commented 8 years ago

You may be right. Will do this like you said.

Thanks.