Skip to content

Fix compilation errors with ESP-IDF 5.x and Arduino Core 3.x#22

Merged
jbtronics merged 3 commits intomasterfrom
copilot/fix-compilation-new-esp-idf
Mar 14, 2026
Merged

Fix compilation errors with ESP-IDF 5.x and Arduino Core 3.x#22
jbtronics merged 3 commits intomasterfrom
copilot/fix-compilation-new-esp-idf

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 11, 2026

The library fails to compile against ESP-IDF 5.x / Arduino Core 3.x due to stricter type checking, API deprecations, removed WiFi methods, and chip info headers being reorganized.

Changes

  • Console.h — Add #include "driver/uart.h". Change uart_channel_ field from uint8_t to uart_port_t. Change the primary begin() overload to accept uart_port_t channel = UART_NUM_0. Add a begin(int, int, int, uint8_t) overload for backward compatibility with older code passing plain integers or uint8_t values.

  • Console.cpp — Update begin() definition to use uart_port_t channel. Gate VFS include and calls on ESP-IDF version: use uart_vfs_dev_* (5.0+) vs esp_vfs_dev_uart_* (legacy).

  • GPIOCommands.cpp — Add missing #include <string> and #include <stdexcept> required for std::stoul / std::invalid_argument.

  • NetworkCommands.cpp — Guard WiFi.localIPv6() behind ESP_ARDUINO_VERSION_MAJOR < 3; method was removed in Arduino Core 3.x.

  • SystemCommands.cpp:

    • Conditionally include <esp_chip_info.h> via __has_include (esp_chip_info_t moved out of esp_system.h in ESP-IDF 5.x).
    • Guard <core_version.h> and <xtensa/xtruntime.h> with __has_include; provide a portable XTSTR fallback for RISC-V targets (ESP32-C3/C6/H2).
    • Guard the Arduino Core version printf on defined(ARDUINO_ESP32_GIT_DESC).

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Console.cpp: Cast uint8_t channel to uart_port_t in UART function calls
- Console.cpp: Use new uart_vfs_dev_* API in ESP-IDF 5.0+ with version guards
- GPIOCommands.cpp: Add missing #include <string> and <stdexcept>
- NetworkCommands.cpp: Guard WiFi.localIPv6() for Arduino Core < 3 only
- SystemCommands.cpp: Conditionally include esp_chip_info.h, guard core_version.h
  and xtruntime.h with __has_include, provide fallback XTSTR for non-Xtensa chips

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compilation issues for new ESP-IDF versions Fix compilation errors with ESP-IDF 5.x and Arduino Core 3.x Mar 11, 2026
@jbtronics
Copy link
Copy Markdown
Owner

@copilot Is this still compatible with the older arduino core versions? Especially if uart_port_t is not available?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot Is this still compatible with the older arduino core versions? Especially if uart_port_t is not available?

Yes, fully backward compatible with older Arduino Core versions:

  • uart_port_t has been defined in driver/uart.h since ESP-IDF 3.x — it's just an enum {UART_NUM_0=0, UART_NUM_1=1, ...}. The explicit cast (uart_port_t)channel is safe on all versions; we're just being explicit to satisfy the stricter type-checking in newer compilers (older compilers accepted the implicit conversion from uint8_t silently).

  • esp_idf_version.h and ESP_IDF_VERSION_VAL have been available since ESP-IDF 3.3.1, so the version guards work fine on old and new targets alike.

  • The VFS functions (esp_vfs_dev_uart_*) are preserved in the #else branch for ESP-IDF < 5.0. They weren't removed in 5.x — only deprecated — so the #if/#else split is the cleanest way to support both without warnings.

Copilot AI requested a review from jbtronics March 13, 2026 23:33
@jbtronics
Copy link
Copy Markdown
Owner

@copilot Make the uart_channel_ field and channel argument of type uart_port_t, and add a overloaded version which accepts an uint8_t

…8_t overload for backward compat

Co-authored-by: jbtronics <5410681+jbtronics@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot Make the uart_channel_ field and channel argument of type uart_port_t, and add a overloaded version which accepts an uint8_t

Done in commit 19cae5f:

  • uart_channel_ field changed from uint8_t to uart_port_t
  • begin() primary overload now takes uart_port_t channel = UART_NUM_0
  • Added a begin(int, int, int, uint8_t) overload that delegates to the typed version via static_cast<uart_port_t> for backward compatibility
  • #include "driver/uart.h" added to Console.h so consumers of the header see uart_port_t
  • Removed the now-redundant (uart_port_t)channel casts throughout Console.cpp

@jbtronics jbtronics marked this pull request as ready for review March 14, 2026 12:03
@jbtronics jbtronics merged commit f758fff into master Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants