Open clemenseder opened 3 years ago
Per thread it is also possible to specify the flash offset using
[env:due]
platform = atmelsam
board = due
framework = arduino
upload_protocol = stlink
debug_tool = stlink
board_upload.offset_address = 0x80000
but the standard settings should really be correct.
The problem I see is that the .bin
file is used for the OpenOCD upload when the .elf file would be better since it has the address information. Same for the JLink upload.
Or, append the board defnition's JSON files to include "offset_address": "0x80000"
.
There are two issues, one concerns the upload and one the debugging. I am first describing the problems / solutions in A) and then specify the requirements for a fix in B):
A) Problem description and solution with scripts:
1) When connecting an Arduino board through the ATMEL-ICE debugger, the code does not upload. First of all it seems to upload binaries instead of the .elf (although probably created from .elf) and OpenOCD gets stuck with the following line
Error: invalid subcommand "write_image erase Users/xxxxx/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin" embedded:startup.tcl:449: Error: Programming Failed
I have addressed the issue in the community and I have found a solution from the following ealier post https://community.platformio.org/t/help-with-pio-debugger-using-atmel-ice-and-arduino-due/8759/19
The solution (for the upload problem) involved creating a custom script that contains the correct upload settings in Platformio.ini (see below)
[env:due] platform = atmelsam board = sainSmartDueUSB framework = arduino extra_script = extra_script.py upload_protocol = custom . . 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/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" )
2) As for the debugger, the breakpoint was never reached as it got (if I understand correctly) stuck in the Arduino's main routine, which subsequently calls setup() and loop(). It seems that the system needs to be told where to set the first breakpoint after reset...
This was solved by the following switches in Platformio.ini
. . build_type = debug build_unflags = -Os build_flags = -Og -g3 -ggdb3 debug_tool = custom debug_init_break = tbreak setup // Note: works also for tbreak loop 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]”
B) Requirements for a fix
Although it was shown that this could be fixed using changes in upload/debug settings, the user -especially new user- cannot be asked to undertake these without prior extensive knowledge on the overall system. It should be just the case of specifying upload_protocol = atmel_ice, without setting anything else. At the very least, the user should be given clear instructions in
https://docs.platformio.org/en/latest/plus/debug-tools/atmel-ice.html
as it stands at the moment, these instructions are incomplete. I suggest update of the instructions on the web page, but preferably a fix that includes all necessary settings by default.