Skip to content

Commit 581f7a4

Browse files
pennamfacchinm
authored andcommitted
RP2040: Watchdog: get_reload_value returns 0 if wd is not properly configured
1 parent 1800e0a commit 581f7a4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

targets/TARGET_RASPBERRYPI/TARGET_RP2040/watchdog_api.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
#if DEVICE_WATCHDOG
66

7-
static watchdog_config_t watchdogConfig;
7+
static watchdog_config_t watchdogConfig = {
8+
0 // timeout_ms
9+
};
810

911
watchdog_status_t hal_watchdog_init(const watchdog_config_t *config)
1012
{
11-
watchdogConfig = *config;
1213
// The pico watchdogs accept a maximum value of 0x7fffff
1314
if ( config->timeout_ms < 0x1 && config->timeout_ms > 0x7FFFFF ) {
1415
return WATCHDOG_STATUS_INVALID_ARGUMENT;
1516
}
1617

18+
watchdogConfig = *config;
1719
watchdog_enable(config->timeout_ms, true);
1820

1921
return WATCHDOG_STATUS_OK;
@@ -32,9 +34,12 @@ watchdog_status_t hal_watchdog_stop(void)
3234

3335
uint32_t hal_watchdog_get_reload_value(void)
3436
{
35-
uint32_t load_value = watchdogConfig.timeout_ms * 1000 * 2;
36-
if (load_value > 0xffffffu) {
37-
load_value = 0xffffffu;
37+
uint32_t load_value = 0;
38+
if ( watchdogConfig.timeout_ms > 0 ) {
39+
load_value = watchdogConfig.timeout_ms * 1000 * 2;
40+
if (load_value > 0xffffffu) {
41+
load_value = 0xffffffu;
42+
}
3843
}
3944
return load_value;
4045
}

0 commit comments

Comments
 (0)