Skip to content

Commit 96d900c

Browse files
committed
Fixes for targets with invalid HardFault_Handler implementation and review/other fixes
1 parent 29348d8 commit 96d900c

File tree

12 files changed

+74
-76
lines changed

12 files changed

+74
-76
lines changed

rtos/TARGET_CORTEX/TARGET_CORTEX_M/TOOLCHAIN_ARM/except.S

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
; *
2222
; * -----------------------------------------------------------------------------
2323
; */
24-
25-
IF :LNOT::DEF:__DOMAIN_NS
26-
__DOMAIN_NS EQU 1
27-
ENDIF
28-
24+
#ifndef MBED_FAULT_HANDLER_DISABLED
25+
26+
#ifndef __DOMAIN_NS
27+
#define __DOMAIN_NS 1
28+
#endif
29+
2930
FAULT_TYPE_HARD_FAULT EQU 0x10
3031
FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
3132
FAULT_TYPE_BUS_FAULT EQU 0x30
@@ -66,7 +67,7 @@ UsageFault_Handler\
6667
6768
Fault_Handler PROC
6869
EXPORT Fault_Handler
69-
IF __DOMAIN_NS = 1
70+
#if (__DOMAIN_NS == 1)
7071
IMPORT osRtxInfo
7172
IMPORT mbed_fault_handler
7273
IMPORT mbed_fault_context
@@ -148,8 +149,10 @@ Fault_Handler_Continue2
148149
LDR R1,=mbed_fault_context
149150
LDR R2,=osRtxInfo
150151
BLX R3
151-
ENDIF
152+
#endif
152153
B . ; Just in case we come back here
153154
ENDP
154155
156+
#endif
157+
155158
END

rtos/TARGET_CORTEX/TARGET_CORTEX_M/TOOLCHAIN_GCC/except.S

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
*
2222
* -----------------------------------------------------------------------------
2323
*/
24+
#ifndef MBED_FAULT_HANDLER_DISABLED
2425

25-
26-
.file "except_cm0.S"
26+
.file "except.S"
2727
.syntax unified
28-
29-
.ifndef __DOMAIN_NS
30-
.equ __DOMAIN_NS, 1
31-
.endif
32-
28+
29+
#ifndef __DOMAIN_NS
30+
#define __DOMAIN_NS 1
31+
#endif
32+
3333
.equ FAULT_TYPE_HARD_FAULT, 0x10
3434
.equ FAULT_TYPE_MEMMANAGE_FAULT, 0x20
3535
.equ FAULT_TYPE_BUS_FAULT, 0x30
@@ -103,7 +103,7 @@ UsageFault_Handler:
103103
.cantunwind
104104

105105
Fault_Handler:
106-
.if __DOMAIN_NS == 1
106+
#if (__DOMAIN_NS == 1)
107107
MRS R0,MSP
108108
LDR R1,=0x4
109109
MOV R2,LR
@@ -181,10 +181,14 @@ Fault_Handler_Continue2:
181181
LDR R1,=mbed_fault_context
182182
LDR R2,=osRtxInfo
183183
BLX R3
184-
.endif
184+
#endif
185185
B . // Just in case we come back here
186186
187187
.fnend
188188
.size Fault_Handler, .-Fault_Handler
189189

190+
#endif
191+
190192
.end
193+
194+

rtos/TARGET_CORTEX/TARGET_CORTEX_M/TOOLCHAIN_IAR/except.S

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,24 @@
2222
; * -----------------------------------------------------------------------------
2323
; */
2424

25-
26-
NAME except_cm0.s
25+
NAME except.S
2726
28-
#ifndef __DOMAIN_NS
29-
#define __DOMAIN_NS 1
30-
#endif
31-
3227
FAULT_TYPE_HARD_FAULT EQU 0x10
3328
FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
3429
FAULT_TYPE_BUS_FAULT EQU 0x30
3530
FAULT_TYPE_USAGE_FAULT EQU 0x40
3631

32+
#ifndef MBED_FAULT_HANDLER_DISABLED
33+
34+
#ifndef __DOMAIN_NS
35+
#define __DOMAIN_NS 1
36+
#endif
3737
PRESERVE8
3838
SECTION .rodata:DATA:NOROOT(2)
3939
4040
THUMB
4141
SECTION .text:CODE:NOROOT(2)
4242

43-
4443
HardFault_Handler
4544
EXPORT HardFault_Handler
4645
LDR R3,=FAULT_TYPE_HARD_FAULT
@@ -147,5 +146,6 @@ Fault_Handler_Continue2
147146
BLX R3
148147
#endif
149148
B . ; Just in case we come back here
149+
#endif ; #if (MBED_FAULT_HANDLER_SUPPORT == 1)
150150

151151
END

rtos/TARGET_CORTEX/mbed_rtx_fault_handler.c renamed to rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mbed_rtx_fault_handler.h"
2020
#include "hal/serial_api.h"
2121

22+
#ifndef MBED_FAULT_HANDLER_DISABLED
2223
//Global for populating the context in exception handler
2324
mbed_fault_context_t mbed_fault_context;
2425

@@ -36,17 +37,29 @@ extern int stdio_uart_inited;
3637
extern serial_t stdio_uart;
3738
#endif
3839

40+
//This is a handler function called from Fault handler to print the error information out.
41+
//This runs in fault context and uses special functions(defined in mbed_rtx_fault_handler.c) to print the information without using C-lib support.
3942
__NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn)
4043
{
4144
fault_print_init();
4245
fault_print_str("\n++ MbedOS Fault Handler ++\n\nFaultType: ",NULL);
4346

4447
switch( fault_type ) {
45-
case HARD_FAULT_EXCEPTION: fault_print_str("HardFault",NULL); break;
46-
case MEMMANAGE_FAULT_EXCEPTION: fault_print_str("MemManageFault",NULL); break;
47-
case BUS_FAULT_EXCEPTION: fault_print_str("BusFault",NULL); break;
48-
case USAGE_FAULT_EXCEPTION: fault_print_str("UsageFault",NULL); break;
49-
default: fault_print_str("Unknown Fault",NULL); break;
48+
case HARD_FAULT_EXCEPTION:
49+
fault_print_str("HardFault",NULL);
50+
break;
51+
case MEMMANAGE_FAULT_EXCEPTION:
52+
fault_print_str("MemManageFault",NULL);
53+
break;
54+
case BUS_FAULT_EXCEPTION:
55+
fault_print_str("BusFault",NULL);
56+
break;
57+
case USAGE_FAULT_EXCEPTION:
58+
fault_print_str("UsageFault",NULL);
59+
break;
60+
default:
61+
fault_print_str("Unknown Fault",NULL);
62+
break;
5063
}
5164
fault_print_str("\n\nContext:",NULL);
5265
print_context_info();
@@ -71,7 +84,7 @@ __NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_conte
7184

7285
fault_print_str("\n\n-- MbedOS Fault Handler --\n\n",NULL);
7386

74-
/* Just spin here, we have alrady crashed */
87+
/* Just spin here, we have already crashed */
7588
for (;;) {}
7689
}
7790

@@ -211,3 +224,5 @@ void hex_to_str(uint32_t value, char *hex_str)
211224
hex_str[i] = hex_char_map[(value & (0xf << (i * 4))) >> (i * 4)];
212225
}
213226
}
227+
228+
#endif //MBED_FAULT_HANDLER_SUPPORT

rtos/TARGET_CORTEX/mbed_rtx_fault_handler.h renamed to rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ typedef struct {
4646
#define BUS_FAULT_EXCEPTION (0x30)
4747
#define USAGE_FAULT_EXCEPTION (0x40)
4848

49+
//This is a handler function called from Fault handler to print the error information out.
50+
//This runs in fault context and uses special functions(defined in mbed_rtx_fault_handler.c) to print the information without using C-lib support.
4951
__NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn);
5052

targets/TARGET_ONSEMI/TARGET_NCS36510/exceptions.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ void NotImplemented_Handler(void)
6868
while (1) {};
6969
}
7070

71-
/** Hardware fault interrupt handler */
72-
void HardFault_Handler(void)
73-
{
74-
while (1) {};
75-
}
76-
7771
/*************************************************************************************************
7872
* *
7973
* Functions *

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/device/system_clock.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,3 @@ uint8_t SetSysClock_PLL_HSI(void)
236236
return 1; // OK
237237
}
238238

239-
/******************************************************************************/
240-
/* Hard Fault Handler */
241-
/******************************************************************************/
242-
void HardFault_Handler(void)
243-
{
244-
debug("Hard Fault\n");
245-
NVIC_SystemReset();
246-
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/system_clock.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,3 @@ uint8_t SetSysClock_PLL_HSI(void)
236236
return 1; // OK
237237
}
238238

239-
/******************************************************************************/
240-
/* Hard Fault Handler */
241-
/******************************************************************************/
242-
void HardFault_Handler(void)
243-
{
244-
debug("Hard Fault\n");
245-
NVIC_SystemReset();
246-
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/system_clock.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,3 @@ uint8_t SetSysClock_PLL_HSI(void)
238238
return 1; // OK
239239
}
240240

241-
/******************************************************************************/
242-
/* Hard Fault Handler */
243-
/******************************************************************************/
244-
void HardFault_Handler(void)
245-
{
246-
debug("Hard Fault\n");
247-
NVIC_SystemReset();
248-
}

targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/system_clock.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,4 @@ uint8_t SetSysClock_PLL_HSI(void)
249249
return 1; // OK
250250
}
251251

252-
/******************************************************************************/
253-
/* Hard Fault Handler */
254-
/******************************************************************************/
255-
void HardFault_Handler(void)
256-
{
257-
debug("Hard Fault\n");
258-
NVIC_SystemReset();
259-
}
260252

targets/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,7 +3718,7 @@
37183718
}
37193719
},
37203720
"inherits": ["Target"],
3721-
"macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\""],
3721+
"macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\"","MBED_FAULT_HANDLER_DISABLED"],
37223722
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH"],
37233723
"release_versions": ["5"],
37243724
"device_name": "NANO130KE3BN"
@@ -3756,7 +3756,7 @@
37563756
"inherits": ["Target"],
37573757
"detect_code": ["4600"],
37583758
"extra_labels": ["Realtek", "AMEBA", "RTL8195A"],
3759-
"macros": ["__RTL8195A__","CONFIG_PLATFORM_8195A","CONFIG_MBED_ENABLED","PLATFORM_CMSIS_RTOS"],
3759+
"macros": ["__RTL8195A__","CONFIG_PLATFORM_8195A","CONFIG_MBED_ENABLED","PLATFORM_CMSIS_RTOS","MBED_FAULT_HANDLER_DISABLED"],
37603760
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
37613761
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SPI", "TRNG", "EMAC", "FLASH"],
37623762
"features": ["LWIP"],

tools/debug_tools/crash_log_parser/crash_log_parser.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
#!/usr/bin/env python
2+
"""
3+
mbed SDK
4+
Copyright (c) 2017-2019 ARM Limited
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
LIBRARIES BUILD
19+
"""
220

321
from __future__ import print_function
422
from os import path
@@ -25,8 +43,7 @@ def __init__(self, p,m):
2543
self.maplines = map_file.readlines()
2644
self.matches = ptn.findall(op)
2745
self.addrs = [int(x[0],16) for x in self.matches]
28-
#print(self.maplines)
29-
46+
3047
def function_addrs(self):
3148
return self.addrs
3249

@@ -37,18 +54,14 @@ def function_name_for_addr(self, addr):
3754

3855
def file_name_for_function_name(self, funcname):
3956
for eachline in self.maplines:
40-
#print("%s:%s"%(eachline,funcname))
4157
result = eachline.find(funcname)
4258
if(result != -1):
4359
break
4460
toks = eachline.split()
45-
#print("%s:%s"%(str(funcname),str(toks)))
4661
if(len(toks) <= 0):
4762
print("WARN: Unable to find %s in map file"%(str(funcname)))
48-
#return funcname
4963
return ("%s [FUNCTION]"%(str(funcname)))
5064
else:
51-
#return toks[-1].replace("./BUILD/","").replace("/","\\")
5265
return toks[-1]
5366

5467
def parseHFSR(hfsr):
@@ -143,7 +156,6 @@ def main(input):
143156
eachline=lines[i]
144157
if(-1 != eachline.find("--- MbedOS Fault Handler ---")):
145158
break
146-
#print(eachline)
147159

148160
if(eachline.startswith("PC")):
149161
l = re.findall(r"[\w']+", eachline)

0 commit comments

Comments
 (0)