Page 1 of 1

Detect if USB serial/JTAG port is connected to host computer

Posted: Wed Dec 28, 2022 3:31 pm
by jmadsenee
I need to detect whether my ESP32-S3 is connected to a host computer running a terminal program before I start a console on the ESP32. When the ESP32 resets, it may not be connected to anything, it may be connected to a USB cable for charging or there may be a host computer that wants to talk to it. If I just start the console it blocks until a terminal is connected (no good!). I saw on github that @chipweinberger was looking to do something similar, but I don't see that it was resolved.

Does anyone have an idea of a simple way to check if a host computer is connected?

Thanks so much for any help!

Re: Detect if USB serial/JTAG port is connected to host computer

Posted: Sun Jan 29, 2023 3:46 pm
by jmadsenee
For posterity: While I didn't figure out how to detect if the USB serial/JTAG was hooked to a computer running a terminal program such as Tera Term, I found a work around. Basically, I just started the console initialization in a task, so it didn't matter if it blocked. Everything else runs just fine, and if a terminal is connected, it initializes the console and terminates the task. Instead of calling consoleInit() I call consoleRunInit().

Code: Select all

static wl_handle_t 			wl_handle;

// runs when USB plugged in (charger or terminal)
void consoleInitTask(void *pvParameter)
{
	consoleInit();
	vTaskDelete(xHandle);
}



void consoleRunInit(void)
{
	xTaskCreate(&consoleInitTask, "console_init_task", 4096, NULL, 4, &xHandle);
}



void consoleInit(void)
{
    esp_console_repl_t *Repl = NULL;
    esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
...
}

Re: Detect if USB serial/JTAG port is connected to host computer

Posted: Mon Mar 27, 2023 8:44 am
by MicroController
Trying to solve a similiar problem, I found

Code: Select all

bool usb_serial_jtag_is_connected(void);
in driver/usb_serial_jtag