1+ /*
2+ * Copyright (c) 2026, Niklas Hauser
3+ *
4+ * This file is part of the modm project.
5+ *
6+ * This Source Code Form is subject to the terms of the Mozilla Public
7+ * License, v. 2.0. If a copy of the MPL was not distributed with this
8+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+ */
10+ // ----------------------------------------------------------------------------
11+
12+ /*
13+ # nRF5340-DK watchdog (app core)
14+
15+ Watchdog example for the nRF5340 application core.
16+
17+ - Target: `nrf5340-xxaa@app`
18+ - Uses app-core-owned `Led1` and `Button1` from the BSP.
19+ - If `Button1` is held for more than 4 seconds after the watchdog starts,
20+ the MCU resets.
21+ - A watchdog reset is indicated by a faster LED blink sequence after startup.
22+ */
23+
24+ #include < modm/board.hpp>
25+
26+ using namespace Board ;
27+ using namespace std ::chrono_literals;
28+
29+ int
30+ main ()
31+ {
32+ Board::initialize ();
33+ Wdt::initialize<SystemClock, 4s>();
34+ auto startupDelay = 100ms;
35+
36+ MODM_LOG_INFO << " nRF5340-DK watchdog example" << modm::endl;
37+ MODM_LOG_INFO << " Press and hold Button1 for more than 4s to trigger a watchdog reset." << modm::endl;
38+ if (NRF_RESET->RESETREAS & RESET_RESETREAS_DOG0_Msk) {
39+ NRF_RESET->RESETREAS = RESET_RESETREAS_DOG0_Msk;
40+ MODM_LOG_INFO << " Previous reset reason: watchdog." << modm::endl;
41+ startupDelay = 50ms;
42+ }
43+
44+ uint32_t counter (0 );
45+ while (counter < 10 )
46+ {
47+ Led1::toggle ();
48+ modm::delay (startupDelay);
49+ MODM_LOG_INFO << " startup: " << counter++ << modm::endl;
50+ }
51+
52+ Wdt::enable ();
53+ MODM_LOG_INFO << " Watchdog started." << modm::endl;
54+
55+ while (true )
56+ {
57+ Led1::toggle ();
58+ modm::delay (500ms);
59+ if (!Button1::read ()) { Wdt::trigger (); }
60+ MODM_LOG_INFO << " loop: " << counter++ << modm::endl;
61+ }
62+
63+ return 0 ;
64+ }
0 commit comments