-
Notifications
You must be signed in to change notification settings - Fork 3k
ST: Watchdog: Fix timeout registers value calculation #11178
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
Conversation
@Tharazi97, thank you for your changes. |
TESTS/mbed_drivers/watchdog/main.cpp
Outdated
@@ -18,6 +18,10 @@ | |||
#error [NOT_SUPPORTED] Watchdog not supported for this target | |||
#else | |||
|
|||
#ifndef MAX_IWDG_PR | |||
#define MAX_IWDG_PR 0x6 |
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.
Why is the max pre-scaler defined as 6 ?
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.
Right, I didn't look to other targets than STM and assumed that it is used like this in all boards. I'll take a peek to other drivers and make it work on all devices.
Test run: FAILEDSummary: 3 of 3 test jobs failed Failed test jobs:
|
TESTS/mbed_drivers/watchdog/main.cpp
Outdated
// The watchdog should trigger at, or after the timeout value. | ||
TEST_ASSERT(watchdog.get_timeout() >= max_timeout); | ||
// The watchdog should trigger at, or after the timeout value - maximum time spend on prescaller. | ||
uint32_t max_window = ceil((float)(4 << MAX_IWDG_PR) * 1000 / LSI_VALUE); |
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.
this is also one MCU family specific value. See LSI_VALUE
error in the build logs.
The test need to be generic and using driver functionality (=test).
I've changed the function in stm watchdog_api.c so it rounds the value of timeout up. This makes the test pass, but it still needs to be discussed if it's the right way of doing that. @fkjagodzinski might help in clarifying this problem. |
TESTS/mbed_drivers/watchdog/main.cpp
Outdated
@@ -225,7 +225,7 @@ void test_start_max_timeout() | |||
Watchdog &watchdog = Watchdog::get_instance(); | |||
uint32_t max_timeout = watchdog.get_max_timeout(); | |||
TEST_ASSERT_TRUE(watchdog.start(max_timeout)); | |||
// The watchdog should trigger at, or after the timeout value. | |||
// The watchdog should trigger at, or after the timeout value; |
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.
this change is not related. the rest of the comments in this file has it as it was. please revert
This currently is touching only ST targets, this should be stated (title and updated comment about the scope of this fix) |
6e9eafd
to
eb558de
Compare
eb558de
to
302be42
Compare
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.
- Please clean up the commit history -- if you make an update and then revert it, this shouldn't be visible here.
- Please update the commit messages -- e.g. change in stm watchdog doesn't say much. The commit message may be as long as you need it to be to explain why and what was updated. Take a look at our commit history for reference.
- If the code needs an
astyle
update to pass the CI, please keep that in a separate commit.
targets/TARGET_STM/watchdog_api.c
Outdated
|
||
// Convert Prescaler_divider bits (PR) of Prescaler_register (IWDG_PR) and a timeout value [ms] | ||
// to Watchdog_counter_reload_value bits (RL) of Reload_register (IWDG_RLR) | ||
#define PR_TIMEOUT_MS2RL(PR_BITS, TIMEOUT_MS) \ | ||
((TIMEOUT_MS) * (LSI_VALUE) / (PR2PRESCALER_DIV(PR_BITS)) / 1000UL) | ||
((uint32_t)ceil((float)(TIMEOUT_MS) * (LSI_VALUE) / (PR2PRESCALER_DIV(PR_BITS)) / 1000UL)) |
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.
Avoid using floating point if possible. The code below will give same values as ceil()
.
((uint32_t)ceil((float)(TIMEOUT_MS) * (LSI_VALUE) / (PR2PRESCALER_DIV(PR_BITS)) / 1000UL)) | |
(((TIMEOUT_MS) * (LSI_VALUE) / (PR2PRESCALER_DIV(PR_BITS)) + 999UL) / 1000UL) |
targets/TARGET_STM/watchdog_api.c
Outdated
const uint32_t rl = PR_TIMEOUT_MS2RL(pr, config->timeout_ms); | ||
uint32_t rl = PR_TIMEOUT_MS2RL(pr, config->timeout_ms); | ||
if (rl > MAX_IWDG_RL) { | ||
rl = MAX_IWDG_RL; |
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.
Isn't that a dead code? pr != INVALID_IWDG_PR
should guarantee that rl
is also valid.
@Tharazi97 could you also update the name and the description of this PR? From what I see now, this could be as simple as ST: Watchdog: Fix timeout registers value calculation. ;) |
302be42
to
a75d43b
Compare
Change the calculation method of rl so it is rounded up.
a75d43b
to
df43350
Compare
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.
NUCLEO_L073RZ watchdog tests are now OK!
DISCO_L475VG_IOT01A watchdog tests are still OK.
Thx for the fix
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
@donatieng we fixed a watchdog issue related to NUCLEO_L073RZ and someother STM target, you might need to aware of this change |
Description
Proposition of fixing: #11175
Changes only implementation of watchdog on ST devices, but problem applies mainly to the meaning of this test. I don't know if this is a right way of fixing that. @fkjagodzinski might help.
Pull request type
Reviewers
@maciejbocianski @mprse @jamesbeyond @fkjagodzinski
Release Notes