Program and Debug the ESP32-C3

Setup programming and inbuilt JTAG debugging for an ESP32-C3 on Platformio.

  • This is a ‘your results may vary’ solution, due to unknown variation.

Connection

Check first that your ESP32-C3 is recognised when connected via USB (Linux).

user@machine:~$ lsusb
...
Bus 008 Device 033: ID 303a:1001 Espressif USB JTAG/serial debug unit
...

platformio.ini

Some build flags are required if you wish to enable serial output over USB, at the bitrate set by monitor_speed.

The on-chip CMSIS-DAP device handles uploading for debugging, JTAG debugging, and can also flash code for non-debugger uploads if required.

For non-debugger builds, we can choose to use the USB CDC Serial firmware upload tool, which affords us some extra project statistics.

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino

monitor_speed=115200

build_flags = 
  -D ARDUINO_USB_MODE=1          ; Enable USB hardware (if used).
  -D ARDUINO_USB_CDC_ON_BOOT=1   ; Enable CDC (Communications Device
                                 ; Class) functionality on boot, 
                                 ; enabling USB serial communication.

debug_tool = cmsis-dap           ; on-chip JTAG debug
; upload_protocol = esp-builtin    ; on-chip JTAG upload (less feedback)
upload_protocol = esptool        ; USB serial upload
debug_init_break = tbreak setup
debug_server =
  $PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/bin/openocd
  -f $PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/share/openocd/scripts/board/esp32c3-builtin.cfg
  

build and upload via USB serial

Remember that you can always enter program upload mode manually by RESETting the device with the BOOT switch depressed, in cases where previously programmed serial configuration prevents automatic CDC uploads.

monitor serial

build for debugging then flash by JTAG

Full rebuild and upload produces lengthy wait, then blue ‘working’ indicator stops and the debugger control pallet appears.

set breakpoint and debug via JTAG


If you’ve found this compilation useful, then your assistance in helping others find it will be both benevolent and appreciated.


Setup esp-prog for ESP-WROOM-32

Wire an Espressif esp-prog debugger to a ESP-WROOM-32 DEV KIT MODULE, and setup debugging on Platformio.

Prerequisites:

  • esp-prog debugger.
  • ESP-WROOM-32 DEV KIT MODULE (or ESP-WROOM-32 chip).
  • 6-12 Dupont leads, male to female.

esp-prog IDC to ESP-WROOM-32 and DEV KIT MODULE wiring

A typical setup involves using the esp-prog JTAG interface for uploading and debugging.

To monitor program output during runtime, you can either use the built-in FTDI serial of the esp-prog, or save on extra wiring by utilising the onboard FTDI serial of the ESP-WROOM-32 Dev Kit Module. Source selection is automated.

If you choose the latter option, you can safely connect the VDD 3V3 line of the esp-prog to the USB-powered Dev Kit Module, as the esp-prog includes reverse current protection circuitry.

esp-prog IDC pinouts

Add wiring tags to DuPont leads

Print this file esp-prog_wiring_flags.txt, cut out wiring tags, and Sellotape them to your DuPont leads.

platformio.ini file

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

; monitor either autoset serial 
monitor_speed = 115200
#monitor_port = /dev/ttyUSB2 ; uncomment & tune if autoset fails
monitor_filters = esp32_exception_decoder

; upload and debug via esp-prog JTAG
upload_protocol = esp-prog
debug_tool = esp-prog
debug_init_break = tbreak setup

lib_deps = 

build and upload via JTAG

monitor either serial

build for debug and JTAG upload

Full rebuild and upload produces lengthy wait, then blue ‘working’ indicator stops and the debugger control pallet appears.

set breakpoint and debug via JTAG

If you’ve found this compilation useful, then your assistance in helping others find it will be both benevolent and appreciated.