variable mismatch error with ESP_LOG

infynniti
Posts: 2
Joined: Sat Mar 12, 2022 4:27 pm

variable mismatch error with ESP_LOG

Postby infynniti » Mon May 27, 2024 8:24 pm

esp hardware: esp32 WROOM D3
esp-idf version: ESP-IDF 4.2 (previously ESP-IDF 3.3)
compiler: Microsoft Visual C++ (MSVC)
Solution Platform: VisualGDB
IDE: Visual Studio 2022
Toolchain: com.visualgdb.xtensa-esp32-elf 13.2.0/12.1/r1 (originally built with com.visualgdb.xtensa-esp32-elf 8.2.0/8.1.0/r7)

I wanted to look into an old project to see if I could do some debug work on it.
The esp project started off using v3.3 release but was later migrated to v4.2. In v3.3, there is a aws_iot folder in the components folder but this is not present in v4.2

To solve this, I pulled the aws_iot folder and added it to my v4.2 component folder.

When I tried to build, i got some confusing errors.

Most of my errors look like this:

In file included from C:/sysgcc/esp32/esp-idf/v4.2/components/spi_flash/spi_flash_chip_generic.c:19:
C:/sysgcc/esp32/esp-idf/v4.2/components/spi_flash/spi_flash_chip_generic.c: In function 'spi_flash_chip_generic_read':
C:/sysgcc/esp32/esp-idf/v4.2/components/log/include/esp_log.h:256:27: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
256 | #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
| ^~~~~~~~~

C:/sysgcc/esp32/esp-idf/v4.2/components/log/include/esp_log.h:256:27: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
256 | #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
| ^~~~~~~~~

C:/sysgcc/esp32/esp-idf/v4.2/components/spi_flash/spi_flash_chip_generic.c:149:1: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
149 | ESP_LOGE(TAG, "configure host io mode failed - unsupported");
| ^ ~~~

C:/sysgcc/esp32/esp-idf/v4.2/components/spi_flash/partition.c:76:1: error: format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
76 | ESP_LOGD(TAG, "Loading the partition table");
| ^



Some uses of most uses of ESP_LOGx trigger this error while other instances have no problem.
It is worth noting that the source files that have o problem using ESP_LOGx are found in the aws_iot folder but even in those files there are instances where it throws the same error.

I came across a post that seemed to have a similar error when migrating from v3 to v4:
https://esp32.com/viewtopic.php?t=18513

The suggested solution was to insert this line:
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-format)

after the idf_component_register line in a CmakeList.txt (I assume that the CmakList.txt to be changes is in the component that has the issue, for me it would be something like the log folder in components).

I tried this but it actually produces double the errors, most of which seem to be duplicate.
I also tried the solutions suggested in this forum with no luck:
https://github.com/espressif/esp-idf/issues/9511

I know that there is a migration document that has been floating around that says I should change the formatting identifier (my case %u) to match the variable type but I am unsure how to do that when it is a macro.

I also don't see the %u format being used anywhere. I must be missing something but I have hit a dead end.

Any guidance or help would be much appreciated.

infynniti
Posts: 2
Joined: Sat Mar 12, 2022 4:27 pm

Re: variable mismatch error with ESP_LOG

Postby infynniti » Wed Jul 24, 2024 12:31 pm

So I figured out what the problem was. When opening the project in visual studio, a pop-up window informs me that the GGC toolchain this project was made with cannot be found on my computer. It then gives me the option to use a more recent version of the toolchain that is on my desktop or to download the old toolchain. If I try to use a newer version of the toolchain I get the issue described in the post but if I download the old one, I don't see these errors. It stands to reason, I needed to keep all esp-idf versions as well as GCC toolchains matching to build.

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot], SegmentationFault and 106 guests