[Q/BUG] ets_printf("\r") gives me never only \r (0x0D )

User avatar
rudi ;-)
Posts: 1728
Joined: Fri Nov 13, 2015 3:25 pm

[Q/BUG] ets_printf("\r") gives me never only \r (0x0D )

Postby rudi ;-) » Sat Sep 07, 2019 8:24 pm

hi guys

i remember we have this theme many times.

i want simple formated print out

Code: Select all

while (1) ets_printf("VAL: %d\r",val);
so the terminal is allways in one line and prints the line in the same line cause i use only "\r" for the format


this was changed / removed:

Code: Select all

Component config -> ESP32-specific config ->  Standard-out output adds carriage return before newline
i know we can setup in menuconfig the uart now on other way..
uart_out.jpg
uart_out.jpg (36.35 KiB) Viewed 4880 times


but i get not the result which i need.

here is my setup and code and result:

Code: Select all

Menuconfig		CODE			Result
------------------------------------------------------
CR			\n			\r\n
CR			\r			----
CR			---			----

LF			\n			\r\n
LF			\r			----
LF			---			----

CRLF			\n			\r\n
CRLF			\r			----
CRLF			\r\n			\r\n
i never get only \r or only \n

the declaration ets_printf is only in the header available, the definitation is in the lib

my workaround for this is, to print out without any CR / LF
and send a sign behind

Code: Select all

while (1) {
ets_printf("VAL: %d",val);
uart_tx_one_char('\r');
}
this is not a good solution if you use time criticals and the sendbuffer is splitted.

why append ets_printf chars to the output what we not set?
why delete ets_printf chars from the outgoing what we want send?

Unfortunately, ets_printf adds an additional \r for each \n which is not send by user.

this topic has often annoyed me hours, days and weeks in the begin
because the slave is waiting for certain character encoding
but never gets :(

please, do not delete in the bin_blob_lib chars what we want send.
this is - why i am not a friend to the bin_blob_libs what we can not edit or controll in open soucre.

( annoy me again about it )

rudi
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: [Q/BUG] ets_printf("\r") gives me never only \r (0x0D )

Postby WiFive » Sun Sep 08, 2019 12:42 am

ets_printf is a ROM function so it can't be changed at compile time

https://github.com/espressif/esp-idf/bl ... p32.rom.ld

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: [Q/BUG] ets_printf("\r") gives me never only \r (0x0D )

Postby ESP_Sprite » Mon Sep 09, 2019 3:29 am

That is technically true, but it doesn't mean you can't change its behaviour. From what I can see here (but the code I have here is not exactly the same as the ESP32 version, so take with a grain of salt.) ets_printf uses a callback function to actually output characters, and by default it is set to ets_write_char_uart, which does \n->\r\n-conversion. However, you can change this using the ets_install_putc1 function. From what I can see here, doing ets_install_putc1(uart_tx_one_char); should bypass the conversion logic and do what you want.

User avatar
rudi ;-)
Posts: 1728
Joined: Fri Nov 13, 2015 3:25 pm

Re: [Q/BUG] ets_printf("\r") gives me never only \r (0x0D )

Postby rudi ;-) » Mon Sep 09, 2019 1:59 pm

txs you guys,
i come back at weekend to this again.
jeroen, i read the header notice but did not register this to my brain :) .
i will try it. txs!

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Who is online

Users browsing this forum: No registered users and 131 guests