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

0 commit comments

Comments
 (0)