15#if defined ( __CC_ARM )
16#if (__ARMCC_VERSION < 400000)
19#pragma import _printf_widthprec
26#if defined(DEBUG_ENABLE_SEMIHOST)
36#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 6040000)) || (defined(__ICCARM__) && (__VER__ >= 8000000))
37struct __FILE {
int handle; };
46 printf(
"r0 = 0x%x\n", stack[
r0]);
47 printf(
"r1 = 0x%x\n", stack[
r1]);
48 printf(
"r2 = 0x%x\n", stack[
r2]);
49 printf(
"r3 = 0x%x\n", stack[
r3]);
50 printf(
"r12 = 0x%x\n", stack[
r12]);
51 printf(
"lr = 0x%x\n", stack[
lr]);
52 printf(
"pc = 0x%x\n", stack[
pc]);
53 printf(
"psr = 0x%x\n", stack[
psr]);
58 printf(
"In Hard Fault Handler\n");
70#if defined(DEBUG_ENABLE_SEMIHOST)
73static char g_buf_len = 0;
77# if defined ( __GNUC__ ) && !(__CC_ARM) && !(__ICCARM__)
79# elif defined(__ICCARM__)
102 "LDR R1, [R0, #24] \n"
104 "LDR R2, [pc, #8] \n"
106 "BNE HardFault_Handler_Ret\n"
108 "STR R1, [R0, #24] \n"
111 "HardFault_Handler_Ret:\n"
115 "BEQ Stack_Use_MSP \n"
117 "B Get_LR_and_Branch \n"
120 "Get_LR_and_Branch: \n"
122 "B Hard_Fault_Handler \n"
138int32_t SH_DoCommand(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
184 BNE HardFault_Handler_Ret
197 MRS R0, PSP ;stack use PSP
200 MRS R0, MSP ; stack use MSP
202 MOV R1, LR ; LR current
value
221__asm int32_t SH_DoCommand(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
248# if defined ( __GNUC__ ) && !(__CC_ARM) && !(__ICCARM__)
268 "B Hard_Fault_Handler \n"
271 "B Hard_Fault_Handler \n"
277# elif defined(__ICCARM__)
294 "BEQ Stack_Use_MSP \n"
296 "B Get_LR_and_Branch \n"
299 "Get_LR_and_Branch: \n"
301 "B Hard_Fault_Handler \n"
325 MRS R0, PSP ;stack use PSP
328 MRS R0, MSP ; stack use MSP
330 MOV R1, LR ; LR current
value
368#if defined(DEBUG_ENABLE_SEMIHOST)
369 g_buf[g_buf_len++] = ch;
370 g_buf[g_buf_len] =
'\0';
371 if(g_buf_len + 1 >=
sizeof(g_buf) || ch ==
'\n' || ch ==
'\0')
376 if(SH_DoCommand(0x04, (
int)g_buf,
NULL) != 0)
385 for(i=0;i<g_buf_len;i++)
405#if defined(DEBUG_ENABLE_SEMIHOST)
406# if defined ( __CC_ARM )
408 while(SH_DoCommand(0x101, 0, &nRet) != 0)
412 SH_DoCommand(0x07, 0, &nRet);
418 while(SH_DoCommand(0x7, 0, &nRet) != 0)
486#if defined (__GNUC__) && !defined(__ARMCC_VERSION)
488int _write (
int fd,
char *ptr,
int len)
507int _read (
int fd,
char *ptr,
int len)
529#ifdef DEBUG_ENABLE_SEMIHOST
531void __exit(
int return_code) {
535 if(SH_DoCommand(0x18, 0x20026,
NULL) == 0)
544void _sys_exit(
int return_code) {
547 if(SH_DoCommand(0x18, 0x20026,
NULL) == 0)
Mini51 series peripheral access layer header file. This file contains all the peripheral register's d...
#define UART_FSR_TX_FULL_Msk
#define UART_FSR_RX_EMPTY_Msk
#define UART_FSR_TE_FLAG_Msk
#define UART
Pointer to UART register structure.
#define NULL
NULL pointer.
__asm int32_t HardFault_Handler(void)
This HardFault handler is implemented to show r0, r1, r2, r3, r12, lr, pc, psr.
int IsDebugFifoEmpty(void)
Check whether UART transmit FIFO is empty or not.
void SendChar_ToUART(int ch)
Write a char to UART.
int kbhit(void)
Check whether UART receive FIFO is empty or not.
int fputc(int ch, FILE *f)
void Hard_Fault_Handler(uint32_t stack[])
void SendChar(int ch)
Write a char to debug console.
char GetChar(void)
Read a char from debug console.
void stackDump(uint32_t stack[])