Page 1 of 1

Re-using GPIO 1 & 3

Posted: Sat Apr 06, 2019 10:57 am
by NevynSelby
I have an application that needs to reuse the UART0 pins for GPIO and I am trying to work out how to do it.

I have used make menuconfig and changed the debug UART output pin for UART0 to pins 21 and 22. When the ESP32 is restarted I see the initial debug information going to pins 1 & 3 (this is OK). I then switch the UART0 pins to 21 and 22. When I connect a FTDI cable to 22 I get output from ESP_LOGI(...) output as expected.

So the first part of the problem looks to be solved, I can still get debug output.

It is the next part I am having problems with. I try to reconfigure the GPIO pins as output but the output always seems to be high even when I set the pin to a low state.

To compound the problem, when I hook a scope to the original Tx pin for UART0 I get what appears to be serial data being transmitted. This makes me think that the pins are still associated with UART0 in some way.

This simple test application illustrates the problem:

Code: Select all

#include "freertos/FreeRTOS.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "soc/uart_struct.h"
#include "esp_log.h"

void app_main(void)
{
    uart_driver_delete(UART_NUM_0);
    const uart_config_t loggingUARTConfig =
    {
        .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
    };
    uart_param_config(UART_NUM_0, &loggingUARTConfig);
    uart_set_pin(UART_NUM_0, GPIO_NUM_22, GPIO_NUM_21, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    uart_driver_install(UART_NUM_0, 2 * 1024, 2 * 1024, 0, NULL, 0);

    gpio_set_direction(GPIO_NUM_3, GPIO_MODE_OUTPUT);
    bool level = false;
    while (true)
    {
        ESP_LOGI(__func__, "Setting output level to %d", level ? 1 : 0);
        gpio_set_level(GPIO_NUM_3, level ? 1 : 0);
        level = !level;
        vTaskDelay(250 / portTICK_PERIOD_MS);
    }
}
Has anyone managed to remap these pins to GPIO?

Regards,
Mark

Re: Re-using GPIO 1 & 3

Posted: Sat Apr 06, 2019 11:32 am
by WiFive
gpio_pad_select_gpio

Re: Re-using GPIO 1 & 3

Posted: Sat Apr 06, 2019 11:41 am
by NevynSelby
Spot on - thank you for your help.

Regards,
Mark