Implementation of the printf() function

Cupcake
Posts: 4
Joined: Tue Dec 01, 2020 10:05 am

Implementation of the printf() function

Postby Cupcake » Thu Dec 03, 2020 10:30 am

Hi,

Currently we are using the log output as main debug system on our ESP32 board.

We have some problems with it:
- Sometimes we loose bytes (not transmited ? error during the transmission to the USB Serial Dongle ? We don't really know)
- Sometimes we have some log messages that "cuts" other log messages

We see that ESP_LOGx() macros/functions call the vprintf() function.

We would like to investigate on vprintf() functions especially for the second problem.

We would like to debug in this function to know how the bytes are transmit to uart and to know if there are RTOS things during the process. (queue, semaphore, vTaskYield(), etc)

We found that the code used for this function is defined in newlib and it is provided to the espidf as a library that comes from https://github.com/espressif/newlib-esp32

We are currently debugging this problem with eclipse, GDB and QEMU. (with a substitute-path configured).

The debug works, but not as well, I think the library is not compiled with optimisation for debug because we can step into/step out but sometimes it jumps, it's not really accurate.

I don't find a lot of documentations to build newlib-esp32 on windows so i'm here to ask if someone can send me the compiled library with debugging options enabled or if you know how to build it on windows

celticzy
Posts: 2
Joined: Sat Dec 05, 2020 2:50 am

Re: Implementation of the printf() function

Postby celticzy » Sat Dec 05, 2020 4:05 am

Hi!

I do not think the newlib cause the problems ,the macro ESP_LOGx calls the function esp_log_write, and esp_log_write calls the esp_log_writev like below:
  1. void esp_log_write(esp_log_level_t level,
  2.                    const char *tag,
  3.                    const char *format, ...)
  4. {
  5.     va_list list;
  6.     va_start(list, format);
  7.     esp_log_writev(level, tag, format, list);
  8.     va_end(list);
  9. }

In esp_log_write function, va_start is not reentrant, which is not recommended used in RTOS.

Could you try on your board with modifying esp_log_write function like
  1. void esp_log_write(esp_log_level_t level,
  2.                    const char *tag,
  3.                    const char *format, ...)
  4. {
  5.     va_list list;
  6.  
  7.     mutexLock();//use FreeRTOS mutex
  8.  
  9.     va_start(list, format);
  10.     esp_log_writev(level, tag, format, list);
  11.     va_end(list);
  12.  
  13.     mutexUnlock();//use FreeRTOS mutex
  14. }
,or share your project? (idf version? board type?)

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

Re: Implementation of the printf() function

Postby ESP_Sprite » Sun Dec 06, 2020 4:12 am

Since when is va_start not reentrant? My manuals indicates it as MT-safe.

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: Implementation of the printf() function

Postby PeterR » Wed Dec 09, 2020 1:38 am

I direct ESP_LOGx to UDP and that works fine. I do see some 232 corruptions from time to time though but hey that's 232.
printf() is not declared as RT safe (its pre C++11 for a start) & so you might well see RT issues!
I think you are looking quite deep. Why debug that deep when you could roll your own RT safe logger?
Guess you have to trust that the UART library is RT safe and so that's a very simple wrapper if you wanna do your own logger thing.
But actually ESP_LOGx is RT safe! (k, never checked but 2 years in n having seen plenty of other weird stuff but still each log line has been complete etc).
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: No registered users and 89 guests