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

rozzie
Posts: 12
Joined: Sat Sep 05, 2020 4:57 pm

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

Postby rozzie » Thu Dec 15, 2022 6:19 pm

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.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » Fri Dec 16, 2022 12:05 am

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.

rozzie
Posts: 12
Joined: Sat Sep 05, 2020 4:57 pm

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

Postby rozzie » Fri Dec 16, 2022 12:31 am

perfect. Once again, thank you @ESP_igrr !

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

Who is online

Users browsing this forum: Baidu [Spider], twompark and 100 guests