Skip to content

Commit 1016fea

Browse files
committed
Redirect stdout to serial
1 parent 56f441b commit 1016fea

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

cores/esp8266/libc_replacements.c

+21-14
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,49 @@ int ICACHE_RAM_ATTR _fstat_r(struct _reent* unused, int file, struct stat *st) {
6666
return 0;
6767
}
6868

69-
int _lseek_r(struct _reent* unused, int file, int ptr, int dir) {
69+
int ICACHE_RAM_ATTR _lseek_r(struct _reent* unused, int file, int ptr, int dir) {
7070
(void)unused;
7171
(void)file;
7272
(void)ptr;
7373
(void)dir;
7474
return 0;
7575
}
7676

77-
int _read_r(struct _reent* unused, int file, char *ptr, int len) {
77+
int ICACHE_RAM_ATTR _read_r(struct _reent* unused, int file, char *ptr, int len) {
7878
(void)unused;
7979
(void)file;
8080
(void)ptr;
8181
(void)len;
8282
return 0;
8383
}
8484

85-
int _write_r(struct _reent* unused, int file, char *ptr, int len) {
86-
(void)unused;
87-
(void)file;
88-
(void)ptr;
85+
int ICACHE_RAM_ATTR _write_r(struct _reent* r, int file, char *ptr, int len) {
86+
if (file == STDOUT_FILENO) {
87+
while(len--) {
88+
ets_putc(*ptr);
89+
++ptr;
90+
}
91+
}
8992
return len;
9093
}
9194

92-
// newlib has 'putchar' defined to a big scary construct
93-
#undef putchar
95+
int ICACHE_RAM_ATTR puts(const char * str) {
96+
char c;
97+
while((c = *str) != 0) {
98+
ets_putc(c);
99+
++str;
100+
}
101+
ets_putc('\n');
102+
return true;
103+
}
94104

105+
#undef putchar
95106
int ICACHE_RAM_ATTR putchar(int c) {
96-
return ets_putc(c);
107+
ets_putc(c);
108+
return c;
97109
}
98110

99-
100111
#if 0
101-
int ICACHE_RAM_ATTR puts(const char * str) {
102-
return ets_printf("%s", str);
103-
}
104-
105112

106113
int ICACHE_RAM_ATTR printf(const char* format, ...) {
107114
int ret;

tools/sdk/lib/make_libcmin.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ lib_a-psignal.o
259259
# lib_a-putchar_u.o
260260
lib_a-putenv.o
261261
lib_a-putenv_r.o
262-
lib_a-puts.o
262+
# lib_a-puts.o
263263
lib_a-putw.o
264264
lib_a-putwc.o
265265
lib_a-putwchar.o

0 commit comments

Comments
 (0)