aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/stm32f4/Makefile2
-rw-r--r--src/stm32f4/watchdog.c25
2 files changed, 26 insertions, 1 deletions
diff --git a/src/stm32f4/Makefile b/src/stm32f4/Makefile
index 4263208f..6ed6a52b 100644
--- a/src/stm32f4/Makefile
+++ b/src/stm32f4/Makefile
@@ -11,7 +11,7 @@ CFLAGS += -Ilib/cmsis-core -Ilib/stm32f4/include
CFLAGS += -DSTM32F446xx
# Add source files
-src-y += stm32f4/main.c stm32f4/clock.c stm32f4/gpio.c
+src-y += stm32f4/main.c stm32f4/clock.c stm32f4/watchdog.c stm32f4/gpio.c
src-y += generic/crc16_ccitt.c generic/alloc.c
src-y += generic/armcm_irq.c generic/armcm_timer.c
src-y += ../lib/stm32f4/system_stm32f4xx.c
diff --git a/src/stm32f4/watchdog.c b/src/stm32f4/watchdog.c
new file mode 100644
index 00000000..1f642616
--- /dev/null
+++ b/src/stm32f4/watchdog.c
@@ -0,0 +1,25 @@
+// Watchdog handler on STM32F4
+//
+// Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "internal.h" // IWDG
+#include "sched.h" // DECL_TASK
+
+void
+watchdog_reset(void)
+{
+ IWDG->KR = 0xAAAA;
+}
+DECL_TASK(watchdog_reset);
+
+void
+watchdog_init(void)
+{
+ IWDG->KR = 0x5555;
+ IWDG->PR = 0;
+ IWDG->RLR = 0x0FFF; // 512ms timeout
+ IWDG->KR = 0xCCCC;
+}
+DECL_INIT(watchdog_init);