14#if defined (__ICCARM__)
15 #pragma diag_suppress=Pm150
19#if defined ( __CC_ARM )
20 #if (__ARMCC_VERSION < 400000)
23 #pragma import _printf_widthprec
28 #define DEBUG_PORT UART0
36#if !(defined(__ICCARM__) && (__VER__ >= 6010000))
37#if (__ARMCC_VERSION < 6040000)
43#if !defined(__MICROLIB)
44 #if (__OPTIMIZE__ == -O0)
45 __asm(
".global __ARM_use_no_argv\n\t" "__ARM_use_no_argv:\n\t");
50#elif(__VER__ >= 8000000)
60#if defined (__ARMCC_VERSION) || defined (__ICCARM__)
61 extern int32_t SH_DoCommand(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0);
63 #if defined( __ICCARM__ )
69 uint32_t ProcessHardFault(uint32_t
lr, uint32_t msp, uint32_t psp);
75int fputc(
int ch, FILE *stream);
77#if defined ( __GNUC__ ) && !defined (__ARMCC_VERSION)
78 #if !defined (OS_USE_SEMIHOSTING)
79 int _read(
int fd,
char *ptr,
int len);
82 int _write(
int fd,
char *ptr,
int len);
85#if defined (__ARMCC_VERSION) || defined (__ICCARM__)
86 int fgetc(FILE *stream);
118#if defined(DEBUG_ENABLE_SEMIHOST)
121static char g_buf[16];
122static char g_buf_len = 0;
134int32_t
SH_Return(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
139 *pn32Out_R0 = n32In_R0;
150#if defined ( __GNUC__ ) && !defined (__ARMCC_VERSION)
167 "LDR R3, =ProcessHardFault \n"
174int32_t
SH_Return(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0);
175int32_t
SH_Return(int32_t n32In_R0, int32_t n32In_R1, int32_t *pn32Out_R0)
184#if defined( __ICCARM__ )
189uint32_t ProcessHardFault(uint32_t
lr, uint32_t msp, uint32_t psp)
198#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
207 sp = (uint32_t *)psp;
211 sp = (uint32_t *)msp;
214#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
220 sp = (uint32_t *)__TZ_get_PSP_NS();
222 sp = (uint32_t *)__TZ_get_MSP_NS();
241 printf(
" HardFault!\n\n");
260#ifndef NONBLOCK_PRINTF
265 if ((
char)ch ==
'\n')
281 static uint8_t u8Buf[
BUF_SIZE] = {0};
282 static int32_t i32Head = 0;
283 static int32_t i32Tail = 0;
293 i32Tmp = i32Head + 1;
297 if (i32Tmp != i32Tail)
299 u8Buf[i32Head] =
'\r';
304 i32Tmp = i32Head + 1;
308 if (i32Tmp != i32Tail)
316 if (i32Tail == i32Head)
323 i32Tmp = i32Tail + 1;
334 }
while (i32Tail != i32Head);
349#if !defined( __ICCARM__ )
350 #define __WEAK __attribute__((weak))
354#if defined(DEBUG_ENABLE_SEMIHOST)
355 g_buf[g_buf_len++] = ch;
356 g_buf[g_buf_len] =
'\0';
358 if (g_buf_len + 1 >=
sizeof(g_buf) || ch ==
'\n' || ch ==
'\0')
364 if (SH_DoCommand(0x04, (
int)g_buf,
NULL) != 0)
373#if (DEBUG_ENABLE_SEMIHOST == 1)
376 for (i = 0; i < g_buf_len; i++)
401#ifdef DEBUG_ENABLE_SEMIHOST
405#if defined (__ICCARM__)
408 while (SH_DoCommand(0x7, 0, &nRet) != 0)
417 while (SH_DoCommand(0x101, 0, &nRet) != 0)
421 SH_DoCommand(0x07, 0, &nRet);
432#if (DEBUG_ENABLE_SEMIHOST == 1)
534#if defined ( __GNUC__ ) && !defined (__ARMCC_VERSION)
536#if defined (OS_USE_SEMIHOSTING)
540int _write(
int fd,
char *ptr,
int len)
562int _read(
int fd,
char *ptr,
int len)
610#ifdef DEBUG_ENABLE_SEMIHOST
612void __exit(
int return_code)
615 if (SH_DoCommand(0x18, 0x20026,
NULL) == 0)
627void _sys_exit(
int return_code)
630 if (SH_DoCommand(0x18, 0x20026,
NULL) == 0)
NANO103 peripheral access layer header file. This file contains all the peripheral register's definit...
#define UART_FIFOSTS_TXENDF_Msk
#define UART_FIFOSTS_TXFULL_Msk
#define UART_FIFOSTS_RXEMPTY_Msk
#define M16(addr)
Get a 16-bit unsigned value from specified address.
#define NULL
NULL pointer.
__attribute__((weak))
A callback called by library while smartcard request for a time extension.
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