14#if defined (__ICCARM__)
15 #pragma diag_suppress=Pm150
19#if defined ( __CC_ARM )
20 #if (__ARMCC_VERSION < 400000)
23 #pragma import _printf_widthprec
27#ifdef DEBUG_ENABLE_UART1
28#define DEBUG_PORT UART1
30#define DEBUG_PORT UART0
39#if !(defined(__ICCARM__) && (__VER__ >= 6010000))
40#if (__ARMCC_VERSION < 6040000)
46#if !defined(__MICROLIB)
47 #if (__OPTIMIZE__ == -O0)
48 __asm(
".global __ARM_use_no_argv\n\t" "__ARM_use_no_argv:\n\t");
53#elif(__VER__ >= 8000000)
63#if defined (__ARMCC_VERSION) || defined (__ICCARM__)
64 extern int32_t SH_DoCommand(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0);
66 #if defined( __ICCARM__ )
72 uint32_t ProcessHardFault(uint32_t
lr, uint32_t msp, uint32_t psp);
78int fputc(
int ch, FILE *stream);
80#if defined ( __GNUC__ ) && !defined (__ARMCC_VERSION)
81 #if !defined (OS_USE_SEMIHOSTING)
82 int _read(
int fd,
char *ptr,
int len);
85 int _write(
int fd,
char *ptr,
int len);
88#if defined (__ARMCC_VERSION) || defined (__ICCARM__)
89 int fgetc(FILE *stream);
121#if defined(DEBUG_ENABLE_SEMIHOST)
124static char g_buf[16];
125static char g_buf_len = 0;
137int32_t
SH_Return(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
142 *pn32Out_R0 = n32In_R0;
153#if defined ( __GNUC__ ) && !defined (__ARMCC_VERSION)
170 "LDR R3, =ProcessHardFault \n"
177int32_t
SH_Return(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0);
178int32_t
SH_Return(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
187#if defined( __ICCARM__ )
192uint32_t ProcessHardFault(uint32_t
lr, uint32_t msp, uint32_t psp)
201#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
210 sp = (uint32_t *)psp;
214 sp = (uint32_t *)msp;
217#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
223 sp = (uint32_t *)__TZ_get_PSP_NS();
225 sp = (uint32_t *)__TZ_get_MSP_NS();
244 printf(
" HardFault!\n\n");
263#ifndef NONBLOCK_PRINTF
268 if ((
char)ch ==
'\n')
284 static uint8_t u8Buf[
BUF_SIZE] = {0};
285 static int32_t i32Head = 0;
286 static int32_t i32Tail = 0;
296 i32Tmp = i32Head + 1;
300 if (i32Tmp != i32Tail)
302 u8Buf[i32Head] =
'\r';
307 i32Tmp = i32Head + 1;
311 if (i32Tmp != i32Tail)
319 if (i32Tail == i32Head)
326 i32Tmp = i32Tail + 1;
337 }
while (i32Tail != i32Head);
352#if !defined( __ICCARM__ )
353 #define __WEAK __attribute__((weak))
357#if defined(DEBUG_ENABLE_SEMIHOST)
358 g_buf[g_buf_len++] = ch;
359 g_buf[g_buf_len] =
'\0';
361 if (g_buf_len + 1 >=
sizeof(g_buf) || ch ==
'\n' || ch ==
'\0')
367 if (SH_DoCommand(0x04, (
int)g_buf,
NULL) != 0)
376#if (DEBUG_ENABLE_SEMIHOST == 1)
379 for (i = 0; i < g_buf_len; i++)
404#ifdef DEBUG_ENABLE_SEMIHOST
408#if defined (__ICCARM__)
411 while (SH_DoCommand(0x7, 0, &nRet) != 0)
420 while (SH_DoCommand(0x101, 0, &nRet) != 0)
424 SH_DoCommand(0x07, 0, &nRet);
435#if (DEBUG_ENABLE_SEMIHOST == 1)
537#if defined ( __GNUC__ ) && !defined (__ARMCC_VERSION)
539#if defined (OS_USE_SEMIHOSTING)
543int _write(
int fd,
char *ptr,
int len)
565int _read(
int fd,
char *ptr,
int len)
613#ifdef DEBUG_ENABLE_SEMIHOST
615void __exit(
int return_code)
618 if (SH_DoCommand(0x18, 0x20026,
NULL) == 0)
630void _sys_exit(
int return_code)
633 if (SH_DoCommand(0x18, 0x20026,
NULL) == 0)
Mini58 series peripheral access layer header file. This file contains all the peripheral register's d...
#define UART_FIFOSTS_TXFULL_Msk
#define UART_FIFOSTS_TXEMPTYF_Msk
#define UART_FIFOSTS_RXEMPTY_Msk
#define M16(addr)
Get a 16-bit unsigned value from specified address.
#define NULL
NULL pointer.
static void DumpStack(uint32_t stack[])
Helper function to dump register while hard fault occurred.
int32_t SH_Return(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
void _ttywrch(int ch)
C library retargetting.
int fputc(int ch, FILE *stream)
Write character to stream.
int ferror(FILE *stream)
Check error indicator.
int IsDebugFifoEmpty(void)
Check if debug message finished.
void SendChar_ToUART(int ch)
Routine to send a char.
int kbhit(void)
Check any char input from UART.
int fgetc(FILE *stream)
Get character from UART debug port or semihosting input.
#define __WEAK
Routine to send a char.
char GetChar(void)
Routine to get a char.
static volatile int32_t g_ICE_Conneced