Skip to content

Commit

Permalink
[fault] Add CrashCatcher coredump for HardFaults
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed May 14, 2019
2 parents 840ef29 + dfb7e34 commit 4ab28fe
Show file tree
Hide file tree
Showing 48 changed files with 1,369 additions and 558 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
[submodule "ext/aws/freertos"]
path = ext/aws/freertos
url = https://github.com/modm-ext/freertos-partial.git
[submodule "ext/adamgreen/crashcatcher"]
path = ext/adamgreen/crashcatcher
url = https://github.com/modm-ext/CrashCatcher-partial.git
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ boards:
- NUCLEO-F031K6:
[Blinky & Serial](https://github.com/modm-io/modm/tree/develop/examples/nucleo_f031k6/blink/main.cpp).
- NUCLEO-F103RB:
[Blinky & Serial](https://github.com/modm-io/modm/blob/develop/examples/nucleo_f103rb/blink/main.cpp).
[Blinky & Serial](https://github.com/modm-io/modm/blob/develop/examples/nucleo_f103rb/blink/main.cpp),
[Debugging hard faults](https://github.com/modm-io/modm/blob/develop/examples/nucleo_f103rb/hard_fault/main.cpp).
- STM32F072 Discovery:
[Blinky](https://github.com/modm-io/modm/blob/develop/examples/stm32f072_discovery/blink/main.cpp),
[CAN](https://github.com/modm-io/modm/blob/develop/examples/stm32f072_discovery/can/main.cpp),
Expand All @@ -120,8 +121,7 @@ boards:
[Blinky](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/blink/main.cpp),
[CAN](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/can/main.cpp),
[Accelerometer](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/accelerometer/main.cpp),
[Timer & LED Animations](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/timer/main.cpp),
[Debugging hard faults](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/hard_fault/main.cpp).
[Timer & LED Animations](https://github.com/modm-io/modm/blob/develop/examples/stm32f4_discovery/timer/main.cpp).
- STM32F469 Discovery:
[Blinky](https://github.com/modm-io/modm/blob/develop/examples/stm32f469_discovery/blink/main.cpp),
[Drawing on display](https://github.com/modm-io/modm/blob/develop/examples/stm32f469_discovery/display/main.cpp),
Expand Down
83 changes: 83 additions & 0 deletions examples/nucleo_f103rb/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();
Board::Leds::setOutput(modm::Gpio::High);

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

if (FaultReporter::hasReport())
{
MODM_LOG_ERROR << "\n\nHardFault! Copy the data into a 'coredump.txt' file, ";
MODM_LOG_ERROR << "then execute 'scons postmortem firmware=";
MODM_LOG_ERROR << modm::hex << FaultReporter::firmware() << "'.\n\n";
for (const uint8_t data : FaultReporter())
{
MODM_LOG_ERROR << modm::hex << data << modm::flush;
}
MODM_LOG_ERROR << "\n\n\n" << modm::flush;
FaultReporter::clearAndReboot();
}

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

if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
MODM_LOG_INFO << "Debugger connected!" << modm::endl;
}

while (1)
{
Board::Leds::toggle();

function2(23, 43);

modm::delayMilliseconds(250);
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/nucleo_f103rb/hard_fault/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:nucleo-f103rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f103rb/hard_fault</option>
</options>
<modules>
<module>modm:platform:fault</module>
<module>modm:build:scons</module>
</modules>
</library>
11 changes: 11 additions & 0 deletions examples/stm32f072_discovery/hard_fault/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ main()
Usart1::connect<GpioOutputA9::Tx>();
Usart1::initialize<Board::SystemClock, 115200_Bd>();

if (FaultReporter::hasReport())
{
MODM_LOG_ERROR << "\n\nHardFault! Copy the data into a 'coredump.txt' file, ";
MODM_LOG_ERROR << "then execute 'scons postmortem firmware=";
MODM_LOG_ERROR << modm::hex << FaultReporter::firmware() << "'.\n\n";
for (const uint8_t data : FaultReporter())
MODM_LOG_ERROR << modm::hex << data << modm::flush;
MODM_LOG_ERROR << "\n\n\n" << modm::flush;
FaultReporter::clearAndReboot();
}

MODM_LOG_INFO << "Causing a Hardfault now!" << modm::endl;

// simulate some stack usage
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f072_discovery/hard_fault/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</options>
<modules>
<module>modm:debug</module>
<module>modm:platform:gpio</module>
<module>modm:platform:fault</module>
<module>modm:platform:uart:1</module>
<module>modm:build:scons</module>
</modules>
Expand Down
74 changes: 0 additions & 74 deletions examples/stm32f3_discovery/hard_fault/main.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions examples/stm32f3_discovery/hard_fault/project.xml

This file was deleted.

86 changes: 86 additions & 0 deletions examples/stm32f469_discovery/hard_fault/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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\nHardFault! Copy the data into a 'coredump.txt' file, ";
MODM_LOG_ERROR << "then execute 'scons postmortem firmware=";
MODM_LOG_ERROR << modm::hex << FaultReporter::firmware() << "'.\n\n";
for (const uint8_t data : FaultReporter())
{
MODM_LOG_ERROR << modm::hex << data << modm::flush;
}
MODM_LOG_ERROR << "\n\n\n" << modm::flush;
FaultReporter::clearAndReboot();
}

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="modm:build:build.path">../../../build/stm32f469_discovery/hard_fault</option>
</options>
<modules>
<module>modm:platform:fault</module>
<module>modm:build:scons</module>
</modules>
</library>
Loading

0 comments on commit 4ab28fe

Please sign in to comment.