Error in UART examples (IDFGH-3839) #5746

@phildimond

Description

The UART example code for ESP32 has an error. The driver install must come after the configuration.

For example in the esp-idf/examples/peripherals/uart/uart_echo/ example, the code below in uart_echo_example_main.c will not work if the UART is changed to UART_NUM_2 unless the uart_driver_install is moved after the uart_set_pin.

/* Configure parameters of an UART driver,
 * communication pins and install the driver */
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,
uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0);
uart_param_config(UART_NUM_1, &uart_config);
uart_set_pin(UART_NUM_1, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);