Skip to content

Instantly share code, notes, and snippets.

@rrbutani
Last active May 27, 2022 09:14
Show Gist options
  • Save rrbutani/32e3b9b8063a1fdbd5af0bf0f6400a2b to your computer and use it in GitHub Desktop.
Save rrbutani/32e3b9b8063a1fdbd5af0bf0f6400a2b to your computer and use it in GitHub Desktop.
esp debugging support

okay so i think im starting to get it

i think there was software magic stuff for debugging the esp8266 (comms over serial; uart handler/exception handlers on the device that parse gdb commands and stuff; on the host just points gdb at the serial device) (as per that readme, I think it predates espressif making their opencod fork that has xtensa support) that stub doesn't support the esp32 but there is an equivalent one in esp-idf proper; as the linked issue notes the stub approach in general has caveats for what you can actually do you in your debugger and anyways, it doesn't seem like anyone actually uses this anymore; all the guides and stuff seem to point you to the real hw based debugging

for hw based debugging it's the same as any other MCU (though the ESP32 and C3 only support JTAG, not SWD) as in you need a USB <-> JTAG bridge

the esp32-pico-D4 dev board we had actually did not have one on board (the CP2102 does not speak JTAG and isn't hooked up to all the JTAG pins – IO12-IO15 – anyways)

however other esp32 dev boards like the esp-wrover-kit use USB <-> UART chips like the FT232R that have bitbang modes that openocd and friends use to "implement" JTAG (as an aside it's super funny to me that we abuse the rate control pins for like, reset and stuff, and abuse the whole UART interface for other protocols too and that it feels like newer FTDI products have just become super general "here's an MCU with some GPIOs that you can fling bytes at over USB. oh and also, it has silicon for UART or w/e too")

the wrover specifically uses the FT2232HL which has two "channels" so the wrover can expose a UART device and a JTAG device to the host computer with 1 port (you do have to add some jumpers for this board though)

the esp32-c3 is even better; it has a built-in USB interface (IO18/IO19) so you don't need a USB<->UART bridge and it supports both USB-to-serial and USB-to-JTAG more details here

the devkitm-1 has an esp32-c3-mini1 (c3 w/flash + an antenna I think) which itself has an esp32-c3

the unfortunate bit is that (if I'm reading this right) devkitm-1 chose to include a CP2102N and connected it to the esp32-c3's UART interface instead of just using the built in USB interface I think this is because if you use the built-in USB interface you don't have a way to whack the reset pin/put it into download mode but it's unfortunate because you can do those things over JTAG

it seems like they left in unpopulated resistors on the micro USB port for you that let you swap the port over to use the built-in USB interface instead of the CP2102? R2 and R3 instead of R1 and R4 wish they'd included a jumper instead hard to be sure from this picture but I think they're the two that are left and up of the RST silkscreen text

or you can wire in another USB port (no electronics, just wires) to the built-in interface or connect a JTAG thing to the right pins (not sure if those are actually exposed on the C3/mini)

other misc things:

  • as per the book you can run your rust programs on bare metal or as a task on freertos/esp-idf (esp-idf-hal/esp-idf-svc)
  • espressif has openocd and gdb forks
    • for the esp32/8266 the big thing is xtensa support
    • other than that I think the changes are mostly just freertos support but I haven't looked at the source
    • it really does seem like there shouldn't be anything required for the esp32-c3 since it's risc-v; notably there is no overlay for it
    • I think if you're running bare metal rust you should just be able to use upstream opencod and risc-v gdb or lldb without losing anything?
  • espressif has a DAP server of their own that uses openocd; not sure what this buys you over DAP -> gdb -> openocd (or probe-rs')
  • there's probe-rs support for the esp32-c3 in upstream probe-rs, and debug support is kind of there too, not just flashing (probe-rs is what all the knurling-rs things like defmt and defmt-test are built on)
  • i forgot that the esp32 has an ethernet MAC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment