Skip to content

Commit 4bc3e93

Browse files
Copilotjbtronics
andcommitted
Fix compilation errors with newer ESP-IDF/Arduino Core versions
- 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>
1 parent e00a8aa commit 4bc3e93

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/ESP32Console/Commands/GPIOCommands.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "./GPIOCommands.h"
22
#include "Arduino.h"
3+
#include <string>
4+
#include <stdexcept>
35

46
static int _pinmode(int argc, char **argv)
57
{

src/ESP32Console/Commands/NetworkCommands.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ static void ipconfig_wlan()
209209
printf("IP: %s\n", WiFi.localIP().toString().c_str());
210210
printf("Subnet Mask: %s (/%d)\n", WiFi.subnetMask().toString().c_str(), WiFi.subnetCIDR());
211211
printf("Gateway: %s\n", WiFi.gatewayIP().toString().c_str());
212+
#if !defined(ESP_ARDUINO_VERSION_MAJOR) || ESP_ARDUINO_VERSION_MAJOR < 3
212213
printf("IPv6: %s\n", WiFi.localIPv6().toString().c_str());
214+
#endif
213215

214216
printf("\n");
215217
printf("Hostname: %s\n", WiFi.getHostname());

src/ESP32Console/Commands/SystemCommands.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@
44
#include <esp_partition.h>
55
#include <esp_ota_ops.h>
66
#include <esp_system.h>
7+
#if __has_include(<esp_chip_info.h>)
8+
#include <esp_chip_info.h>
9+
#endif
10+
#if __has_include(<core_version.h>)
711
#include <core_version.h>
12+
#endif
813
#include <getopt.h>
914

10-
// For XSTR macros
15+
// For XTSTR macros (Xtensa-specific)
16+
#if __has_include(<xtensa/xtruntime.h>)
1117
#include <xtensa/xtruntime.h>
18+
#else
19+
// Provide a fallback stringification macro for non-Xtensa architectures (e.g. RISC-V)
20+
#ifndef XTSTR
21+
#define _XTSTR(x) #x
22+
#define XTSTR(x) _XTSTR(x)
23+
#endif
24+
#endif
1225

1326
static String mac2String(uint64_t mac)
1427
{
@@ -84,7 +97,9 @@ static int sysInfo(int argc, char **argv)
8497
esp_chip_info(&info);
8598

8699
printf("ESP32Console version: %s\n", ESP32CONSOLE_VERSION);
100+
#if defined(ARDUINO_ESP32_GIT_DESC)
87101
printf("Arduino Core version: %s (%x)\n", XTSTR(ARDUINO_ESP32_GIT_DESC), ARDUINO_ESP32_GIT_VER);
102+
#endif
88103
printf("ESP-IDF Version: %s\n", ESP.getSdkVersion());
89104

90105
printf("\n");

src/ESP32Console/Console.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#include "./Console.h"
22
#include "soc/soc_caps.h"
33
#include "esp_err.h"
4+
#include "esp_idf_version.h"
45
#include "ESP32Console/Commands/CoreCommands.h"
56
#include "ESP32Console/Commands/SystemCommands.h"
67
#include "ESP32Console/Commands/NetworkCommands.h"
78
#include "ESP32Console/Commands/VFSCommands.h"
89
#include "ESP32Console/Commands/GPIOCommands.h"
910
#include "driver/uart.h"
11+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
12+
#include "driver/uart_vfs.h"
13+
#else
1014
#include "esp_vfs_dev.h"
15+
#endif
1116
#include "linenoise/linenoise.h"
1217
#include "ESP32Console/Helpers/PWDHelpers.h"
1318
#include "ESP32Console/Helpers/InputParser.h"
@@ -99,8 +104,8 @@ namespace ESP32Console
99104
this->uart_channel_ = channel;
100105

101106
//Reinit the UART driver if the channel was already in use
102-
if (uart_is_driver_installed(channel)) {
103-
uart_driver_delete(channel);
107+
if (uart_is_driver_installed((uart_port_t)channel)) {
108+
uart_driver_delete((uart_port_t)channel);
104109
}
105110

106111
/* Drain stdout before reconfiguring it */
@@ -111,9 +116,15 @@ namespace ESP32Console
111116
setvbuf(stdin, NULL, _IONBF, 0);
112117

113118
/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
119+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
120+
uart_vfs_dev_port_set_rx_line_endings(channel, ESP_LINE_ENDINGS_CR);
121+
/* Move the caret to the beginning of the next line on '\n' */
122+
uart_vfs_dev_port_set_tx_line_endings(channel, ESP_LINE_ENDINGS_CRLF);
123+
#else
114124
esp_vfs_dev_uart_port_set_rx_line_endings(channel, ESP_LINE_ENDINGS_CR);
115125
/* Move the caret to the beginning of the next line on '\n' */
116126
esp_vfs_dev_uart_port_set_tx_line_endings(channel, ESP_LINE_ENDINGS_CRLF);
127+
#endif
117128

118129
/* Configure UART. Note that REF_TICK is used so that the baud rate remains
119130
* correct while APB frequency is changing in light sleep mode.
@@ -131,21 +142,25 @@ namespace ESP32Console
131142
};
132143

133144

134-
ESP_ERROR_CHECK(uart_param_config(channel, &uart_config));
145+
ESP_ERROR_CHECK(uart_param_config((uart_port_t)channel, &uart_config));
135146

136147
// Set the correct pins for the UART of needed
137148
if (rxPin > 0 || txPin > 0) {
138149
if (rxPin < 0 || txPin < 0) {
139150
log_e("Both rxPin and txPin has to be passed!");
140151
}
141-
uart_set_pin(channel, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
152+
uart_set_pin((uart_port_t)channel, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
142153
}
143154

144155
/* Install UART driver for interrupt-driven reads and writes */
145-
ESP_ERROR_CHECK(uart_driver_install(channel, 256, 0, 0, NULL, 0));
156+
ESP_ERROR_CHECK(uart_driver_install((uart_port_t)channel, 256, 0, 0, NULL, 0));
146157

147158
/* Tell VFS to use UART driver */
159+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
160+
uart_vfs_dev_use_driver(channel);
161+
#else
148162
esp_vfs_dev_uart_use_driver(channel);
163+
#endif
149164

150165
esp_console_config_t console_config = {
151166
.max_cmdline_length = max_cmdline_len_,

0 commit comments

Comments
 (0)