Skip to content

Commit d772940

Browse files
wald-zatvictorandrehc
authored andcommitted
[example] Added watchdog example for Nucleo-F072RB
Co-authored-by: Victor Costa <[email protected]>
1 parent c87056f commit d772940

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2023, Zühlke Engineering (Austria) GmbH
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+
#include <modm/board.hpp>
13+
#include <modm/platform.hpp>
14+
15+
using namespace Board;
16+
17+
/**
18+
* If the button is pressed for more than 4 seconds, the MCU will be reset by the Watchdog.
19+
* This can be observed by the faster blinking LED after startup.
20+
*/
21+
22+
int
23+
main()
24+
{
25+
Board::initialize();
26+
LedD13::setOutput();
27+
// set the watchdog timeout to 4 seconds
28+
Iwdg::initialize(Iwdg::Prescaler::Div32, 0x0FFFu);
29+
30+
// Use the logging streams to print some messages.
31+
// Change MODM_LOG_LEVEL above to enable or disable these messages
32+
MODM_LOG_DEBUG << "debug" << modm::endl;
33+
MODM_LOG_INFO << "info" << modm::endl;
34+
MODM_LOG_WARNING << "warning" << modm::endl;
35+
MODM_LOG_ERROR << "error" << modm::endl;
36+
37+
uint32_t counter(0);
38+
39+
while (counter < 10)
40+
{
41+
LedD13::toggle();
42+
modm::delay(100ms);
43+
MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
44+
}
45+
46+
Iwdg::enable();
47+
48+
while (1)
49+
{
50+
LedD13::toggle();
51+
modm::delay(500ms);
52+
if (!Button::read()) { Iwdg::trigger(); }
53+
MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
54+
}
55+
56+
return 0;
57+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<library>
2+
<extends>modm:nucleo-f072rb</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_f072rb/independend_watchdog</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:platform:iwdg</module>
9+
</modules>
10+
</library>

0 commit comments

Comments
 (0)