← index #16511PR #7715
Related · high · value 1.581
QUERY · ISSUE

esp32s3/c3 hardware JTAG control to external pins

openby emardopened 2025-01-01updated 2025-03-30
enhancementport-esp32

Description

Allows routing of ESP32C3 and ESP32S3 internal hardware usb-jtag
to external gpio pins making ESP32S3/C3 cheap and fast JTAG for
programming other devices.

Once enabled this ESP32 hardware services JTAG by itself
so no other software interrupts or any server running
is needed.

Code Size

12 lines of code to enable, 6 lines to disable here is arduino example

#if CONFIG_IDF_TARGET_ESP32S3
#define OMATRIX_TCK 85
#define OMATRIX_TMS 86
#define OMATRIX_TDI 87
#define OMATRIX_SRST 251
#define IMATRIX_TDO 251
#endif

#if CONFIG_IDF_TARGET_ESP32C3
#define OMATRIX_TCK 36
#define OMATRIX_TMS 37
#define OMATRIX_TDI 38
#define OMATRIX_SRST 127
#define IMATRIX_TDO 39
#endif

void route_usb_jtag_to_gpio()
{
digitalWrite(LED_BUILTIN, LED_ON);
pinMode(PIN_TCK, OUTPUT);
pinMode(PIN_TMS, OUTPUT);
pinMode(PIN_TDI, OUTPUT);
pinMode(PIN_TDO, INPUT);
pinMode(PIN_SRST, OUTPUT);
WRITE_PERI_REG(USB_SERIAL_JTAG_CONF0_REG,
READ_PERI_REG(USB_SERIAL_JTAG_CONF0_REG)
| USB_SERIAL_JTAG_USB_JTAG_BRIDGE_EN);
// esp_rom_gpio_connect_out_signal(GPIO, IOMATRIX, false, false);
esp_rom_gpio_connect_out_signal(PIN_TCK, OMATRIX_TCK, false, false);
esp_rom_gpio_connect_out_signal(PIN_TMS, OMATRIX_TMS, false, false);
esp_rom_gpio_connect_out_signal(PIN_TDI, OMATRIX_TDI, false, false);
esp_rom_gpio_connect_out_signal(PIN_SRST, OMATRIX_SRST, false, false);
esp_rom_gpio_connect_in_signal (PIN_TDO, IMATRIX_TDO, false);
}

void unroute_usb_jtag_to_gpio()
{
WRITE_PERI_REG(USB_SERIAL_JTAG_CONF0_REG,
READ_PERI_REG(USB_SERIAL_JTAG_CONF0_REG)
& ~USB_SERIAL_JTAG_USB_JTAG_BRIDGE_EN);
pinMode(PIN_TCK, INPUT);
pinMode(PIN_TMS, INPUT);
pinMode(PIN_TDI, INPUT);
pinMode(PIN_TDO, INPUT);
pinMode(PIN_SRST, INPUT);
digitalWrite(LED_BUILTIN, LED_OFF);
}

Implementation

I hope the MicroPython maintainers or community will implement this feature

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

esp32/boards: Add GENERIC_C3_USB.

closedby xorbitopened 2021-08-26updated 2021-08-30
port-esp32

Add a new board type for ESP32-C3 revision 3 and up that implements the USB serial/JTAG port on pin 18 and 19. This variant uses the USB serial for programming and console, leaving the UART free.

  • Pins 18 and 19 are correctly reserved for this variant. I also added pins 14-17 as reserved for flash for any ESP32-C3 so they can't be reconfigured anymore to crash the system.
  • Added usb_serial_jtag.c and .h to implement this interface.
  • Interface was tested to work correctly together with webrepl.
  • Interface was tested to work correctly when sending and receiving large files with ampy.
  • Disconnecting terminal or USB will not hang the system when it's trying to print.
  • Control+C is working correctly.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied