15 #if defined ( __CC_ARM ) 16 #if (__ARMCC_VERSION < 400000) 19 #pragma import _printf_widthprec 24 #define DEBUG_PORT UART0 30 #if defined(DEBUG_ENABLE_SEMIHOST) 40 #if !(defined(__ICCARM__) && (__VER__ >= 6010000)) 53 printf(
"r0 = 0x%x\n", stack[
r0]);
54 printf(
"r1 = 0x%x\n", stack[
r1]);
55 printf(
"r2 = 0x%x\n", stack[
r2]);
56 printf(
"r3 = 0x%x\n", stack[
r3]);
57 printf(
"r12 = 0x%x\n", stack[
r12]);
58 printf(
"lr = 0x%x\n", stack[
lr]);
59 printf(
"pc = 0x%x\n", stack[
pc]);
60 printf(
"psr = 0x%x\n", stack[
psr]);
65 printf(
"In Hard Fault Handler\n");
77 #if defined(DEBUG_ENABLE_SEMIHOST) 79 static char g_buf[16];
80 static char g_buf_len = 0;
84 # if defined ( __GNUC__ ) && !(__CC_ARM) && !(__ICCARM__) 86 # elif defined(__ICCARM__) 109 "LDR R1, [R0, #24] \n" 111 "LDR R2, [pc, #8] \n" 113 "BNE HardFault_Handler_Ret\n" 115 "STR R1, [R0, #24] \n" 118 "HardFault_Handler_Ret:\n" 122 "BEQ Stack_Use_MSP \n" 124 "B Get_LR_and_Branch \n" 127 "Get_LR_and_Branch: \n" 129 "B Hard_Fault_Handler \n" 145 int32_t SH_DoCommand(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
191 BNE HardFault_Handler_Ret
197 HardFault_Handler_Ret
204 MRS R0, PSP ; stack use PSP
207 MRS R0, MSP ; stack use MSP
209 MOV R1, LR ; LR current
value 228 __asm int32_t SH_DoCommand(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
255 # if defined ( __GNUC__ ) && !(__CC_ARM) && !(__ICCARM__) 275 "B Hard_Fault_Handler \n" 278 "B Hard_Fault_Handler \n" 284 # elif defined(__ICCARM__) 301 "BEQ Stack_Use_MSP \n" 303 "B Get_LR_and_Branch \n" 306 "Get_LR_and_Branch: \n" 308 "B Hard_Fault_Handler \n" 332 MRS R0, PSP ;stack use PSP
335 MRS R0, MSP ;stack use MSP
337 MOV R1, LR ;LR current
value 375 #if defined(DEBUG_ENABLE_SEMIHOST) 376 g_buf[g_buf_len++] = ch;
377 g_buf[g_buf_len] =
'\0';
378 if(g_buf_len + 1 >=
sizeof(g_buf) || ch ==
'\n' || ch ==
'\0')
383 if(SH_DoCommand(0x04, (
int)g_buf,
NULL) != 0)
392 for(i=0; i<g_buf_len; i++)
412 #if defined(DEBUG_ENABLE_SEMIHOST) 413 # if defined ( __CC_ARM ) 415 while(SH_DoCommand(0x101, 0, &nRet) != 0)
419 SH_DoCommand(0x07, 0, &nRet);
425 while(SH_DoCommand(0x7, 0, &nRet) != 0)
495 #if defined (__GNUC__) && !defined(__ARMCC_VERSION) 497 int _write (
int fd,
char *ptr,
int len)
516 int _read (
int fd,
char *ptr,
int len)
539 #ifdef DEBUG_ENABLE_SEMIHOST 541 void __exit(
int return_code)
546 if(SH_DoCommand(0x18, 0x20026,
NULL) == 0)
556 void _sys_exit(
int return_code)
560 if(SH_DoCommand(0x18, 0x20026,
NULL) == 0)
char GetChar(void)
Read a char from debug console.
int IsDebugFifoEmpty(void)
Check whether UART transmit FIFO is empty or not.
__asm int32_t HardFault_Handler(void)
This HardFault handler is implemented to show r0, r1, r2, r3, r12, lr, pc, psr.
void SendChar_ToUART(int ch)
Write a char to UART.
#define UART_FSR_TE_F_Msk
void Hard_Fault_Handler(uint32_t stack[])
#define NULL
NULL pointer.
int kbhit(void)
Check whether UART receive FIFO is empty or not.
Nano102/112 peripheral access layer header file. This file contains all the peripheral register's def...
void SendChar(int ch)
Write a char to debug console.
#define UART_FSR_TX_FULL_F_Msk
void stackDump(uint32_t stack[])
#define UART_FSR_RX_EMPTY_F_Msk
int fputc(int ch, FILE *f)