-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.c
83 lines (68 loc) · 2.23 KB
/
Main.c
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
/// @see https://github.com/endurodave/CoreDumpARM
/// @see https://github.com/endurodave/CoreDump
/// David Lafreniere, January 2017.
#include <stm32f10x.h>
#include "CoreDump.h"
#include "Fault.h"
// Defined to generate a hardware exception test. Undefined to
// generate a software fault test.
//#define HARD_FAULT_TEST 1
#if HARD_FAULT_TEST
static int val = 2, zero = 0, result;
#endif
//----------------------------------------------------------------------------
// Call3
//----------------------------------------------------------------------------
int Call3()
{
int stackArr3[5]= { 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333 };
#if HARD_FAULT_TEST
// Cause a divide by 0 exception. HardFault_Handler will be called.
result = val / zero;
#else
// Cause a software fault. FaultHandler() will be called.
ASSERT();
#endif
return stackArr3[0];
}
//----------------------------------------------------------------------------
// Call2
//----------------------------------------------------------------------------
int Call2()
{
int stackArr2[5]= { 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222 };
Call3();
return stackArr2[0];
}
//----------------------------------------------------------------------------
// Call1
//----------------------------------------------------------------------------
int Call1()
{
int stackArr1[5]= { 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111 };
Call2();
return stackArr1[0];
}
//----------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------
int main(void)
{
// Stack memory patterns to assist in viewing stack frame within debugger
int stackArr0[5]= { 0xEFEFEFEF, 0xEFEFEFEF, 0xEFEFEFEF, 0xEFEFEFEF, 0xEFEFEFEF };
// Enable divide by 0 hardware exception
SCB->CCR |= 0x10;
// Did a core dump get saved?
if (IsCoreDumpBoot() == true)
{
// Get the core dump data structure
CoreDumpData* coreDumpData = CoreDumpGet();
// TODO - Save core dump to persistent storage or transmit
// the data to a remote device.
// Reset core dump for next time.
CoreDumpReset();
}
// Create call stack by calling a few functions
Call1();
return stackArr0[0];
}