Skip to content
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

Start alarm by subSeconds: Avoid overflow during conversion from ms to ticks. #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrschuster
Copy link

The issue stm32duino/STM32LoRaWAN#38 describes a bug that occus on LoRaWAN after 4 hours 40 minutes. This PR is the fix for that.

The bug occurs, when an alarm shall be put in place using subseconds for RTC_StartAlarm64(). If the subSeconds value is large enough, a computation in RTC_StartAlarm64() overflows.

E.g. when having predivSync=255, a value of subSeconds=2^24 (still well below UINT32_MAX and thus using the 32bit computation branch) would be multiplied by 256 and result in an overflow during computation. The overflow leads to not putting the right alarm in place.
In fact, 2^24 ms is about 4 hours 40 minutes.

E.g. when having predivSync=255, a value of subSeconds=2^24 (still well below UINT32_MAX and thus using the 32bit computation branch) would be multiplied by 256 and result in an overflow during computation. In fact, 2^24 ms is about 4 hours 40 minutes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant