18 #if !defined(USE_STDIO_USART)
32 void retarget_init(
void)
36 setvbuf(stdout, NULL, _IONBF, 0);
46 static inline uint32_t
_semi(uint32_t syscall,
void *param)
72 :
"r" (syscall),
"r" (param)
75 :
"r0",
"r1",
"r2",
"r3",
"ip",
"lr",
"memory",
"cc"
83 SEMI_SYS_WRITE = 0x05,
84 SEMI_SYS_WRITEC = 0x03,
85 SEMI_SYS_WRITE0 = 0x04,
86 SEMI_SYS_READC = 0x07,
89 SEMI_SYS_CLOSE = 0x02,
107 static int semi_write(
int fd,
const void *ptr,
size_t len)
109 struct semi_3_params params =
116 return _semi(SEMI_SYS_WRITE, ¶ms);
119 static int semi_read(
int fd,
void *ptr,
size_t len)
121 struct semi_3_params params =
128 int status =
_semi(SEMI_SYS_READ, ¶ms);
146 int _open(
const char *pathname,
int flags)
164 case O_WRONLY|O_CREAT|O_TRUNC:
169 case O_WRONLY|O_CREAT|O_APPEND:
179 case O_RDWR|O_CREAT|O_TRUNC:
184 case O_RDWR|O_CREAT|O_APPEND:
194 struct semi_3_params params =
196 .w1 = (uint32_t)pathname,
201 return _semi(SEMI_SYS_OPEN, ¶ms);
206 return _semi(SEMI_SYS_CLOSE, &fd);
209 int _lseek(
int fd,
long offset,
int whence)
228 struct semi_3_params params =
234 return _semi(SEMI_SYS_SEEK, ¶ms);
237 int _fstat(
int fd,
struct stat *sbuf)
239 memset(sbuf, 0x0,
sizeof(*sbuf));
240 sbuf->st_size =
_semi(SEMI_SYS_FLEN, &fd);
242 if (sbuf->st_size < 0)
251 int _write(
int fd,
const char *ptr,
size_t len)
257 if ( (fd == STDOUT_FILENO || fd == STDERR_FILENO) && auto_crlf)
259 for (i = 0 ; i < len ; i++)
266 _semi(SEMI_SYS_WRITEC, &cr);
268 _semi(SEMI_SYS_WRITEC, &c);
273 semi_write(fd, ptr, len);
279 int _read(
int fd,
char *ptr,
int len)
282 if (fd == STDIN_FILENO)
284 *ptr =
_semi(SEMI_SYS_READC, NULL);
287 _write(STDOUT_FILENO, ptr, 1);
292 result = semi_read(fd, ptr, len);
297 void _ttywrch(
int ci)
300 _write(STDOUT_FILENO, &c, 1);
static uint32_t _semi(uint32_t syscall, void *param)
Semihosting communication.
void * memset(void *dest, int n, size_t n)
libheivs configuration file
#define USE_STDIO_AUTO_CR_BEFORE_LF
Put a CR ('') before every LF (' ') on stdout (and stderr)
#define USE_STDIO_ECHO
Enable echo for stdio.
#define debugger_is_connected()
Detect is debugger is connected.
size_t strlen(const char *str)
#define USE_STDIO_NOBUF
Disable stdio buffering.