Skip to content

Commit 0720180

Browse files
giulcioffifacchinm
authored andcommitted
RP2040: Implement reset reasons
1 parent a40a192 commit 0720180

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "reset_reason_api.h"
2+
#include "hardware/watchdog.h"
3+
4+
#ifdef DEVICE_RESET_REASON
5+
6+
#include "structs/resets.h"
7+
8+
reset_reason_t hal_reset_reason_get(void)
9+
{
10+
if (watchdog_caused_reboot()) {
11+
return RESET_REASON_WATCHDOG;
12+
} else {
13+
return RESET_REASON_PIN_RESET;
14+
}
15+
16+
return RESET_REASON_UNKNOWN;
17+
}
18+
19+
20+
uint32_t hal_reset_reason_get_raw(void)
21+
{
22+
return resets_hw->reset;
23+
}
24+
25+
26+
void hal_reset_reason_clear(void)
27+
{
28+
for (int i = 1; i < 25; i++) {
29+
hw_clear_bits(&resets_hw->reset, i);
30+
}
31+
}
32+
33+
#endif // DEVICE_RESET_REASON

targets/targets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7977,7 +7977,8 @@
79777977
"SPI",
79787978
"USTICKER",
79797979
"WATCHDOG",
7980-
"USBDEVICE"
7980+
"USBDEVICE",
7981+
"RESET_REASON"
79817982
]
79827983
},
79837984
"NANO_RP2040_CONNECT": {

0 commit comments

Comments
 (0)