Fast Debug and Upload by using JLINK in platformio

Make sure the JLINK driver is SEGGER’s and use the latest version.

This is my settings.
platformio.ini:

[env:jlink_debug_and_upload]
platform = gd32v
board = sipeed-longan-nano
framework = gd32vf103-sdk
extra_scripts = extra_script.py
upload_protocol = custom
debug_tool = custom
debug_server =
  C:\Program Files (x86)\SEGGER\JLink\JLinkGDBServerCL.exe
  -singlerun
  -if
  JTAG
  -select
  USB
  -port
  2331
  -device
  GD32VF103CBT6
debug_extra_cmds = set $pc=0x08000000

Make this file: extra_scripts.py in same directory as platformio.ini:

from os import makedirs
from os.path import isdir, join
Import('env')

def _jlink_cmd_script(env, source):
    build_dir = env.subst("$BUILD_DIR")
    if not isdir(build_dir):
        makedirs(build_dir)
    script_path = join(build_dir, "upload.jlink")
    commands = ["h", "loadfile %s,0" % source , "r", "q"]
    with open(script_path, "w") as fp:
        fp.write("\n".join(commands))
    return script_path

env.Replace(
    __jlink_cmd_script=_jlink_cmd_script,
    UPLOADER="C:/Program Files (x86)/SEGGER/JLink/JLink.exe",
    UPLOADERFLAGS=[
        "-device", "GD32VF103CBT6",
        "-speed", "4000",
        "-if", "jtag",
        "-autoconnect", "1"
    ],
    UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS -CommanderScript ${__jlink_cmd_script(__env__, SOURCE) } '
)

works very well,
much faster than debug_tool = jlink

It’s not working unfortunatelly :frowning: