ESP32-C3 Enabling GPIO18 and GPIO19 for IO use

skateone
Posts: 7
Joined: Fri May 19, 2017 12:06 pm

ESP32-C3 Enabling GPIO18 and GPIO19 for IO use

Postby skateone » Sun Nov 28, 2021 9:07 pm

hello there.
i hav been going through the config options relating to disabling the USB/JTAG interface and cannot find anything in the docs on how to disable the driver.
I would like to use the GPIO 18 and 19 for io and am struggling getting that right

ESP_Sprite
Posts: 9014
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-C3 Enabling GPIO18 and GPIO19 for IO use

Postby ESP_Sprite » Mon Nov 29, 2021 1:44 am

I think that in newer ESP-IDF versions, you can simply configure these pins as a GPIO in the same way you would normally do (using gpio_config(), or gpio_reset_pin followed by other configuration calls).

espmich
Posts: 4
Joined: Tue Jan 16, 2024 8:32 pm

Re: ESP32-C3 Enabling GPIO18 and GPIO19 for IO use

Postby espmich » Tue Jan 16, 2024 9:06 pm

It's now 2024 and I'm using ESP-IDF 5.1.2 (the most current stable) to try to do as suggested. Like the poster, I want to (re)use GPIO18 and GPIO19 of the ESP32-C3 as tactical switch button inputs. So I'm trying to disable the USB-JTAG driver on these pins.

Code: Select all

// For good measure set GPIO 18 and 19 twice, one time here
gpio_reset_pin(GPIO_NUM_18);
gpio_reset_pin(GPIO_NUM_19);
gpio_set_pull_mode(GPIO_NUM_18, GPIO_PULLDOWN_DISABLE);
gpio_set_pull_mode(GPIO_NUM_18, GPIO_PULLUP_ENABLE);
gpio_set_pull_mode(GPIO_NUM_19, GPIO_PULLDOWN_DISABLE);
gpio_set_pull_mode(GPIO_NUM_19, GPIO_PULLUP_ENABLE);
gpio_set_direction(GPIO_NUM_18, GPIO_MODE_INPUT);
gpio_set_direction(GPIO_NUM_19, GPIO_MODE_INPUT);

// For good measure set GPIO 18 and 19 twice, a second time here
gpio_config_t cfg;
esp_err_t result;
memset(&cfg, 0x0, sizeof(cfg));
cfg.pin_bit_mask |= (1LL << gpio);
cfg.mode = GPIO_MODE_INPUT;
cfg.pull_up_en = GPIO_PULLUP_ENABLE;
cfg.pull_down_en = GPIO_PULLDOWN_DISABLE;
cfg.intr_type = GPIO_INTR_ANYEDGE;
result = gpio_config(&cfg);
Expectation

I should be able to press the tactical switch button on GPIO18 or GPIO19 which drives the pin low and the MCU interrupts, just like I'm doing with GPIO8 and GPIO9. My device has four buttons.

Problem

While GPIO8 and GPIO9 work properly, when I press the button on GPIO18 or GPIO19 then nothing happens and the MCU does not interrupt.

Is anybody else having trouble doing this, and is it because the necessary code is still not in ESP-IDF as of 5.1.2?

I'm using gpio_isr_handler_add() on both GPIO18 and GPIO19. Is that a problem?

There are some CLEAR_PERI_REG_MASK() and REG_SET_BIT() macros that I'm not using, because I'm unsure which parameters to pass. I hope these kinds of macros are not needed, what do you think?

Who is online

Users browsing this forum: No registered users and 84 guests