ESP32-C6 GPIO0 issue

dmaxben
Posts: 110
Joined: Thu Nov 16, 2017 6:04 pm

ESP32-C6 GPIO0 issue

Postby dmaxben » Thu Oct 02, 2025 2:45 am

Is there something special about GPIO-0 on the ESP32-C6? Specifically the ESP32-C6-MINI-1-N4. Using ESP-IDF v5.5.1.

It does not mention anything in the datasheet, it is not a strapping pin.

I am building a device with 3 CAN busses. I know that the ESP32-C6 only has two TWAI controllers, so im using the IOMUX to allow software to select any 2 of the 3 CAN busses for use.

I have the following setup in my design:

CAN-1 Rx - GPIO4
CAN-1 Tx - GPIO5
CAN-2 Rx - GPIO6
CAN-2 Tx - GPIO22
CAN-3 Rx - GPIO1
CAN-3 Tx - GPIO0

CAN 1, CAN 2 seem to work fine. CAN 3 seems to work for Rx/receive only.

In the ESP-LOG window, it prints a message upon boot saying "esp_twai: GPIO 0 is not usable, maybe used by others"

Line 151 in esp_twai_onchip.c:

Code: Select all

    node->gpio_reserved = reserve_mask;
    uint64_t busy_mask = esp_gpio_reserve(reserve_mask);
    uint64_t conflict_mask = busy_mask & reserve_mask;
    for (; conflict_mask > 0;) {
        uint8_t pos = __builtin_ctzll(conflict_mask);
        conflict_mask &= ~(1ULL << pos);
        ESP_LOGW(TAG, "GPIO %d is not usable, maybe used by others", pos);
    }
    return ESP_OK;
Why is GPIO0 not allowed to be used by TWAI? There is NO mention in the TWAI documents or ESP32-C6 datasheets about this limitation of GPIO0.

Luckily I only had a handful of prototype boards made, this could have been catastrophic if I had done a full production run without knowing this hidden TWAI limitation...

Sprite
Espressif staff
Espressif staff
Posts: 10593
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-C6 GPIO0 issue

Postby Sprite » Thu Oct 02, 2025 5:12 am

Are you initializing other peripherals as well? Maybe you're forgetting to set a pin number in a configuration struct used to initialize some peripheral? If so, that member will automatically get set to 0, causing that gpio to be reserved.

dmaxben
Posts: 110
Joined: Thu Nov 16, 2017 6:04 pm

Re: ESP32-C6 GPIO0 issue

Postby dmaxben » Thu Oct 02, 2025 9:30 pm

Figured it out! I'm stupid...

Apparently if you do not manually set .bus_off_indicator to disabled (-1), it defaults to enabled, and defaults to GPIO0.

Once I set the bus_off_indicator output to -1, everything worked perfectly.

Code: Select all

    /* Node 1 config */
    twai_onchip_node_config_t cfg1 = {
        .io_cfg = {
            .tx = NODE1_TX_GPIO,
            .rx = NODE1_RX_GPIO,
            .quanta_clk_out = -1,    // Not used
            .bus_off_indicator = -1, // Not used
        },
        .bit_timing = {
            .bitrate = NODE1_BITRATE,
        },
        .tx_queue_depth = 5,
        .intr_priority = 1,
    };

    /* Node 2 config */
    twai_onchip_node_config_t cfg2 = {
        .io_cfg = {
            .tx = NODE2_TX_GPIO,
            .rx = NODE2_RX_GPIO,
            .quanta_clk_out = -1,    // Not used
            .bus_off_indicator = -1, // Not used
        },
        .bit_timing = {
            .bitrate = NODE2_BITRATE,
        },
        .tx_queue_depth = 5,
        .intr_priority = 1,
    };

Who is online

Users browsing this forum: Qwantbot, Semrush [Bot] and 2 guests