Page 1 of 1
ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
Posted: Sat Feb 26, 2022 1:32 pm
by arnaudmz
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
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
Posted: Sun Feb 27, 2022 5:10 am
by ESP_Sprite
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.
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
Posted: Mon Feb 28, 2022 3:39 pm
by arnaudmz
@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
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
Posted: Mon Feb 28, 2022 3:57 pm
by arnaudmz
Found it in the meantime:
does the trick very well.
Thanks.
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
Posted: Tue Jan 31, 2023 6:54 am
by dongrigorio
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);
}
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
Posted: Wed Jul 10, 2024 8:58 am
by kscheff
With framework 5.2.1
Code: Select all
*(uint_32_t*)USB_SERIAL_JTAG_FRAM_NUM_REG
returns a 12-bit counter, counting down.
In my observation the counter runs in average with ~36.5ms.
When no USB was connect it shows 0, it stops counting down when USB is unplugged.
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
Posted: Wed Oct 16, 2024 10:42 am
by mano1979
dongrigorio wrote: ↑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);
}
How to use this? I am trying to implement it in my arduino sketch, but i get errors.
Code: Select all
'USB_SERIAL_JTAG_FRAM_NUM_REG ' was not declared in this scope.
Where should it be placed?