-
Notifications
You must be signed in to change notification settings - Fork 2k
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
periph/rtt: fix overflow in tick conversion macros #15431
periph/rtt: fix overflow in tick conversion macros #15431
Conversation
|
done, |
good catch, fixed. |
here are the results from the HiL Tests |
nucleo-f767zi, esp8266-esp-12x seem to have introduced problems when compared to master... If possible please verify. |
I will see on Monday which boards I have available at the office and check them out... |
I gave this one some testing: nucleo-f767zi: works like a charm
esp32-wroom-32 (not esp8266 though): works
frdm-kw41z (for the fun): works
arduino-mega2560: conversion works (but RTT is not supported anyway)Apply the following patch: diff --git a/boards/common/arduino-atmega/Makefile.features b/boards/common/arduino-atmega/Makefile.features
index 3bc938d8f6..6c234e4bd1 100644
--- a/boards/common/arduino-atmega/Makefile.features
+++ b/boards/common/arduino-atmega/Makefile.features
@@ -2,6 +2,7 @@
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
+FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart I could verify that the conversion are also working on 8 bits (RTT doesn't work on arduino-mega2560 but we can already check the conversion):
I think we are good with this PR. Please squash! |
af03668
to
56ee87e
Compare
Squashed - many thanks for the verification @aabadie! @MrKevinWeiss as @aabadie has verified this PR to be working on some of the boards in question, could there any other issue with this PR that causes the HIL to fail? Seems like we should sort this out before merging this fix, right?! |
56ee87e
to
261d63f
Compare
@aabadie fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good to me. I think the problem raised by @MrKevinWeiss on nucleo-f767zi/esp8266 are false positives (maybe a setup issue ?).
ACK
Contribution description
The tick conversion macros provided by the
periph/rtt
driver are subject to overflow for large values. E.g. when doing something likethe resulting tick value will be wrong. Reason is this line:
-> the value of
ticks * 10000000 / RTT_FREQUENCY
is larger thenUINT32_MAX
, and therefore overflows. And as this macro is used in aRTT_TICKS_TO_MIN() -> RTT_TICKS_TO_SEC() -> RTT_TICKS_TO_MS() -> RTT_TICKS_TO_US()
cascade, all resulting values will be flawed.The same goes for the time-to-tick conversion the other way around...
This PR fixes this by omitting the explicit cast to
uint32_t
in both directions. Now when assiginguint32_t foo = RTT_TICKS_TO_US()
with a (static) value larger thenUINT32_MAX
the compiler will shout at you :-)Also added some basic tests for the tick conversion to the test application.
Testing procedure
Run the included version of the test application on any platform of your choice, it should fail. Run it with the fix included in this PR -> it should run successfully..
Issues/PRs references
none