-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (79 loc) · 2.32 KB
/
main.cpp
File metadata and controls
93 lines (79 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* 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::delay(100ms);
// 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\n\n\tscons debug-coredump ";
#ifdef MODM_DEBUG_BUILD
MODM_LOG_ERROR << "profile=debug ";
#endif
MODM_LOG_ERROR << "firmware=" << modm::hex;
for (const auto data : FaultReporter::buildId()) MODM_LOG_ERROR << data;
MODM_LOG_ERROR << "\nor\n\tmake debug-coredump";
#ifdef MODM_DEBUG_BUILD
MODM_LOG_ERROR << " profile=debug";
#endif
MODM_LOG_ERROR << "\n\n";
for (const auto 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 (true)
{
LedGreen::toggle();
LedOrange::toggle();
function2(23, 43);
modm::delay(250ms);
}
return 0;
}