arduino / uno-r4-wifi-usb-bridge

26 stars 8 forks source link

How to use this with OpenOCD #6

Closed maxgerhardt closed 1 year ago

maxgerhardt commented 1 year ago

There's tons of "writing on the wall" that the ESP32-S3 on the Uno R4 WiFi board is loaded with a firmware that makes the device appear as 1. A USB CDC device for the serial bridge, 2. A CMSIS-DAP debugger device for flashing. And also somehow BOSSAC is in there.

https://github.com/bcmi-labs/uno-r4-wifi-usb-bridge/blob/5bb1f0620fb7375511b474399dd4365a42730fd8/UNOR4USBBridge/freedap.c#L83-L90

https://github.com/arduino/ArduinoCore-renesas/blob/main/variants/UNOWIFIR4/openocd.cfg even provides the OpenOCD configuration and the Arduino IDE downloads C:\Users\Max\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.11.0-arduino2 specifically for this core.

However, I have ZERO luck connecting OpenOCD to the board. In Zadig, I see both "TinyUSB" devices created by the board

grafik grafik

But OpenOCD just says

openocd.exe -f C:\Users\Max\Desktop\ren\framework-arduinorenesas\variants\UNOWIFIR4\openocd.cfg
Open On-Chip Debugger 0.11.0+dev-gab95bac57-dirty (2021-05-11-10:45)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
0x2341 0x1002
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
adapter speed: 1000 kHz

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: unable to find a matching CMSIS-DAP device

I also tried adding

set cmsis_dap_vid_pid "0x2341 0x1002"
set cmsis_dap_backend hid

in the config file with no avail. Verbose OpenOCD info just shows it trying to enumerate all devices but it can't find a CMSIS-DAP one.

Debug: 209 554 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x1022:0x145f: Operation not supported or unimplemented on this platform
Debug: 210 559 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2341:0x1002: Operation not supported or unimplemented on this platform
Debug: 211 563 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2109:0x0817: Operation not supported or unimplemented on this platform
Debug: 212 568 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x05a3:0x9331: Operation not supported or unimplemented on this platform
Debug: 213 573 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x05a3:0x9331: Operation not supported or unimplemented on this platform
Debug: 214 577 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2109:0x2813: Operation not supported or unimplemented on this platform
Debug: 215 582 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x062a:0x5918: Operation not supported or unimplemented on this platform
Debug: 216 602 cmsis_dap_usb_bulk.c:182 cmsis_dap_usb_open(): enumerating interfaces of 0x2109:0x8817
Debug: 217 606 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2109:0x2817: Operation not supported or unimplemented on this platform
Debug: 218 611 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x04a9:0x10d3: Operation not supported or unimplemented on this platform
Debug: 219 616 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x062a:0x5918: Entity not found
Debug: 220 619 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x046a:0xc122: Operation not supported or unimplemented on this platform
Debug: 221 637 cmsis_dap_usb_bulk.c:182 cmsis_dap_usb_open(): enumerating interfaces of 0x2109:0x8817
Debug: 222 641 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2341:0x1002: Entity not found
Debug: 223 646 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2109:0x0817: Operation not supported or unimplemented on this platform
Debug: 224 654 cmsis_dap_usb_bulk.c:182 cmsis_dap_usb_open(): enumerating interfaces of 0x046a:0xc122
Debug: 225 657 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x0a12:0x0001: Operation not supported or unimplemented on this platform
Debug: 226 661 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2109:0x2817: Operation not supported or unimplemented on this platform
Debug: 227 667 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x05a3:0x9331: Entity not found
Debug: 228 671 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x1022:0x43d5: Operation not supported or unimplemented on this platform
Debug: 229 675 cmsis_dap_usb_bulk.c:117 cmsis_dap_usb_open(): could not open device 0x2109:0x0813: Operation not supported or unimplemented on this platform
Error: 230 706 cmsis_dap.c:255 cmsis_dap_open(): unable to find a matching CMSIS-DAP device
maxgerhardt commented 1 year ago

Oooof!! I was so close, but my configuration commands were wrong. I had to add in the config file

source [find interface/cmsis-dap.cfg]
cmsis_dap_vid_pid 0x2341 0x1002
cmsis_dap_backend hid

which I can also probably do with -c switches. I was using the set command before. And now

openocd.exe  -f C:\Users\Max\Desktop\ren\framework-arduinorenesas\variants\UNOWIFIR4\openocd.cfg
Open On-Chip Debugger 0.11.0+dev-gab95bac57-dirty (2021-05-11-10:45)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
adapter speed: 1000 kHz

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Serial# = 123456789101112
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x5ba02477
Info : ra4m1.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for ra4m1.cpu on 3333
Info : Listening on port 3333 for gdb connections

Edit: Yeah, same result with

openocd.exe  -f C:\Users\Max\Desktop\ren\framework-arduinorenesas\variants\UNOWIFIR4\openocd.cfg  -c "cmsis_dap_vid_pid 0x2341 0x1002"

Cool 😎

maxgerhardt commented 1 year ago

With a few GDB quirks such as set mem inaccessible-by-default off and mem 0 0x40000 ro to make peripheral registers read out work and force hardware breakpoints (Software/Flash breakpoints won't work because OpenOCD has no flash driver for that Renesas chip? :( :() ,it does work nicely.

https://github.com/platformio/platformio-core/issues/4028#issuecomment-1622317146