Skip to content

Commit a052daa

Browse files
committed
Added a watchdog
This will reset the MCU after 2 seconds of the last poke, which happens during the RTC tick handler in the animation task. Shouldn't be necessary. :( But I've been working on trying to resolve a crash in the MQTT task for ages without success. Not a great solution at all, but I'm telling myself that nearly all non trivial MCU software has them to fix "issues".
1 parent 35017a5 commit a052daa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <hardware/gpio.h>
66
#include <hardware/spi.h>
77
#include <hardware/dma.h>
8+
#include <hardware/watchdog.h>
89
#include <pico/cyw43_arch.h>
910

1011
#include <FreeRTOS.h>
@@ -49,6 +50,9 @@ int main(void)
4950
{
5051
stdio_init_all();
5152

53+
// Let USB UART wake up on a listener.
54+
sleep_ms(1000);
55+
5256
DEBUG_printf("Hello, matrix here\n");
5357

5458
srand(0);
@@ -83,6 +87,14 @@ void animate_task(void *dummy)
8387
DEBUG_printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
8488
#endif
8589

90+
if (watchdog_enable_caused_reboot()) {
91+
DEBUG_printf("Restart caused by watchdog!\n");
92+
} else {
93+
DEBUG_printf("Clean start; not caused by watchdog\n");
94+
}
95+
96+
bool watchdog_enabled = false;
97+
8698
message_anim_t message;
8799
memset(&message, 0, sizeof(message_anim_t));
88100

@@ -123,6 +135,18 @@ void animate_task(void *dummy)
123135
break;
124136

125137
case MESSAGE_ANIM_DS3231:
138+
if (! watchdog_enabled) {
139+
// On the first message from the RTC task, Enable the watchdog
140+
// requiring the watchdog to be updated every 2s or the MCU will
141+
// reboot.
142+
watchdog_enable(2000, 1);
143+
watchdog_enabled = true;
144+
DEBUG_printf("Watchdog enabled\n");
145+
}
146+
else {
147+
// We must now get a new time every two seconds or we will reboot
148+
watchdog_update();
149+
}
126150
anim.new_ds3231(&message.ds3231);
127151
break;
128152

0 commit comments

Comments
 (0)