Skip to content

Commit

Permalink
add support for jlink as transport for openocd
Browse files Browse the repository at this point in the history
though menu selection does not seem to work with debug script. Though
this is probably IDE issue.
  • Loading branch information
hathach committed Jun 22, 2023
1 parent c9e285c commit c3d53ad
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 49 deletions.
193 changes: 161 additions & 32 deletions boards.txt

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,23 @@ tools.openocd.cmd.windows=bin/openocd.exe

tools.openocd.upload.params.verbose=-d2
tools.openocd.upload.params.quiet=-d0
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"

tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b

# Program flashes the binary at 0x0000, so use the linker script without_bootloader
tools.openocd.program.params.verbose=-d2
tools.openocd.program.params.quiet=-d0
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"

tools.openocd.erase.params.verbose=-d3
tools.openocd.erase.params.quiet=-d0
tools.openocd.erase.pattern=

tools.openocd.bootloader.params.verbose=-d2
tools.openocd.bootloader.params.quiet=-d0
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"

#
# OpenOCD sketch upload - version with configurable bootloader size
Expand All @@ -208,20 +208,20 @@ tools.openocd-withbootsize.cmd.windows=bin/openocd.exe

tools.openocd-withbootsize.upload.params.verbose=-d2
tools.openocd-withbootsize.upload.params.quiet=-d0
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"

# Program flashes the binary at 0x0000, so use the linker script without_bootloader
tools.openocd-withbootsize.program.params.verbose=-d2
tools.openocd-withbootsize.program.params.quiet=-d0
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"

tools.openocd-withbootsize.erase.params.verbose=-d3
tools.openocd-withbootsize.erase.params.quiet=-d0
tools.openocd-withbootsize.erase.pattern=

tools.openocd-withbootsize.bootloader.params.verbose=-d2
tools.openocd-withbootsize.bootloader.params.quiet=-d0
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"

# ----------------------------------------
# Debugger configuration (general options)
Expand All @@ -232,13 +232,17 @@ debug.executable={build.path}/{build.project_name}.elf
debug.toolchain=gcc
debug.toolchain.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
debug.toolchain.prefix=arm-none-eabi-

debug.server=openocd
debug.server.openocd.path={runtime.tools.openocd.path}/bin/openocd
debug.server.openocd.scripts_dir={runtime.tools.openocd.path}/share/openocd/scripts/
debug.server.openocd.script={runtime.platform.path}/{build.openocdscript}

# jlink is not supported by arduino-cli yet, but supported by IDE
# JLinkServer is not supported by arduino-cli yet
# https://github.com/arduino/arduino-cli/blob/eca9d9a8f00582a08fadea8a4b7e3ef01b40d082/commands/debug/debug.go#L160
# use debug_custom.json to run JLinkGDBServer instead
# https://docs.arduino.cc/tutorials/mkr-wifi-1010/mkr-jlink-setup
#debug.server=jlink
#debug.server.jlink.path={runtime.tools.openocd.path}/bin/openocd
#debug.server.jlink.scripts_dir={runtime.tools.openocd.path}/share/openocd/scripts/
#debug.server.jlink.path=JLinkGDBServer
#debug.server.jlink.device=ATSAMD21G18
#debug.server.jlink.script={runtime.platform.path}/{build.openocdscript}
6 changes: 6 additions & 0 deletions scripts/jlink/samd21/debug_custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"servertype": "jlink",
"device": "ATSAMD21G18A",
"interface": "SWD",
"serverpath": "JLinkGDBServer"
}
6 changes: 6 additions & 0 deletions scripts/jlink/samd51/debug_custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"servertype": "jlink",
"device": "ATSAMD51G18",
"interface": "SWD",
"serverpath": "JLinkGDBServer"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ source [find interface/cmsis-dap.cfg]
transport select swd

# chip name
set CHIPNAME same51
set CHIPNAME samd51

source [find target/atsame5x.cfg]
27 changes: 27 additions & 0 deletions scripts/openocd/jlink_samd21.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Arduino Zero OpenOCD script.
#
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

source [find interface/jlink.cfg]
transport select swd

# chip name
set CHIPNAME samd21

source [find target/at91samdXX.cfg]
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

source [find interface/cmsis-dap.cfg]
#source [find interface/jlink.cfg]
source [find interface/jlink.cfg]
transport select swd

# chip name
Expand Down
14 changes: 9 additions & 5 deletions tools/makeboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'build_mcu': 'cortex-m0plus',
'f_cpu': '48000000L',
'extra_flags': '-DARDUINO_SAMD_ZERO -DARM_MATH_CM0PLUS',
'openocdscript': 'scripts/openocd/samd2x.cfg',
},

'SAMD51': {
Expand All @@ -35,7 +34,6 @@
'build_mcu': 'cortex-m4',
'f_cpu': '120000000L',
'extra_flags': '-D__SAMD51__ -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16',
'openocdscript': 'scripts/openocd/samd5x.cfg',
},

'SAME51': {
Expand All @@ -45,8 +43,7 @@
'build_mcu': 'cortex-m4',
'f_cpu': '120000000L',
'extra_flags': '-D__SAMD51__ -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16',
'openocdscript': 'scripts/openocd/same5x.cfg',
},
},
}


Expand Down Expand Up @@ -106,7 +103,6 @@ def build_build(mcu, name, variant, vendor, product, vid, pid_list, boarddefine,
print(f"{name}.build.extra_flags={extra_flags} {mcu_properties['extra_flags']} {{build.usb_flags}}")

print(f"{name}.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld")
print(f"{name}.build.openocdscript={mcu_properties['openocdscript']}")
print(f"{name}.build.variant={variant}")
print(f"{name}.build.variant_system_lib=")
print(f"{name}.build.vid={vid}")
Expand Down Expand Up @@ -171,6 +167,13 @@ def build_menu(mcu, name):
print(f"{name}.menu.debug.on.build.flags.debug=-g")
print()

print("# Menu: Debugger")
script_mcu = 'samd21' if mcu == 'SAMD21' else 'samd51'
print(f"{name}.menu.debugger.daplink=CMSIS-DAP (DAPLink)")
print(f"{name}.menu.debugger.daplink.build.openocdscript=scripts/openocd/daplink_{script_mcu}.cfg")
print(f"{name}.menu.debugger.jlink=J-Link")
print(f"{name}.menu.debugger.jlink.build.openocdscript=scripts/openocd/jlink_{script_mcu}.cfg")


def build_global_menu():
print("menu.cache=Cache")
Expand All @@ -179,6 +182,7 @@ def build_global_menu():
print("menu.maxqspi=Max QSPI")
print("menu.usbstack=USB Stack")
print("menu.debug=Debug")
print("menu.debugger=Debugger")


def make_board(mcu, name, variant, vendor, product, vid, pid_list, boarddefine, extra_flags, bootloader):
Expand Down

0 comments on commit c3d53ad

Please sign in to comment.