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

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

mrschuster
Copy link
Contributor

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.
@fpistm fpistm added this to the 1.6.0 milestone Nov 25, 2024
@fpistm fpistm added the fix 🩹 Bug fix label Nov 27, 2024
@fpistm fpistm merged commit d1eed86 into stm32duino:main Nov 27, 2024
3 checks passed
@mrschuster mrschuster deleted the lorawan_issue38 branch November 27, 2024 15:44
@fpistm fpistm linked an issue Nov 27, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 🩹 Bug fix
Projects
Development

Successfully merging this pull request may close these issues.

RX1 window Timer event never reached
3 participants