-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Adapt for new fault reporter module
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |