Skip to content

Commit

Permalink
[example] Added watchdog example for Nucleo-F072RB
Browse files Browse the repository at this point in the history
Co-authored-by: Victor Costa <[email protected]>
  • Loading branch information
2 people authored and rleh committed May 5, 2023
1 parent c87056f commit d772940
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/nucleo_f072rb/independend_watchdog/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <modm/board.hpp>
#include <modm/platform.hpp>

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;
}
10 changes: 10 additions & 0 deletions examples/nucleo_f072rb/independend_watchdog/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:nucleo-f072rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f072rb/independend_watchdog</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:iwdg</module>
</modules>
</library>

0 comments on commit d772940

Please sign in to comment.