Fixes for targets with invalid HardFault_Handler implementation and review/other fixes

pull/5847/head
Senthil Ramakrishnan 2018-01-26 10:19:49 -06:00
parent 29348d823d
commit 96d900c99f
12 changed files with 74 additions and 76 deletions

View File

@ -21,10 +21,11 @@
; * ; *
; * ----------------------------------------------------------------------------- ; * -----------------------------------------------------------------------------
; */ ; */
#ifndef MBED_FAULT_HANDLER_DISABLED
IF :LNOT::DEF:__DOMAIN_NS #ifndef __DOMAIN_NS
__DOMAIN_NS EQU 1 #define __DOMAIN_NS 1
ENDIF #endif
FAULT_TYPE_HARD_FAULT EQU 0x10 FAULT_TYPE_HARD_FAULT EQU 0x10
FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20 FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
@ -66,7 +67,7 @@ UsageFault_Handler\
Fault_Handler PROC Fault_Handler PROC
EXPORT Fault_Handler EXPORT Fault_Handler
IF __DOMAIN_NS = 1 #if (__DOMAIN_NS == 1)
IMPORT osRtxInfo IMPORT osRtxInfo
IMPORT mbed_fault_handler IMPORT mbed_fault_handler
IMPORT mbed_fault_context IMPORT mbed_fault_context
@ -148,8 +149,10 @@ Fault_Handler_Continue2
LDR R1,=mbed_fault_context LDR R1,=mbed_fault_context
LDR R2,=osRtxInfo LDR R2,=osRtxInfo
BLX R3 BLX R3
ENDIF #endif
B . ; Just in case we come back here B . ; Just in case we come back here
ENDP ENDP
#endif
END END

View File

@ -21,14 +21,14 @@
* *
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
#ifndef MBED_FAULT_HANDLER_DISABLED
.file "except.S"
.file "except_cm0.S"
.syntax unified .syntax unified
.ifndef __DOMAIN_NS #ifndef __DOMAIN_NS
.equ __DOMAIN_NS, 1 #define __DOMAIN_NS 1
.endif #endif
.equ FAULT_TYPE_HARD_FAULT, 0x10 .equ FAULT_TYPE_HARD_FAULT, 0x10
.equ FAULT_TYPE_MEMMANAGE_FAULT, 0x20 .equ FAULT_TYPE_MEMMANAGE_FAULT, 0x20
@ -103,7 +103,7 @@ UsageFault_Handler:
.cantunwind .cantunwind
Fault_Handler: Fault_Handler:
.if __DOMAIN_NS == 1 #if (__DOMAIN_NS == 1)
MRS R0,MSP MRS R0,MSP
LDR R1,=0x4 LDR R1,=0x4
MOV R2,LR MOV R2,LR
@ -181,10 +181,14 @@ Fault_Handler_Continue2:
LDR R1,=mbed_fault_context LDR R1,=mbed_fault_context
LDR R2,=osRtxInfo LDR R2,=osRtxInfo
BLX R3 BLX R3
.endif #endif
B . // Just in case we come back here B . // Just in case we come back here
.fnend .fnend
.size Fault_Handler, .-Fault_Handler .size Fault_Handler, .-Fault_Handler
#endif
.end .end

View File

@ -22,25 +22,24 @@
; * ----------------------------------------------------------------------------- ; * -----------------------------------------------------------------------------
; */ ; */
NAME except.S
NAME except_cm0.s
#ifndef __DOMAIN_NS
#define __DOMAIN_NS 1
#endif
FAULT_TYPE_HARD_FAULT EQU 0x10 FAULT_TYPE_HARD_FAULT EQU 0x10
FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20 FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
FAULT_TYPE_BUS_FAULT EQU 0x30 FAULT_TYPE_BUS_FAULT EQU 0x30
FAULT_TYPE_USAGE_FAULT EQU 0x40 FAULT_TYPE_USAGE_FAULT EQU 0x40
#ifndef MBED_FAULT_HANDLER_DISABLED
#ifndef __DOMAIN_NS
#define __DOMAIN_NS 1
#endif
PRESERVE8 PRESERVE8
SECTION .rodata:DATA:NOROOT(2) SECTION .rodata:DATA:NOROOT(2)
THUMB THUMB
SECTION .text:CODE:NOROOT(2) SECTION .text:CODE:NOROOT(2)
HardFault_Handler HardFault_Handler
EXPORT HardFault_Handler EXPORT HardFault_Handler
LDR R3,=FAULT_TYPE_HARD_FAULT LDR R3,=FAULT_TYPE_HARD_FAULT
@ -147,5 +146,6 @@ Fault_Handler_Continue2
BLX R3 BLX R3
#endif #endif
B . ; Just in case we come back here B . ; Just in case we come back here
#endif ; #if (MBED_FAULT_HANDLER_SUPPORT == 1)
END END

View File

@ -19,6 +19,7 @@
#include "mbed_rtx_fault_handler.h" #include "mbed_rtx_fault_handler.h"
#include "hal/serial_api.h" #include "hal/serial_api.h"
#ifndef MBED_FAULT_HANDLER_DISABLED
//Global for populating the context in exception handler //Global for populating the context in exception handler
mbed_fault_context_t mbed_fault_context; mbed_fault_context_t mbed_fault_context;
@ -36,17 +37,29 @@ extern int stdio_uart_inited;
extern serial_t stdio_uart; extern serial_t stdio_uart;
#endif #endif
//This is a handler function called from Fault handler to print the error information out.
//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.
__NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn) __NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn)
{ {
fault_print_init(); fault_print_init();
fault_print_str("\n++ MbedOS Fault Handler ++\n\nFaultType: ",NULL); fault_print_str("\n++ MbedOS Fault Handler ++\n\nFaultType: ",NULL);
switch( fault_type ) { switch( fault_type ) {
case HARD_FAULT_EXCEPTION: fault_print_str("HardFault",NULL); break; case HARD_FAULT_EXCEPTION:
case MEMMANAGE_FAULT_EXCEPTION: fault_print_str("MemManageFault",NULL); break; fault_print_str("HardFault",NULL);
case BUS_FAULT_EXCEPTION: fault_print_str("BusFault",NULL); break; break;
case USAGE_FAULT_EXCEPTION: fault_print_str("UsageFault",NULL); break; case MEMMANAGE_FAULT_EXCEPTION:
default: fault_print_str("Unknown Fault",NULL); break; fault_print_str("MemManageFault",NULL);
break;
case BUS_FAULT_EXCEPTION:
fault_print_str("BusFault",NULL);
break;
case USAGE_FAULT_EXCEPTION:
fault_print_str("UsageFault",NULL);
break;
default:
fault_print_str("Unknown Fault",NULL);
break;
} }
fault_print_str("\n\nContext:",NULL); fault_print_str("\n\nContext:",NULL);
print_context_info(); print_context_info();
@ -71,7 +84,7 @@ __NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_conte
fault_print_str("\n\n-- MbedOS Fault Handler --\n\n",NULL); fault_print_str("\n\n-- MbedOS Fault Handler --\n\n",NULL);
/* Just spin here, we have alrady crashed */ /* Just spin here, we have already crashed */
for (;;) {} for (;;) {}
} }
@ -211,3 +224,5 @@ void hex_to_str(uint32_t value, char *hex_str)
hex_str[i] = hex_char_map[(value & (0xf << (i * 4))) >> (i * 4)]; hex_str[i] = hex_char_map[(value & (0xf << (i * 4))) >> (i * 4)];
} }
} }
#endif //MBED_FAULT_HANDLER_SUPPORT

View File

@ -46,5 +46,7 @@ typedef struct {
#define BUS_FAULT_EXCEPTION (0x30) #define BUS_FAULT_EXCEPTION (0x30)
#define USAGE_FAULT_EXCEPTION (0x40) #define USAGE_FAULT_EXCEPTION (0x40)
//This is a handler function called from Fault handler to print the error information out.
//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.
__NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn); __NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn);

View File

@ -68,12 +68,6 @@ void NotImplemented_Handler(void)
while (1) {}; while (1) {};
} }
/** Hardware fault interrupt handler */
void HardFault_Handler(void)
{
while (1) {};
}
/************************************************************************************************* /*************************************************************************************************
* * * *
* Functions * * Functions *

View File

@ -236,11 +236,3 @@ uint8_t SetSysClock_PLL_HSI(void)
return 1; // OK return 1; // OK
} }
/******************************************************************************/
/* Hard Fault Handler */
/******************************************************************************/
void HardFault_Handler(void)
{
debug("Hard Fault\n");
NVIC_SystemReset();
}

View File

@ -236,11 +236,3 @@ uint8_t SetSysClock_PLL_HSI(void)
return 1; // OK return 1; // OK
} }
/******************************************************************************/
/* Hard Fault Handler */
/******************************************************************************/
void HardFault_Handler(void)
{
debug("Hard Fault\n");
NVIC_SystemReset();
}

View File

@ -238,11 +238,3 @@ uint8_t SetSysClock_PLL_HSI(void)
return 1; // OK return 1; // OK
} }
/******************************************************************************/
/* Hard Fault Handler */
/******************************************************************************/
void HardFault_Handler(void)
{
debug("Hard Fault\n");
NVIC_SystemReset();
}

View File

@ -249,12 +249,4 @@ uint8_t SetSysClock_PLL_HSI(void)
return 1; // OK return 1; // OK
} }
/******************************************************************************/
/* Hard Fault Handler */
/******************************************************************************/
void HardFault_Handler(void)
{
debug("Hard Fault\n");
NVIC_SystemReset();
}

View File

@ -3718,7 +3718,7 @@
} }
}, },
"inherits": ["Target"], "inherits": ["Target"],
"macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\""], "macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\"","MBED_FAULT_HANDLER_DISABLED"],
"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"], "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"],
"release_versions": ["5"], "release_versions": ["5"],
"device_name": "NANO130KE3BN" "device_name": "NANO130KE3BN"
@ -3756,7 +3756,7 @@
"inherits": ["Target"], "inherits": ["Target"],
"detect_code": ["4600"], "detect_code": ["4600"],
"extra_labels": ["Realtek", "AMEBA", "RTL8195A"], "extra_labels": ["Realtek", "AMEBA", "RTL8195A"],
"macros": ["__RTL8195A__","CONFIG_PLATFORM_8195A","CONFIG_MBED_ENABLED","PLATFORM_CMSIS_RTOS"], "macros": ["__RTL8195A__","CONFIG_PLATFORM_8195A","CONFIG_MBED_ENABLED","PLATFORM_CMSIS_RTOS","MBED_FAULT_HANDLER_DISABLED"],
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"], "supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SPI", "TRNG", "EMAC", "FLASH"], "device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SPI", "TRNG", "EMAC", "FLASH"],
"features": ["LWIP"], "features": ["LWIP"],

View File

@ -1,4 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
"""
mbed SDK
Copyright (c) 2017-2019 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
LIBRARIES BUILD
"""
from __future__ import print_function from __future__ import print_function
from os import path from os import path
@ -25,7 +43,6 @@ class ElfHelper(object):
self.maplines = map_file.readlines() self.maplines = map_file.readlines()
self.matches = ptn.findall(op) self.matches = ptn.findall(op)
self.addrs = [int(x[0],16) for x in self.matches] self.addrs = [int(x[0],16) for x in self.matches]
#print(self.maplines)
def function_addrs(self): def function_addrs(self):
return self.addrs return self.addrs
@ -37,18 +54,14 @@ class ElfHelper(object):
def file_name_for_function_name(self, funcname): def file_name_for_function_name(self, funcname):
for eachline in self.maplines: for eachline in self.maplines:
#print("%s:%s"%(eachline,funcname))
result = eachline.find(funcname) result = eachline.find(funcname)
if(result != -1): if(result != -1):
break break
toks = eachline.split() toks = eachline.split()
#print("%s:%s"%(str(funcname),str(toks)))
if(len(toks) <= 0): if(len(toks) <= 0):
print("WARN: Unable to find %s in map file"%(str(funcname))) print("WARN: Unable to find %s in map file"%(str(funcname)))
#return funcname
return ("%s [FUNCTION]"%(str(funcname))) return ("%s [FUNCTION]"%(str(funcname)))
else: else:
#return toks[-1].replace("./BUILD/","").replace("/","\\")
return toks[-1] return toks[-1]
def parseHFSR(hfsr): def parseHFSR(hfsr):
@ -143,7 +156,6 @@ def main(input):
eachline=lines[i] eachline=lines[i]
if(-1 != eachline.find("--- MbedOS Fault Handler ---")): if(-1 != eachline.find("--- MbedOS Fault Handler ---")):
break break
#print(eachline)
if(eachline.startswith("PC")): if(eachline.startswith("PC")):
l = re.findall(r"[\w']+", eachline) l = re.findall(r"[\w']+", eachline)