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!
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 toUINT32_MAX
, andnow
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!