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

jmadsenee
Posts: 30
Joined: Tue Apr 19, 2022 1:16 am

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

Postby jmadsenee » Wed Dec 28, 2022 3:31 pm

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!

jmadsenee
Posts: 30
Joined: Tue Apr 19, 2022 1:16 am

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

Postby jmadsenee » Sun Jan 29, 2023 3:46 pm

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();
...
}

MicroController
Posts: 1136
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Mon Mar 27, 2023 8:44 am

Trying to solve a similiar problem, I found

Code: Select all

bool usb_serial_jtag_is_connected(void);
in driver/usb_serial_jtag

Who is online

Users browsing this forum: Pedro Hugo PSC, zelenecul and 109 guests