Page 1 of 1

Programmatic ESP32-S3 detection of JTAG debug session in-progress?

Posted: Thu Dec 15, 2022 6:19 pm
by rozzie
Now that I've got ESP32-S3 usb support implemented (thank you @ESP_igrr !), I've found that I have a minor challenge doing my debugging work using the wonderful JTAG-over-USB feature of the S3.

Specifically, I've found that if I start openocd+gdb to debug over the usb-hosted JTAG, the tinyusb usb initialization code renders the JTAG debugging functionality nonfunctional.

This makes sense, of course And I can prevent the issue by recompiling my app without initializing my USB code.

However, what I would truly like to do is to make it automatic. That is, if I'm debugging, I'd like my code simply not to enable its USB support.

As I'd mentioned previously, this is code that I'm porting from ARM. In my ARM implementation, I have this method which has proven to be super-useful in a variety of situations. For example, I have a "softPanic" method that only panics when I'm debugging.

Code: Select all

bool currentlyDebugging()
{
    return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) != 0;
}
Might there possibly a way, on the ESP32-S3, that in my app_main() I can sense to see if I'm currently connected into the JTAG-over-USB using openocd/gdb, so that I can implement a similar kind of method?

If not, I understand, but thanks for your creative thinking.

Re: Programmatic ESP32-S3 detection of JTAG debug session in-progress?

Posted: Fri Dec 16, 2022 12:05 am
by ESP_igrr
There is a function which checks this:

esp_cpu_dbgr_is_attached() (in v5.0 and later)
cpu_hal_is_debugger_attached() (in v4.x)

The exact behavior is architecture specific, but basically it should return 'true' is OpenOCD has connected to the CPU debug module over JTAG.

Re: Programmatic ESP32-S3 detection of JTAG debug session in-progress?

Posted: Fri Dec 16, 2022 12:31 am
by rozzie
perfect. Once again, thank you @ESP_igrr !

My port is going well and I appreciate your responsiveness that is keeping me unblocked.