espressif / openocd-esp32

OpenOCD branch with ESP32 JTAG support
Other
350 stars 128 forks source link

Launch problem with "Error: esp_usb_jtag: could not find or open device!" ESP32-C3 via USB/IP (Windows -> VM) (OCD-880) #311

Closed lure23 closed 6 months ago

lure23 commented 8 months ago

Development Kit

ESP32-C3-DevKitC-02

Module or chip used

ESP32-C3-WROOM-02

Debug Adapter

built-in

OpenOCD version

v0.12.0-esp32-20230921

Operating System

Windows + Ubuntu Linux

Using an IDE ?

no

OpenOCD command line

openocd -f board/esp32c3-builtin.cfg

JTAG Clock Speed

don't know - please advice

ESP-IDF version

5.3.0

Problem Description

My situation is a bit ... different.

I'm running ESP32 development on a Multipass VM (Ubuntu Linux), under macOS, and primarily (=only) interested in setting up a nice, embedded Rust development environment.

Access to the development board is via USB/IP, because ... Multipass doesn't allow normal USB pass-throughs.

This works. :)

What doesn't work is OpenOCD. I would like eventually to be able to develop using Rust Rover (from JetBrains), but I know they currently don't support OpenOCD in that product. Yet, I have hopes. So wanted to see how far I can get.

Where am I now?

"Everything" works; I can do Rust development on the VM, and flash my code (over USB/IP) to the device.

I installed OpenOCD via the Linux guidance - all the steps are visible in the repo below - and it seems healthy. When reaching for the device, it gives:

$ openocd -f board/esp32c3-builtin.cfg
Open On-Chip Debugger v0.12.0-esp32-20230921 (2023-09-21-13:41)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselecting 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: esp_usb_jtag: could not find or open device!
/home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/target/esp_common.cfg:9: Error: 
at file "/home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 9

That doesn't tell much. Since the documentation here mentions:

image

..I thought that might be it, and installed such a driver on the Windows 10 that deals with the device.

I disconnected the device; no change.

Decided to take the other (PowerShell) approach of installing as well:

image

Does the "Exit code: 0x2a" mean it failed? I did grant it elevated rights when asked.

So...

The internal ticket for this in my repo is https://github.com/lure23/EmbeddedRover/issues/5 - it has some more details.

Debug Logs

Below is `openocd_log.txt`. I am not using GDB and the command on the suggested "item 3 here" link only mentions Xtensa, so I don't provide a gdb log (I'm on Risc V). Let me know if I can provide more info.

---

User : 3 2 options.c:52 configuration_output_handler(): debug_level: 3User : 4 2 options.c:52 configuration_output_handler(): 
Debug: 5 2 options.c:233 add_default_dirs(): bindir=/builds/idf/openocd-esp32/_build/../openocd-esp32/bin
Debug: 6 2 options.c:234 add_default_dirs(): pkgdatadir=/builds/idf/openocd-esp32/_build/../openocd-esp32/share/openocd
Debug: 7 2 options.c:235 add_default_dirs(): exepath=/home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/bin
Debug: 8 2 options.c:236 add_default_dirs(): bin2data=../share/openocd
Debug: 9 2 configuration.c:33 add_script_search_dir(): adding /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts
Debug: 10 2 configuration.c:33 add_script_search_dir(): adding /home/ubuntu/.config/openocd
Debug: 11 2 configuration.c:33 add_script_search_dir(): adding /home/ubuntu/.openocd
Debug: 12 2 configuration.c:33 add_script_search_dir(): adding /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/bin/../share/openocd/site
Debug: 13 2 configuration.c:33 add_script_search_dir(): adding /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/bin/../share/openocd/scripts
Debug: 14 2 command.c:151 script_debug(): command - ocd_find board/esp32c3-builtin.cfg
Debug: 15 2 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/board/esp32c3-builtin.cfg
Debug: 16 3 command.c:151 script_debug(): command - ocd_find interface/esp_usb_jtag.cfg
Debug: 17 3 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/interface/esp_usb_jtag.cfg
Debug: 18 3 command.c:151 script_debug(): command - adapter driver esp_usb_jtag
Info : 19 3 transport.c:106 allow_transports(): only one transport option; autoselecting 'jtag'
Debug: 20 3 command.c:151 script_debug(): command - espusbjtag vid_pid 0x303a 0x1001
Info : 21 3 esp_usb_jtag.c:901 esp_usb_jtag_vid_pid(): esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Debug: 22 3 command.c:151 script_debug(): command - espusbjtag caps_descriptor 0x2000
Info : 23 3 esp_usb_jtag.c:912 esp_usb_jtag_caps_descriptor(): esp_usb_jtag: capabilities descriptor set to 0x2000
Debug: 24 3 command.c:151 script_debug(): command - adapter speed 40000
Debug: 25 3 adapter.c:249 adapter_config_khz(): handle adapter khz
Debug: 26 3 adapter.c:213 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 27 3 adapter.c:213 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 28 3 command.c:151 script_debug(): command - ocd_find target/esp32c3.cfg
Debug: 29 3 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/target/esp32c3.cfg
Debug: 30 3 command.c:151 script_debug(): command - ocd_find target/esp_common.cfg
Debug: 31 4 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/target/esp_common.cfg
Debug: 32 5 command.c:151 script_debug(): command - ocd_find bitsbytes.tcl
Debug: 33 5 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/bitsbytes.tcl
Debug: 34 5 command.c:151 script_debug(): command - ocd_find memory.tcl
Debug: 35 5 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/memory.tcl
Debug: 36 5 command.c:151 script_debug(): command - ocd_find mmr_helpers.tcl
Debug: 37 5 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/mmr_helpers.tcl
Debug: 38 5 command.c:151 script_debug(): command - ocd_find target/esp_version.cfg
Debug: 39 5 configuration.c:88 find_file(): found /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/target/esp_version.cfg
Debug: 40 5 command.c:151 script_debug(): command - version
Debug: 41 6 command.c:151 script_debug(): command - add_help_text program_esp write an image to flash, address is only required for binary images. verify, reset, exit, compress, restore_clock and encrypt are optional
Debug: 42 6 command.c:151 script_debug(): command - add_usage_text program_esp <filename> [address] [verify] [reset] [exit] [compress] [no_clock_boost] [restore_clock] [encrypt]
Debug: 43 6 command.c:151 script_debug(): command - add_help_text program_esp_bins write all the images at address specified in flasher_args.json generated while building idf project
Debug: 44 6 command.c:151 script_debug(): command - add_usage_text program_esp_bins <build_dir> flasher_args.json [verify] [reset] [exit] [compress] [no_clock_boost] [restore_clock]
Debug: 45 6 command.c:151 script_debug(): command - add_help_text esp_get_mac Print MAC address of the chip. Use a `format` argument to return formatted MAC value
Debug: 46 6 command.c:151 script_debug(): command - add_usage_text esp_get_mac [format]
Debug: 47 6 command.c:151 script_debug(): command - jtag newtap esp32c3 cpu -irlen 5 -expected-id 0x00005c25
Debug: 48 6 tcl.c:419 handle_jtag_newtap_args(): Creating New Tap, Chip: esp32c3, Tap: cpu, Dotted: esp32c3.cpu, 4 params
Debug: 49 6 core.c:1476 jtag_tap_init(): Created Tap: esp32c3.cpu @ abs position 0, irlen 5, capture: 0x1 mask: 0x3
Debug: 50 6 command.c:151 script_debug(): command - target create esp32c3 esp32c3 -chain-position esp32c3.cpu -coreid 0 -rtos FreeRTOS
Debug: 51 6 target.c:2166 target_free_all_working_areas_restore(): freeing all working areas
Debug: 52 6 FreeRTOS.c:1414 freertos_create(): freertos_create
Debug: 53 6 command.c:285 register_command(): command 'esp' is already registered
Debug: 54 6 command.c:285 register_command(): command 'esp32c3 esp' is already registered
Debug: 55 6 command.c:151 script_debug(): command - esp32c3 configure -work-area-phys 0x3FC80000 -work-area-virt 0x3FC80000 -work-area-size 0x24000 -work-area-backup 1
Debug: 56 6 target.c:2166 target_free_all_working_areas_restore(): freeing all working areas
Debug: 57 6 target.c:2166 target_free_all_working_areas_restore(): freeing all working areas
Debug: 58 6 target.c:2166 target_free_all_working_areas_restore(): freeing all working areas
Debug: 59 6 target.c:2166 target_free_all_working_areas_restore(): freeing all working areas
Debug: 60 6 command.c:151 script_debug(): command - flash bank esp32c3.flash esp32c3 0x0 0 0 0 esp32c3
Debug: 61 6 command.c:285 register_command(): command 'esp' is already registered
Debug: 62 6 tcl.c:1307 handle_flash_bank_command(): 'esp32c3' driver usage field missing
Debug: 63 6 command.c:151 script_debug(): command - flash bank esp32c3.irom esp32c3 0x0 0 0 0 esp32c3
Debug: 64 6 command.c:285 register_command(): command 'esp' is already registered
Debug: 65 6 command.c:285 register_command(): command 'esp appimage_offset' is already registered
Debug: 66 6 command.c:285 register_command(): command 'esp compression' is already registered
Debug: 67 6 command.c:285 register_command(): command 'esp verify_bank_hash' is already registered
Debug: 68 6 command.c:285 register_command(): command 'esp flash_stub_clock_boost' is already registered
Debug: 69 6 command.c:285 register_command(): command 'esp encrypt_binary' is already registered
Debug: 70 6 command.c:285 register_command(): command 'esp stub_log' is already registered
Debug: 71 6 tcl.c:1307 handle_flash_bank_command(): 'esp32c3' driver usage field missing
Debug: 72 6 command.c:151 script_debug(): command - flash bank esp32c3.drom esp32c3 0x0 0 0 0 esp32c3
Debug: 73 6 command.c:285 register_command(): command 'esp' is already registered
Debug: 74 6 command.c:285 register_command(): command 'esp appimage_offset' is already registered
Debug: 75 6 command.c:285 register_command(): command 'esp compression' is already registered
Debug: 76 6 command.c:285 register_command(): command 'esp verify_bank_hash' is already registered
Debug: 77 6 command.c:285 register_command(): command 'esp flash_stub_clock_boost' is already registered
Debug: 78 6 command.c:285 register_command(): command 'esp encrypt_binary' is already registered
Debug: 79 6 command.c:285 register_command(): command 'esp stub_log' is already registered
Debug: 80 6 tcl.c:1307 handle_flash_bank_command(): 'esp32c3' driver usage field missing
Debug: 81 6 command.c:151 script_debug(): command - esp32c3 configure -event halted 
        global _ESP_WDT_DISABLE
        $_ESP_WDT_DISABLE
        esp halted_event_handler

Debug: 82 6 command.c:151 script_debug(): command - esp32c3 configure -event examine-end 
        # Need to enable to set 'semihosting_basedir'
        arm semihosting enable
        arm semihosting_resexit enable
        if { [info exists _SEMIHOST_BASEDIR] } {
            if { $_SEMIHOST_BASEDIR != "" } {
                arm semihosting_basedir $_SEMIHOST_BASEDIR
            }
        }

Debug: 83 6 command.c:151 script_debug(): command - esp32c3 configure -event reset-assert-post 
        global _ESP_SOC_RESET
        $_ESP_SOC_RESET

Debug: 84 6 command.c:151 script_debug(): command - esp32c3 configure -event gdb-attach 
        if { $_ESP_SMP_BREAK != 0 } {
            $_TARGETNAME_0 xtensa smpbreak BreakIn BreakOut
        }
        # necessary to auto-probe flash bank when GDB is connected and generate proper memory map
        halt 1000
        if { [$_ESP_MEMPROT_IS_ENABLED] } {
            # 'reset halt' to disable memory protection and allow flasher to work correctly
            echo "Memory protection is enabled. Reset target to disable it..."
            reset halt
        }

        if { $_ESP_ARCH == "riscv" } {
            # by default mask interrupts while stepping
            riscv set_maskisr steponly
        }

Debug: 85 6 command.c:151 script_debug(): command - esp32c3 configure -event gdb-detach 
        $_TARGETNAME_0 esp gdb_detach_handler

Debug: 86 6 command.c:151 script_debug(): command - riscv set_reset_timeout_sec 2
Debug: 87 6 command.c:151 script_debug(): command - riscv set_command_timeout_sec 5
Debug: 88 6 command.c:151 script_debug(): command - riscv set_mem_access sysbus progbuf abstract
Debug: 89 6 command.c:151 script_debug(): command - riscv set_ebreakm on
Debug: 90 7 command.c:151 script_debug(): command - riscv set_ebreaks on
Debug: 91 7 command.c:151 script_debug(): command - riscv set_ebreaku on
Debug: 92 7 command.c:151 script_debug(): command - esp32c3 riscv expose_csrs 2016=mpcer
Debug: 93 7 command.c:151 script_debug(): command - esp32c3 riscv expose_csrs 2017=mpcmr
Debug: 94 7 command.c:151 script_debug(): command - esp32c3 riscv expose_csrs 2018=mpccr
Debug: 95 7 command.c:151 script_debug(): command - esp32c3 riscv expose_csrs 2051=cpu_gpio_oen
Debug: 96 7 command.c:151 script_debug(): command - esp32c3 riscv expose_csrs 2052=cpu_gpio_in
Debug: 97 7 command.c:151 script_debug(): command - esp32c3 riscv expose_csrs 2053=cpu_gpio_out
Info : 98 7 server.c:298 add_service(): Listening on port 6666 for tcl connections
Info : 99 7 server.c:298 add_service(): Listening on port 4444 for telnet connections
Debug: 100 7 command.c:151 script_debug(): command - init
Debug: 101 7 command.c:151 script_debug(): command - target init
Debug: 102 7 command.c:151 script_debug(): command - target names
Debug: 103 7 command.c:151 script_debug(): command - esp32c3 cget -event gdb-flash-erase-start
Debug: 104 7 command.c:151 script_debug(): command - esp32c3 configure -event gdb-flash-erase-start reset init
Debug: 105 7 command.c:151 script_debug(): command - esp32c3 cget -event gdb-flash-write-end
Debug: 106 7 command.c:151 script_debug(): command - esp32c3 configure -event gdb-flash-write-end reset halt
Debug: 107 7 command.c:151 script_debug(): command - esp32c3 cget -event gdb-attach
Debug: 108 7 target.c:1624 handle_target_init_command(): Initializing targets...
Debug: 109 7 riscv.c:413 riscv_init_target(): [esp32c3] riscv_init_target()
Debug: 110 7 semihosting_common.c:105 semihosting_common_init():  
Error: 111 9 esp_usb_jtag.c:646 esp_usb_jtag_init(): esp_usb_jtag: could not find or open device!
Debug: 112 9 command.c:541 run_command(): Command 'init' failed with error code -4
User : 113 9 command.c:612 command_run_line(): /home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/target/esp_common.cfg:9: Error: 
at file "/home/ubuntu/.espressif/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 9
Debug: 114 9 riscv.c:463 riscv_deinit_target(): [esp32c3] riscv_deinit_target()
Debug: 115 9 target.c:2166 target_free_all_working_areas_restore(): freeing all working areas

Expected behavior

OpenOCD will be able to connect with the device, via built-in JTAG/USB.

Screenshots

No response

lure23 commented 8 months ago

How OpenOCD is installed: https://github.com/lure23/EmbeddedRover/blob/main/mp-prime/manual/openocd.sh

The device is revision 0.4 - thus should have the built-in USB/JTAG.

I tried on two devices: one where a Rust-made code is running; another straight from the packaging. Both act the same.

erhankur commented 8 months ago

@lure23 What do you see on the client side when you try to attach a USB device? I gave it a try and saw the below error on my macOS host.

[2024-01-13T14:20:14Z WARN  usbip::device] unknown desc type: SetupPacket { request_type: 80, request: 6, value: 2000, index: 0, length: ff }

I think this definitely can be solved on the rust side.

Another workaround solution is to skip requesting device descriptors from the esp32c3 and fill the parameters manually on the OpenOCD side. This will require building from the source.

https://github.com/espressif/openocd-esp32/blob/master/src/jtag/drivers/esp_usb_jtag.c#L677

This is an interesting setup. Let me know if you need help while building the OpenOCD.

lure23 commented 8 months ago

This is an interesting setup. Let me know if you need help while building the OpenOCD.

Thanks!

I'll try to get the connection working on macOS, natively. If that succeeds, I have added confidence and knowledge of the state of JTAG-over-USB. In reality though, it looks like probe-rs might be a better alternative for my needs since it's Rust native and doesn't need the gdb layer.

Steps today:

  1. Tried OpenOCD-ESP release 0.12, but it doesn't have boards/esp32-jtag-builtin.cfg.

  2. Cloned the master.

Prepared dependencies (with HomeBrew).

! Do I need the optional hidapi and/or libftdi for the C3 JTAG-over-USB?

$ ./bootstrap
[...]

$ ./configure
[...]
OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices        yes (auto)
ST-Link Programmer                      yes (auto)
TI ICDI JTAG Programmer                 yes (auto)
Keil ULINK JTAG Programmer              yes (auto)
ANGIE Adapter                           yes (auto)
Altera USB-Blaster II Compatible        yes (auto)
Bitbang mode of FT232R based devices    yes (auto)
Versaloon-Link JTAG Programmer          yes (auto)
TI XDS110 Debug Probe                   yes (auto)
CMSIS-DAP v2 Compliant Debugger         yes (auto)
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Olimex ARM-JTAG-EW Programmer           yes (auto)
Raisonance RLink JTAG Programmer        yes (auto)
USBProg JTAG Programmer                 yes (auto)
Espressif JTAG Programmer               yes (auto)
CMSIS-DAP Compliant Debugger            no
Nu-Link Programmer                      no
Cypress KitProg Programmer              no
Altera USB-Blaster Compatible           no
ASIX Presto Adapter                     no
OpenJTAG Adapter                        no
Linux GPIO bitbang through libgpiod     no
SEGGER J-Link Programmer                no
Bus Pirate                              yes (auto)
Use Capstone disassembly framework      no

Observation: Expected to see "JTAG-over-USB"-something, but (looking at the source) "Espressif JTAG Programmer" seems to be it?

(installed locally)

With the ESP32-C3-DevKitC-02 connected:

$ openocd -f /usr/local/share/openocd/scripts/board/esp32c3-builtin.cfg 
Open On-Chip Debugger v0.12.0-36eab91e (2024-01-14-12:09)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselecting 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: esp_usb_jtag: could not find or open device!
/usr/local/bin/../share/openocd/scripts/target/esp_common.cfg:9: Error: 
at file "/usr/local/bin/../share/openocd/scripts/target/esp_common.cfg", line 9
Error: [esp32c3] Unsupported DTM version: -1
Error: [esp32c3] Could not identify target type.

This is expected.

Looking at System Profiler, the device is (only) seen as:

$ system_profiler SPUSBDataType
2024-01-14 11:11:06.791 system_profiler[13252:392083] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be
2024-01-14 11:11:06.792 system_profiler[13252:392083] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be
USB:
[...]
        CP2102N USB to UART Bridge Controller:

          Product ID: 0xea60
          Vendor ID: 0x10c4  (Silicon Laboratories, Inc.)
          Version: 1.00
          Serial Number: bc2f214f809ded11aafa5f84e259fb3e
          Speed: Up to 12 Mb/s
          Manufacturer: Silicon Labs
          Location ID: 0x14600000 / 15
          Current Available (mA): 500
          Current Required (mA): 100
          Extra Operating Current (mA): 0
[...]

! Should I set it to bootloader mode, somehow? Would that change the VID:PID?

Reading README.macOS:

erhankur commented 8 months ago

It should be fine as long as you see this in the config summary.

Espressif JTAG Programmer               yes (auto)

esp_usb_jtag is dependent on libusb and looks like it is installed.

The board config file is board/esp32c3-builtin.cfg

Unfortunately, I have no idea why your macOS couldn't enumerate the Jtag device. I don't remember if I installed something special on my mac. You should see something like this;

system_profiler SPUSBDataType

USB:
...
        USB JTAG/serial debug unit:

          Product ID: 0x1001
          Vendor ID: 0x303a
          Version: 1.01
          Serial Number: 7C:DF:A1:A2:8F:38
          Speed: Up to 12 Mb/s
          Manufacturer: Espressif
          Location ID: 0x14400000 / 1
          Current Available (mA): 500
          Current Required (mA): 500
          Extra Operating Current (mA): 0
erhankur commented 6 months ago

@lure23 I don't see an issue related to OpenOCD here. Feel free to re-open if you need something from our side.