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;
}