-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdebug_utils.cpp
More file actions
111 lines (94 loc) · 3.24 KB
/
debug_utils.cpp
File metadata and controls
111 lines (94 loc) · 3.24 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Copyright (c) 2021 Ryan Powell. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Arduino.h>
#include "nrf.h"
#include "compiler_abstraction.h"
#include <stdlib.h>
struct exception_frame {
uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
uint32_t r12;
uint32_t lr;
uint32_t pc;
uint32_t psr;
};
extern "C" {
__attribute__ ((__weak__))
void Hardfault_handler_cpp( uint32_t *p_stack_address )
{
exception_frame* ef = (exception_frame*)p_stack_address;
Serial.printf("Unhandled exception 0x%08lx ", SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk);
Serial.printf(", exception sp 0x%08lx\n", (uint32_t)p_stack_address);
Serial.printf("R0: 0x%08lx, , R1: 0x%08lx , R2: 0x%08lx, R3: 0x%08lx, R12: 0x%08lx\n",
ef->r0, ef->r1, ef->r2, ef->r3, ef->r12);
Serial.printf("LR: 0x%08lx, PC: 0x%08lx, PSR: 0x%08lx\n", ef->lr, ef->pc, ef->psr);
NVIC_SystemReset();
}
__attribute__ ((__weak__))
void __assert_func(const char *file, int line, const char *func, const char *e)
{
Serial.printf("Assertion Failed: %s at line %d , in function: %s\n", file, line, func);
yield();
NVIC_SystemReset();
while (1){} // silence compiler
}
__attribute__ ((__weak__))
void __cxa_pure_virtual(void) {
Serial.println("Pure virtual function called");
NVIC_SystemReset();
}
__attribute__ ((__weak__))
void __cxa_deleted_virtual(void) {
Serial.println("Deleted virtual function called");
NVIC_SystemReset();
}
#if __CORTEX_M == 0x00
__attribute__(( naked ))
void HardFault_Handler(void)
{
__asm volatile
(
" .syntax unified \n"
" ldr r0, =0xFFFFFFFD \n"
" cmp r0, lr \n"
" bne _MSP \n"
" mrs r0, PSP \n"
" b _Done \n"
"_MSP: \n"
" mrs r0, MSP \n"
"_Done: \n"
" ldr r3, =Hardfault_handler_cpp \n"
" bx r3 \n"
" .align \n"
);
}
#endif
#if __CORTEX_M == 0x04
__attribute__(( naked ))
void HardFault_Handler(void)
{
__asm volatile
(
" tst lr, #4 \n"
" ite eq \n"
" mrseq r0, msp \n"
" mrsne r0, psp \n"
" b Hardfault_handler_cpp \n"
);
}
#endif
} // extern "C"