ESP IDF printf

alb702
Posts: 10
Joined: Tue Dec 07, 2021 3:31 am

ESP IDF printf

Postby alb702 » Wed Jun 01, 2022 8:24 am

Hello.

ESP IDF , Master (or 4.4) , ESP32 (ESP32-PICO-D4) .

Periodicaly (i'm do not know cause) 'printf' is no output to defaut uart, if non-constant format, i.e :

---
printf ("test\n"); // output: test
printf ("number %d\n", 1); // no output
char * line = "line\n";
printf (line); // no output
---

but,
---
fprintf (stdout, "number %d\n", 1); // output: number 1
---

'printf(CONSTANT)' is have output, maybe, because gcc replace 'printf(CONSTANT)' to 'puts(CONSTANT)'.

=================

I'm build tcp server in project, and connect to it from terminal on PC.
All ommited 'printf' output i see in terminal.

How to prevent redirect 'printf' output?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP IDF printf

Postby ESP_igrr » Wed Jun 01, 2022 9:06 am

Is it possible that you are overriding 'stdout' stream anywhere in your code? This would explain why printf output (which uses stdout) goes to the TCP connection and 'stderr' is still printed to the console.

If you can find the minimal code to reproduce this issue, please report it at https://github.com/espressif/esp-idf/issues and we will take a look.

alb702
Posts: 10
Joined: Tue Dec 07, 2021 3:31 am

Re: ESP IDF printf

Postby alb702 » Fri Jun 03, 2022 3:17 am

Thanks.

I temporary removed all my modules, excluding main.c from build in my project.
Printf have output in app_main(). Now i will add module by module to localize problem.

My modules are not change explicitly vfs , stdout, etc... but are used many SDK components.

jimmerkle
Posts: 1
Joined: Fri Feb 24, 2023 10:46 pm

Re: ESP IDF printf

Postby jimmerkle » Fri Feb 24, 2023 11:16 pm

Many stdio libraries will buffer a printf() / stdout stream, collecting characters and sending them as a group, usually triggered by a line feed.
Try disabling stdout buffering:

setvbuf(stdout, NULL, _IONBF, 0); // Disable stdout buffering

Who is online

Users browsing this forum: Bing [Bot], ESP_ondrej and 88 guests