tiny_printf.c uses incorrect file identifiers

Share code examples or discuss embedded software, including device drivers, interrupt handlers, middleware and application code.

Moderators: Markus Girdland, Mattias Norlander

Posts: 2
Joined: Mon Jun 25, 2018 2:38 pm

tiny_printf.c uses incorrect file identifiers

Postby foobar » Mon Jun 25, 2018 3:03 pm

I use fprintf(stderr, ... and fprintf(stdout, ... to differentiate trace output to SWO and UART respectively. This works fine with the default Newlib-nano implementation, but if I compile with Atollic's tiny-printf.c to save flash memory, the file argument in the _write function is always 2048. stderr and stdout is defined in stdio.h

Mattias Norlander
Posts: 265
Joined: Fri Apr 29, 2016 10:01 am

Re: tiny_printf.c uses incorrect file identifiers

Postby Mattias Norlander » Thu Aug 09, 2018 6:33 am

Add the following to your main (as early as possible):

Code: Select all

if ((_REENT) && !(_REENT)->__sdidinit) __sinit(_REENT);

This will initialize the C-library (especially the reent structure) with the correct data.
After the C-library has been initialized, the file descriptor in the _write(....) method will be different depending on if you send stdout or stderr (for example).

Return to “Embedded target code development discussions”

Who is online

Users browsing this forum: No registered users and 2 guests