PlatformIO with ESP32 UART.h does not match ESP Documentation

Hi there

I have been having problems running Expressif ESP32 UART Serial examples in VScode & PlatformIO and have been seeing the following compilation error.

void uart2_init(void) {
    const uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_APB,
    };

Error Message:
class “uart_config_t” has no field “source_clk”
identifier “UART_SCLK_APB” is undefined

It appears that the latest version of the ESP32 Platform (3.3.1) is using the deprecated use_ref_tick method in the uart_config_t definition.

As below;

Platformio ESP32 driver/uart.h file

 /**
 * @brief UART configuration parameters for uart_param_config function
 */
typedef struct {
    int baud_rate;                      /*!< UART baud rate*/
    uart_word_length_t data_bits;       /*!< UART byte size*/
    uart_parity_t parity;               /*!< UART parity mode*/
    uart_stop_bits_t stop_bits;         /*!< UART stop bits*/
    uart_hw_flowcontrol_t flow_ctrl;    /*!< UART HW flow control mode (cts/rts)*/
    uint8_t rx_flow_ctrl_thresh;        /*!< UART HW RTS threshold*/
    bool use_ref_tick;                  /*!< Set to true if UART should be clocked from REF_TICK */
} uart_config_t;

Espressif ESP32 Documentation

/**
 * @brief UART configuration parameters for uart_param_config function
 */
typedef struct {
    int baud_rate;                      /*!< UART baud rate*/
    uart_word_length_t data_bits;       /*!< UART byte size*/
    uart_parity_t parity;               /*!< UART parity mode*/
    uart_stop_bits_t stop_bits;         /*!< UART stop bits*/
    uart_hw_flowcontrol_t flow_ctrl;    /*!< UART HW flow control mode (cts/rts)*/
    uint8_t rx_flow_ctrl_thresh;        /*!< UART HW RTS threshold*/
    union {
        uart_sclk_t source_clk;         /*!< UART source clock selection */
        **bool use_ref_tick  __attribute__((deprecated)); /*!< Deprecated method to select ref tick clock source, set source_clk field instead */**
    };
} uart_config_t;

Yes, PlatformIO uses version 3.3.1 of ESP-IDF.

So you should also refer to the documentation and example programs for the same version:

https://docs.espressif.com/projects/esp-idf/en/release-v3.3/api-reference/peripherals/uart.html

Thanks for that,

The current IDF is at 4.1.2 & I hadn’t made the connection that the PlatformIO revision number was relating to the IDF release being 3.3.1 which was released in Dec 2019.

That’s quite a gap, when I looked there was over 5k commits to the IDF since then.

I will go back to using the documentation for the PlatformIO release.

Regards
Dave

I’ve just figured out that something isn’t quite right. For the ESP-IDF framework, PlatformIO uses version 4.3, which is more or less up-to-date. However, the latest stable Arduino framework for ESP32 uses a rather old version ESP-IDF framework.

Do you have a mixed project combining the Arduino and ESP-IDF framework? Can you show your platformio.ini file?

Hi Manuel

Yes you are on the money there, it was an Arduino project that I have called in some IDF header files.

Good to know, I thought that was it bit strange.

I will move to the full IDF once I get off my Arduino training wheels.