newlib getchar()

Some time ago I wrote the syscalls.c file with all functions to use malloc and printf from newlib, and everything worked.

Now I’m trying to use getchar() from newlib, and so I implemented _read_r, the low level function required by getchar(), but it does not work.

It seems that all functions related to stream reading do not work: getchar, getc, scanf, gets, fgets…

getchar() always return 0xff, I traced the function calls, and looks like it calls __srget_r() that calls __srefill_r(), and then returns… it doesn’t even call _read_r :?

Someone got getchar() working? any advice? Am I missing some initialization step?

You might want to check this out

http://www.aeolusdevelopment.com/Articles/download.html

Andy

Fixed.

The problem was that I compiled newlib with --enable-newlib-reent-small,

to reduce RAM and FLASH used by newlib.

I don’t know why, but look like this flag causes bugs in many functions.

To solve the problem I recompiled newlib without that flag. Now printf is 10KBytes bigger, but at least it works :slight_smile: