From 73709984b0eba1282473751427daa160e1a5c9f4 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 26 Jul 2019 08:36:11 -0400 Subject: [PATCH] stm32f4: Add support for watchdog Signed-off-by: Kevin O'Connor --- src/stm32f4/Makefile | 2 +- src/stm32f4/watchdog.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/stm32f4/watchdog.c 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 +// +// 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);