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
ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
-
- Posts: 9764
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
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?
@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
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?
Found it in the meantime: does the trick very well.
Thanks.
Code: Select all
USB_SERIAL_JTAG_FRAM_NUM_REG
Thanks.
-
- Posts: 3
- Joined: Thu Jan 19, 2023 12:52 pm
Re: ESP32-C3 How to know if USB console (GPIO18, GPIO19) is plugged in?
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?
With framework 5.2.1 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.
Code: Select all
*(uint_32_t*)USB_SERIAL_JTAG_FRAM_NUM_REG
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?
How to use this? I am trying to implement it in my arduino sketch, but i get errors.dongrigorio wrote: ↑Tue Jan 31, 2023 6:54 amFor 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); }
Code: Select all
'USB_SERIAL_JTAG_FRAM_NUM_REG ' was not declared in this scope.
Who is online
Users browsing this forum: Baidu [Spider], brushlow18 and 118 guests