Skip to content

Commit

Permalink
[examples] Adapt for new fault reporter module
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed May 11, 2019
1 parent 2e3b670 commit 80a34fc
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ make gdb

## Interesting Examples

We have a lot of examples, <!--examplecount-->175<!--/examplecount--> to be
We have a lot of examples, <!--examplecount-->176<!--/examplecount--> to be
exact, but here are some of our favorite examples for our supported development
boards:

Expand Down
83 changes: 83 additions & 0 deletions examples/stm32f469_discovery/hard_fault/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2019, Niklas Hauser
*
* 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>
using namespace Board;

__attribute__((noinline))
void function1(uint32_t bla)
{
static_cast<void>(bla);

if (Button::read()) {
// execute undefined instructed
// the hard fault handler will blink the blue LED
// or, if the debugger is connected, will trigger a breakpoint
asm volatile (".short 0xde00");
}
}

__attribute__((noinline))
void function2(uint32_t bla, uint8_t blub)
{
static_cast<void>(blub);
function1(bla);
}

void modm_hardfault_entry()
{
// Put hardware in safe mode here
Board::Leds::set();
// But do not wait forever
modm::delayMilliseconds(100);
// Do not depend on interrupts in this function (buffered UART etc!)
}

// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
LedOrange::set();

uint32_t *const ptr = new uint32_t[20*1024];
MODM_LOG_INFO << "Can I allocate 20kB? answer: " << ptr << modm::endl;

if (FaultReporter::hasReport())
{
MODM_LOG_ERROR << "\n\n=== CrashCatcher === HardFault === CoreDump ===\n\n";
for (const uint8_t data : FaultReporter())
{
MODM_LOG_ERROR << modm::hex << data << modm::flush;
}
MODM_LOG_ERROR << "\n\n\n" << modm::flush;
}

MODM_LOG_INFO << "Hold Button to cause a Hardfault!" << modm::endl;

if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
// if this LED is on, the debugger is connected
LedRed::set();
MODM_LOG_INFO << "Debugger connected!" << modm::endl;
}

while (1)
{
LedGreen::toggle();
LedOrange::toggle();

function2(23, 43);

modm::delayMilliseconds(250);
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/stm32f469_discovery/hard_fault/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:disco-f469ni</extends>
<options>
<option name=":build:build.path">../../../build/stm32f469_discovery/hard_fault</option>
</options>
<modules>
<module>:platform:fault</module>
<module>:build:scons</module>
</modules>
</library>

0 comments on commit 80a34fc

Please sign in to comment.