From d772940ae60738aba4ecfd905b0af2e851da2123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Waldh=C3=A4usl?= Date: Fri, 14 Apr 2023 06:33:16 -0700 Subject: [PATCH] [example] Added watchdog example for Nucleo-F072RB Co-authored-by: Victor Costa --- .../independend_watchdog/main.cpp | 57 +++++++++++++++++++ .../independend_watchdog/project.xml | 10 ++++ 2 files changed, 67 insertions(+) create mode 100644 examples/nucleo_f072rb/independend_watchdog/main.cpp create mode 100644 examples/nucleo_f072rb/independend_watchdog/project.xml diff --git a/examples/nucleo_f072rb/independend_watchdog/main.cpp b/examples/nucleo_f072rb/independend_watchdog/main.cpp new file mode 100644 index 0000000000..a767c4d821 --- /dev/null +++ b/examples/nucleo_f072rb/independend_watchdog/main.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023, Zühlke Engineering (Austria) GmbH + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +#include +#include + +using namespace Board; + +/** + * If the button is pressed for more than 4 seconds, the MCU will be reset by the Watchdog. + * This can be observed by the faster blinking LED after startup. + */ + +int +main() +{ + Board::initialize(); + LedD13::setOutput(); + // set the watchdog timeout to 4 seconds + Iwdg::initialize(Iwdg::Prescaler::Div32, 0x0FFFu); + + // Use the logging streams to print some messages. + // Change MODM_LOG_LEVEL above to enable or disable these messages + MODM_LOG_DEBUG << "debug" << modm::endl; + MODM_LOG_INFO << "info" << modm::endl; + MODM_LOG_WARNING << "warning" << modm::endl; + MODM_LOG_ERROR << "error" << modm::endl; + + uint32_t counter(0); + + while (counter < 10) + { + LedD13::toggle(); + modm::delay(100ms); + MODM_LOG_INFO << "loop: " << counter++ << modm::endl; + } + + Iwdg::enable(); + + while (1) + { + LedD13::toggle(); + modm::delay(500ms); + if (!Button::read()) { Iwdg::trigger(); } + MODM_LOG_INFO << "loop: " << counter++ << modm::endl; + } + + return 0; +} diff --git a/examples/nucleo_f072rb/independend_watchdog/project.xml b/examples/nucleo_f072rb/independend_watchdog/project.xml new file mode 100644 index 0000000000..b75648896d --- /dev/null +++ b/examples/nucleo_f072rb/independend_watchdog/project.xml @@ -0,0 +1,10 @@ + + modm:nucleo-f072rb + + + + + modm:build:scons + modm:platform:iwdg + +