PlatformIO Community

Cannot upload und debug Arduino Due with Stlink-V3set

I have this ini settings:

[env:due]
platform = atmelsam
board = due
framework = arduino
debug_tool = stlink
upload_protocol = stlink

I get the following output:
Warn : target at91sam3X8E.cpu examination failed
embedded:startup.tcl:1070: Error: ** Unable to reset target **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 1107
at file “embedded:startup.tcl”, line 1070
*** [upload] Error 1

NRST of ST-Link connected to the RESET pin?

Yes, the Stlink is connected to the 10pin JTAG port of the Arduino Due

And the connector is on the way right way around right?

Can you try adding

upload_flags =
   -c
   reset_config trst_only separate

to the platformio.ini and iterate the reset config through the available combinations (here, here) and see what works for uploading?

I have tried the flags as follows but it did not help !

upload_flags = -c reset_config none
upload_flags = -c reset_config trst_only
upload_flags = -c reset_config srst_only
upload_flags = -c reset_config trst_and_srst

Any other idea ?

picture of my setup:
IMG_20220310_144651

Thanks for your help.

Just for testing, when you remove the upload_flags again, and hold down the Reset button of the board, then press the Upload button in VSCode and only release the code shortly after the OpenOCD output appears (or the OpenOCD output appears to briefly halt), does uploading work then?

No, it does not help

Since I don’t have a Arduino Due I can’t help further. Either someone else from the forum has an idea, or open an issue at Issues · platformio/platform-atmelsam · GitHub. Due to the war, an answer will take its time however.

Thanks for your help !

Hi,
i found this conversation of yours.

I tried it and i am able to upload the blinky example with stlink/v2 but it does not blink. if i upload using usb programming port it blinks.

#extra_script.py:

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/stlink.cfg",

               "-c", 'set CHIPNAME at91sam3X8E',

               '-c', 'source [find target/at91sam3ax_8x.cfg]']

)

env.Append(

UPLOADERFLAGS=["-c", "telnet_port disabled; program {$SOURCE} 0x80000 verify reset; shutdown"]

)

env.Replace(

UPLOADER="openocd",

UPLOADCMD="$UPLOADER $UPLOADERFLAGS"

)

#platformio.ini

[env:due]

platform = atmelsam

board = due #dueUSB #due

framework = arduino

debug_tool = stlink

#upload_protocol = stlink

extra_scripts = extra_script.py

upload_protocol = custom

; Examples 2: temporary stop at void loop() function

debug_init_break = tbreak loop

; Examples 3: stop in main.cpp at line 13

#debug_init_break = break main.cpp:13

build_unflags = -Os

build_flags = -Og -g3 -ggdb3

#debug_tool = custom

debug_server = /Users/phillip/.platformio/packages/tool-openocd/bin/openocd

            -d3

            -s

            /Users/phillip/.platformio/packages/tool-openocd/scripts

            -f

            interface/stlink.cfg

            -c "set CHIPNAME at91sam3X8E"

            -c  "source [find target/at91sam3ax_8x.cfg]"

the upload window:

Building .pio\build\due\firmware.bin
Configuring upload protocol…
AVAILABLE: atmel-ice, blackmagic, custom, jlink, sam-ba, stlink
CURRENT: upload_protocol = custom
Uploading .pio\build\due\firmware.bin
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
at91sam3X8E
Info : auto-selecting first available session transport “hla_swd”. To override use 'transport select '.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 500 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.222587
Info : at91sam3X8E.cpu: Cortex-M3 r2p0 processor detected
Info : at91sam3X8E.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for at91sam3X8E.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0010004c msp: 0x20001000
** Programming Started **
Info : sam3 auto-erases while programming (request ignored)
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
=========================================================== [SUCCESS] Took 12.04 seconds ===========================================================

I would be very greatful for your help.
Thanks and regards.

With this hardware, does it just work with upload_protocol = stlink and no further scripts / modifciations?

No, i get the following message:

Building .pio\build\due\firmware.bin
Configuring upload protocol…
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\due\firmware.bin
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
debug_level: 1

0x2ba01477
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0010004c msp: 0x20001000
** Programming Started **
Warn : no flash bank found for address 0x00000000
** Programming Finished **
** Verify Started **
Error: checksum mismatch - attempting binary compare
embedded:startup.tcl:1070: Error: ** Verify Failed **
in procedure ‘program’
in procedure ‘program_error’ called at file “embedded:startup.tcl”, line 1131
at file “embedded:startup.tcl”, line 1070
*** [upload] Error 1

o_O all of this is very weird. Please report this to Issues · platformio/platform-atmelsam · GitHub for te developers. Due to the war, things may take a while though.

the modified script uploads the firmware.bin file but fails with .elf file.

UPLOADERFLAGS=["-c", “telnet_port disabled; program {/Users/phillip/Documents/PlatformIO/Projects/220310-081051-due/.pio/build/due/firmware.elf} 0x80000 verify reset; shutdown”]

if i try without platformio:

C:\Users\Phillip>/Users/phillip/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/phillip/.platformio/packages/tool-openocd/scripts -f interface/stlink.cfg -c “set CHIPNAME at91sam3X8E” -c “source [find target/at91sam3ax_8x.cfg]” -c “telnet_port disabled; program {/Users/phillip/Documents/PlatformIO/Projects/220310-081051-due/.pio/build/due/firmware.elf} verify reset; shutdown;”
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
debug_level: 2

at91sam3X8E
Info : auto-selecting first available session transport “hla_swd”. To override use 'transport select '.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 500 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.221011
Info : at91sam3X8E.cpu: Cortex-M3 r2p0 processor detected
Info : at91sam3X8E.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for at91sam3X8E.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x0010004c msp: 0x20001000
** Programming Started **
Info : sam3 auto-erases while programming (request ignored)
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

But it also does not blink !!