ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?

arnaudmz
Posts: 3
Joined: Sat Feb 26, 2022 1:25 pm

ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?

Postby arnaudmz » Sat Feb 26, 2022 1:32 pm

Hi there.

I'd like to adapt the behaviour of my application depending on wether the native USB console is plugged or not.

Is there a software-based way to know this?
Do I have to use an extra GPIO plugged on the VUSB (with resistors to lower the voltage) ?

Regards,

Arnaud

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

Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?

Postby ESP_Sprite » Sun Feb 27, 2022 5:10 am

I'm not sure if we have software for that, but the hardware makes the latest SOF received available in a register. While USB is connected, that number should increase at exactly once every millisecond. You could use that.

arnaudmz
Posts: 3
Joined: Sat Feb 26, 2022 1:25 pm

Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?

Postby arnaudmz » Mon Feb 28, 2022 3:39 pm

@ESP_Sprite: sounds good enough, I can live with this.

Could you provide a link to some documentation where to look for this register and give it a go?

Arnaud

arnaudmz
Posts: 3
Joined: Sat Feb 26, 2022 1:25 pm

Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?

Postby arnaudmz » Mon Feb 28, 2022 3:57 pm

Found it in the meantime:

Code: Select all

USB_SERIAL_JTAG_FRAM_NUM_REG
does the trick very well.

Thanks.

dongrigorio
Posts: 3
Joined: Thu Jan 19, 2023 12:52 pm

Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?

Postby dongrigorio » Tue Jan 31, 2023 6:54 am

For esp32-c3 returns zero if usb is not connected, otherwise returns a positive integer (10).

Code: Select all

int is_plugged_usb(void){
    uint32_t *aa = USB_SERIAL_JTAG_FRAM_NUM_REG;
    uint32_t first = *aa;
    vTaskDelay(pdMS_TO_TICKS(10));
    return (int) (*aa - first);
}

Who is online

Users browsing this forum: ESP_Roland, Google [Bot] and 76 guests