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

Fix for issue #4452 - time.sleep on STM #6303

Merged
merged 1 commit into from
Apr 22, 2022
Merged

Conversation

DavePutz
Copy link
Collaborator

Issue #4452. In stm32_peripherals_rtc_set_alarm(), if the STM chip has a high-speed crystal, the value of rtc_clock_frequency is 32000. The SubSeconds calculation in line 185, however, will overflow whenever (raw_ticks % TICK_DIVISOR) is > 1000. The multiplication by 32 will give a value > rtc_clock_frequency. Since alarm.AlarmTime.SubSeconds is an unsigned 32-bit int, the result will wrap around and the sub-seconds time calculation will be very incorrect. The fix is to adjust the calculation by adding rtc_clock_frequency back to SubSeconds if the calculation has wrapped.
Note that a possibly related issue at line 89 in stm32_peripherals_rtc_init() could have resulted in an extended loop, the "while" has been changed to an "if" to make sure that no more than two reads of the SSR take place.
Testing with the script from issue #4452 gives the following output:

Adafruit CircuitPython 7.3.0-beta-1-dirty on 2022-04-21; STM32F411E_DISCO with STM32F411xE
93.186
2.53702
2.561
2.53699
2.56
2.53702
2.56097
2.561
2.53702
2.56
2.53699
2.561
2.53702
2.56097

Which is much improved over the initally reported results.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this fix!

@dhalbert dhalbert merged commit 3885bc9 into adafruit:main Apr 22, 2022
@DavePutz DavePutz deleted the issue_4452 branch June 14, 2022 17:11
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.

2 participants