Esp32 uartSetPins() Error in function - will not compile

The function uartSetPins(), found in esp32-hal-uart.c has two return values the first returns void and the second is the return value from uart_set_pin() which returns either ESP_OK or ESP_FAIL.

I suggest one of these two recommendations: 1. Return ESP_FAIL as the first return value, or 2. modify the function for only 1 return statement at the end of the function.

Function as found in uartSetPins() in esp32-hal-uart.c at line # 147

// Valid pin UART_PIN_NO_CHANGE is defined to (-1)
// Negative Pin Number will keep it unmodified, thus this function can set individual pins
bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)
{
    if(uart_num >= SOC_UART_NUM) {
        log_e("Serial number is invalid, please use numers from 0 to %u", SOC_UART_NUM - 1);
        return;  // <<<--- No Return Value
    }

    // IDF uart_set_pin() will issue necessary Error Message and take care of all GPIO Number validation.
    bool retCode = uart_set_pin(uart_num, txPin, rxPin, rtsPin, ctsPin) == ESP_OK; 
    return retCode;
}

Function minimally modified to return ESP_FAIL on uart_num out of range error:

// Valid pin UART_PIN_NO_CHANGE is defined to (-1)
// Negative Pin Number will keep it unmodified, thus this function can set individual pins
bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)
{
    if(uart_num >= SOC_UART_NUM) {
        log_e("Serial number is invalid, please use numers from 0 to %u", SOC_UART_NUM - 1);
        return ESP_FAIL;
    }

    // IDF uart_set_pin() will issue necessary Error Message and take care of all GPIO Number validation.
    bool retCode = uart_set_pin(uart_num, txPin, rxPin, rtsPin, ctsPin) == ESP_OK; 
    return retCode;
}

One of these should be the return value based on the uart_set_pin() function.

#define ESP_OK          0       /*!< esp_err_t value indicating success (no error) */
#define ESP_FAIL        -1      /*!< Generic esp_err_t code indicating failure */

Function modified for single return value:

// Valid pin UART_PIN_NO_CHANGE is defined to (-1)
// Negative Pin Number will keep it unmodified, thus this function can set individual pins
bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)
{
    if(uart_num < SOC_UART_NUM) {
        // IDF uart_set_pin() will issue necessary Error Message and take care of all GPIO Number validation.
        bool retCode = uart_set_pin(uart_num, txPin, rxPin, rtsPin, ctsPin) == ESP_OK; 
    } else {
    // uart_num Out of range
        bool retCode = ESP_FAIL
        log_e("Serial number is invalid, please use numers from 0 to %u", SOC_UART_NUM - 1);
    }

    return retCode;
}

Hi @peterhouse !

Unfortunately, this is the wrong place for your request. This is the PlatformIO Community Forum. If you want to contact the developers of Espressif Arduino you have to open an issue in Espressif’s arduino-esp32 repository.

Hello @sivar2311,

Thank you for letting me know. I will post this same message there.

In any case, this is where I looked first to solve a problem while compiling my project using Platformio so maybe this posting will help others in the time it takes Espressif to fix their libraries.

Update - This problem was first documented on the github project on September 16 of 2023 and this still has not been fixed. There was some discussion to not fix it since it only issues a warning - I did not delve into versions as I believe I am using the latest version. I will check and get back to this post.