-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (59 loc) · 1.81 KB
/
main.cpp
File metadata and controls
70 lines (59 loc) · 1.81 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
/*
* Copyright (c) 2016-2017, 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>
int
main()
{
Board::initialize();
if (FaultReporter::hasReport())
{
MODM_LOG_ERROR << "\n\nHardFault! Copy the data into a 'coredump.txt' file, ";
MODM_LOG_ERROR << "then execute\n\n\tscons postmortem firmware=" << modm::hex;
for (const auto data : FaultReporter::buildId()) MODM_LOG_ERROR << data;
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 << "Causing a Hardfault now!" << modm::endl;
// simulate some stack usage
asm volatile ("push {r0-r7}");
asm volatile ("push {r0-r7}");
asm volatile ("push {r0-r7}");
asm volatile ("pop {r0-r7}");
asm volatile ("pop {r0-r7}");
asm volatile ("pop {r0-r7}");
// load some patterns into r0-r7
asm volatile ("ldr r0, =0xA000000A");
asm volatile ("ldr r1, =0x0AAAAAA0");
asm volatile ("ldr r2, =0x00A00A00");
asm volatile ("ldr r3, =0x000AA000");
asm volatile ("ldr r4, =0x04040404");
asm volatile ("ldr r5, =0x05050505");
asm volatile ("ldr r6, =0x06060606");
asm volatile ("ldr r7, =0x07070707");
// execute unused stack
asm volatile ("ldr r4, =0x20000247");
asm volatile ("bx r4");
// undefined instruction
asm volatile (".short 0xde00");
// stack overflow
while(true) {
asm volatile ("push {r0-r7}");
}
while (true)
{
modm::delay(1000ms);
Board::LedUp::toggle();
}
return 0;
}