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

Watchdog timer overflow error for big timeout #1523

Open
mrespin opened this issue Jun 8, 2022 · 3 comments
Open

Watchdog timer overflow error for big timeout #1523

mrespin opened this issue Jun 8, 2022 · 3 comments
Labels

Comments

@mrespin
Copy link

mrespin commented Jun 8, 2022

In file hal/architecture/NRF5/drivers/wdt.h line 80:
NRF_WDT->CRV = (32768*timeout)/1000; \
Setting large timeout value generating overflow error.
If changed to
NRF_WDT->CRV = (uint32_t)(32.768*timeout); \
there is no overflow error anymore. Not sure if (uint32_t) cast is needed.

@oxyshad
Copy link

oxyshad commented Jun 8, 2022

You can define the type also in wdt_enable call.
Example with timer of 60 minutes
wdt_enable(60*60*1000UL)

@mrespin
Copy link
Author

mrespin commented Jun 9, 2022

Yes, that is the problem, as wdt_enable expands to:
#define wdt_enable(timeout)
NRF_WDT->CONFIG = NRF_WDT->CONFIG = (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos) | ( WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);
*NRF_WDT->CRV = (32768 * timeout)/1000; *
NRF_WDT->RREN |= WDT_RREN_RR0_Msk;
NRF_WDT->TASKS_START = 1
in hal/architecture/NRF5/drivers/wdt.h

@mfalkvidd mfalkvidd added the nRF5 label Jul 8, 2022
@mrespin
Copy link
Author

mrespin commented Jul 17, 2022

I hope that will help.
src\main.cpp:251:34: warning: integer overflow in expression [-Woverflow]
#define timeout 5 * 60 * 1000
.pio...\MySensors/hal/architecture/NRF5/drivers/wdt.h:80:24: note: in definition of macro 'wdt_enable'
NRF_WDT->CRV = (32768timeout)/1000;
^~~~~~~
Working fix:
NRF_WDT->CRV = (32.768
timeout); \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants