Nordic nRF52840 debugging with ESP-Prog?

Hello team Platformio,
I have a Seeed Studio XIAO nRF52840 connected to the expansion board and would like to use esp-prog debugger on Platformio.

|Xiao     |Esp-prog    |
|---------|------------|
|SWCLK    |ESP_TCK     |
|SWDIO    |ESP_TMS     |
|GND      |  GND       |
|VCC(3.3V)|  VCC       |

So far, I have connected the xiao to the esp-prog. However, I want to know if using the esp-prog on a nordic board is possible, or do I need to get another debugger for Xaio board? Thanks.

The ESP-Prog is just a FTDI FT2232HL board. OpenOCD can handle both that FTDI chip and the nRF52 series of chips (as target/nrf52.cfg.

As you can see here, when you tell PlatformIO in the espressif32 platform to use debug_tool = esp-prog, it just uses ftdi/esp32_devkitj_v1.cfg as an interface.

So, what I recommend you try as an experiment:

  1. Like this article shows, make sure to use Zadig to load “WinUSB” drivers for the “Dual RS232-HS (Interface 0)” interface of the plugged-in esp-prog
  2. Make sure the PlatformIO package for OpenOCD is installed (CLI → pio pkg install -g -t tool-openocd)
  3. Go to the PlatformIO OpenOCD installation folder (Windows: C:\Users\<user>\.platformio\packages\tool-openocd)
  4. Copy the esp32_devkitj_v1.cfg file into the scripts\interface\ftdi folder
  5. Open a terminal (Windwos+R → cmd.exe)
  6. Change-directory into the OpenOCD folder by cd C:\Users\<user>\.platformio\packages\tool-openocd)
  7. Execute and post the output of
bin\openocd.exe -s scripts -f interface/ftdi/esp32_devkitj_v1.cfg -c "transport select swd" -f target/nrf52.cfg
1 Like

Hello @maxgerhardt,
Thanks for the swift respond. I have followed the above steps, here’s is the output:

C:\Users\gigwe\.platformio\packages\tool-openocd>bin\openocd.exe -s scripts -f interface/ftdi/esp32_devkitj_v1.cfg -c "transport select swd" -f target/nrf52.cfg
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 20000 kHz

Info : FTDI SWD mode enabled
swd
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: SWD mode is active but SWD_EN signal is not defined

C:\Users\gigwe\.platformio\packages\tool-openocd>

I also updated my platformio.ini file with the following settings:

[env:xiaoble]
platform = nordicnrf52
board = xiaoble
framework = arduino
debug_tool = esp-prog
debug_init_break = tbreak setup

I got this error:



 *  Executing task in folder blinker: C:\Users\gigwe\.platformio\penv\Scripts\platformio.exe run --target upload 

Processing xiaoble (platform: nordicnrf52; board: xiaoble; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
DebugInvalidOptionsError: Unknown debug tool `esp-prog`. Please use one of `blackmagic, cmsis-dap, jlink` or `custom`:
  File "C:\Users\gigwe\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 187:
    env.SConscript("$BUILD_SCRIPT")
  File "C:\Users\gigwe\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py", line 597:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\gigwe\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Script\SConscript.py", line 285:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "C:\Users\gigwe\.platformio\platforms\nordicnrf52\builder\main.py", line 195:
    target_elf = env.BuildProgram()
  File "C:\Users\gigwe\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py", line 737:
    return self.method(*nargs, **kwargs)
  File "C:\Users\gigwe\.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py", line 60:
    env.ProcessProgramDeps()
  File "C:\Users\gigwe\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py", line 737:
    return self.method(*nargs, **kwargs)
  File "C:\Users\gigwe\.platformio\penv\lib\site-packages\platformio\builder\tools\piobuild.py", line 110:
    env.PrintConfiguration()
  File "C:\Users\gigwe\.platformio\packages\tool-scons\scons-local-4.4.0\SCons\Util.py", line 737:
    return self.method(*nargs, **kwargs)
  File "C:\Users\gigwe\.platformio\penv\lib\site-packages\platformio\builder\tools\pioplatform.py", line 233:
    _get_debug_data(),
  File "C:\Users\gigwe\.platformio\penv\lib\site-packages\platformio\builder\tools\pioplatform.py", line 197:
    % board_config.get_debug_tool_name(env.GetProjectOption("debug_tool")),
  File "C:\Users\gigwe\.platformio\penv\lib\site-packages\platformio\platform\board.py", line 127:
    raise DebugInvalidOptionsError(
===================================================================================== [FAILED] Took 0.76 seconds =====================================================================================

 *  The terminal process "C:\Users\gigwe\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Is there any other thing I’m missing out ?

Hm that’s weird, never seen that before. Gotta do some research about that.

Yes, this is expected, PlatformIO does not recognize esp-prog for the nordicnrf52 platform. At the end you’ll probably have to use debug_server configuration lines. But first we have to make OpenOCD connect to the nRF52.

1 Like

Aha. So some critical info is in

and the config file at openocd/minimodule-swd.cfg at master · openocd-org/openocd · GitHub is also actually for a FT2232H.

And just for reference the esp-prog schematic for the FT2232H is

So can you modify the copied esp32_devkitj_v1.cfg file to

adapter driver ftdi
ftdi vid_pid 0x0403 0x6010 0x0403 0x6014

# interface 1 is the uart
ftdi channel 0

# TCK, TDI, TDO, TMS: ADBUS0-3
# LEDs: ACBUS4-7

# ADBUS0 (TCK)      SWCLK
# ADBUS2 (TDI/TDO)  SWDIO
# ADBUS1 (TDO/TDI)  SWDIO
# ADBUS4 (GPIOL0)   nRESET

ftdi layout_init 0x0008 0xf00b
ftdi layout_signal LED -data 0x1000
ftdi layout_signal LED2 -data 0x2000
ftdi layout_signal LED3 -data 0x4000
ftdi layout_signal LED4 -data 0x8000

ftdi layout_signal nSRST -data 0x0010 -oe 0x0010
ftdi layout_signal SWD_EN -data 0
ftdi layout_signal SWDIO_OE -data 0

adapter speed 5000

and make sure to connect TDI and TDO to SWDIO. The ADBUS4 signal is not available on the esp-prog, so let’s hope we won’t need it for now. Then retry the same OpenOCD command.

@maxgerhardt please can you clarify this statement.

Can you specify the new connection. Here’s my current connection.

For more context, here’s the debug and trace overview for nrf52840:

I read the OpenOCD comments such that OpenOCD will always read data in TDI (test data in) and always write data in TDO (test data out). Since SWDIO pin is bidirectional, you actually have to connect both TDI and TDO to SWDIO. A wire from both TDI and TDO to SWDIO.

I don’t think TestModeSelect needs to be connected at all?

@maxgerhardt Thanks for the clarification. I have connected both TDO and TDI pin from the esp-prog to the Xiao’s SWDIO pin. Here’s the output from openocd:

C:\Users\gigwe\.platformio\packages\tool-openocd>bin\openocd.exe -s scripts -f interface/ftdi/esp32_devkitj_v1.cfg -c "transport select swd" -f target/nrf52.cfg
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 5000 kHz

Info : FTDI SWD mode enabled
swd
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Error: Error connecting DP: cannot read IDR

Update: I got the same response when I connected TDO,TDI and TMS to Xiao’s SWIDIO pin.

Can you change both 0x0010 to 0x0008 so that the nRRST will be mapped onto ADBUS3 instead of ADBUS4, then connect TMS to the reset pin of the Xiao.

Here’s the new configuration for esp32_devkitj_v1.cfg:


# SPDX-License-Identifier: GPL-2.0-or-later
#
# Driver for the FT2232H JTAG chip on the Espressif DevkitJ board
# (and most other FT2232H and FT232H based boards)
#

adapter driver ftdi
ftdi vid_pid 0x0403 0x6010 0x0403 0x6014

# interface 1 is the uart
ftdi channel 0

# TCK, TDI, TDO, TMS: ADBUS0-3
# LEDs: ACBUS4-7

# ADBUS0 (TCK)      SWCLK
# ADBUS2 (TDI/TDO)  SWDIO
# ADBUS1 (TDO/TDI)  SWDIO
# ADBUS4 (GPIOL0)   nRESET

ftdi layout_init 0x0008 0xf00b
ftdi layout_signal LED -data 0x1000
ftdi layout_signal LED2 -data 0x2000
ftdi layout_signal LED3 -data 0x4000
ftdi layout_signal LED4 -data 0x8000

ftdi layout_signal nSRST -data 0x0008 -oe 0x0008
ftdi layout_signal SWD_EN -data 0
ftdi layout_signal SWDIO_OE -data 0

adapter speed 5000

TMS is connected to the reset pin of the board and we have the same output:

C:\Users\gigwe\.platformio\packages\tool-openocd>bin\openocd.exe -s scripts -f interface\ftdi\esp32_devkitj_v1.cfg -c "transport select swd" -f target\nrf52.cfg
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
adapter speed: 5000 kHz

Info : FTDI SWD mode enabled
swd
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Error: Error connecting DP: cannot read IDR

Hmpf :frowning: I’ll have to ask you to seek help with OpenOCD directly at OpenOCD - Open On-Chip Debugger / Tickets. I don’t see a reason why it shouldn’t be possible to use a FT2232H (that the esp-prog is) to talk SWD to the nRF52 chip. It has to be something in the configuration file or in the wiring.

Otherwise, the other supported debugging probes are jlink, cmsis-dap, blackmagic (BlackMagicProbe).

Thanks @maxgerhardt for the awesome feedbacks. I will get another debugging probe.