Right, so I have found an excellent thread where a solution was proposed.
Help with PIO Debugger using Atmel ICE and Arduino Due - #24 by maxgerhardt?
The problem lies in the OpenOCD uploader, which -if I understand correctly- tries to treat the .bin outptu t in the same way as the .elf and causes and error when erasing the chip. At any rate, the topic suggeted a custom script that would prepend OpenOCD options that allow an upload.
If you read towards the end of the topic you can see how the solution was obtained. My platformio.ini now looks like this:
[env:due]
platform = atmelsam
board = sainSmartDueUSB
framework = arduino
extra_script = extra_script.py
upload_protocol = custom
build_type = debug
build_unflags = -Os
build_flags = -Og -g3 -ggdb3
debug_tool = custom
debug_init_break = tbreak setup
debug_server =
/Users/Thinkpad/.platformio/packages/tool-openocd/bin/openocd
-d2
-s
/Users/Thinkpad/.platformio/packages/tool-openocd/scripts
-f
interface/cmsis-dap.cfg
-c “set CHIPNAME at91sam3X8E”
-c “source [find target/at91sam3ax_8x.cfg]”
…and the extra_script.py looks as follows:
from os import path
Import(“env”)
platform = env.PioPlatform()
env.Prepend(
UPLOADERFLAGS=[“-s”, path.join(platform.get_package_dir(“tool-openocd”), “scripts”) or “”,
“-f”, “interface/cmsis-dap.cfg”,
“-c”, ‘set CHIPNAME at91sam3X8E’,
‘-c’, ‘source [find target/at91sam3ax_8x.cfg]’]
)
env.Append(
UPLOADERFLAGS=[“-”, “telnet_port disabled; program {$SOURCE} 0x80000 verify reset; shutdown”]
)
env.Replace(
UPLOADER=“openocd”,
UPLOADCMD=“$UPLOADER $UPLOADERFLAGS”
)