PlatformIO Community

Help with PIO Debugger using Atmel ICE and Arduino Due

Hi, This may be a very basic question, I’m not sure if I’m doing anything wrong, when I run the debugger with Atmel ICE, It seems like it starts and I actually see my application running but it doesn’t stop at the main at the beginning nor at my breakpoints. Then I changed the init to start at my setup(), but it doesn’t do that either.

debug_init_break=tbreak setup

I know the debugger is working because If I pause it, then I can take it from wherever is running. Also, if have added a few breakpoints and it doesn’t stop.

One more thing, I can’t program it through the Atmel ICE using the “upload” task, even though I changed the upload_protocol to atmel-ICE, I’ve been programming through the programing USB port. The programming part doesn’t worry me very much because I can’t still program my board, but the debugging part is the one that is concerning me.

Here is my console print and ini file.

Thanks!!

[env:due]
platform = atmelsam
lib_extra_dirs = ~/Documents/Arduino/libraries
board = due
framework = arduino
lib_extra_dirs=C:\Users\saez.gerardo\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12
debug_tool=atmel-ice
build_type=debug
debug_init_break=tbreak setup
debug_svd_path=C:/Users/saez.gerardo/AppData/Roaming/SPB_Data/.platformio/platforms/atmelsam/misc/svd/ATSAM3X8E.svd
*****************************************************************************************************************
xPSR: 0x01000000 pc: 0x00083a1c msp: 0x20088000
Loading section .text, size 0x8f48 lma 0x80000
Loading section .ARM.exidx, size 0x8 lma 0x88f48
Loading section .relocate, size 0xa70 lma 0x88f50
Start address 0x83a1c, load size 39360
Transfer rate: 31 KB/sec, 7872 bytes/write.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00083a1c msp: 0x20088000
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00083a1c msp: 0x20088000
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak setup`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
***************************************************************************************
  1. Please remove debug_svd_path from the configuration above, PlatformIO handles built-in SVDs automatically.
  2. You 2 lib_extra_dirs, the last one will be used.

So, these are minor issues and are not related to debugging. Let’s go with debugging. Before we start debugging, need to check that openOCD + Atmel-ICE = work.


Please try this configuration:

[env:due]
platform = atmelsam
board = due
framework = arduino
debug_tool=atmel-ice
upload_protocol = atmel-ice
build_type=debug

Also, please use simple sketch - Blink, or similar to it. Open PlatformIO IDE terminal and type

pio run -t upload --verbose

Please post output to https://hastebin.com and share here a link. Thanks!

Hi Ivan,

Thank you for your reply, I tried this configuration with both my code and the blink code and I got the same results. I tried to save the output on hastebin, but the save button wasn’t working for me (I tried chrome and IE), here is the output.

Thanks,

C:\Users\saez.gerardo\Documents\PlatformIO\Projects\Blink>pio run -t upload --verbose
Processing due (platform: atmelsam; board: due; framework: arduino; debug_tool: atmel-ice; upload_protocol: atmel-ice; build_type: debug)
---------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION:
PLATFORM: Atmel SAM 3.7.0 > Arduino Due (Programming Port)
HARDWARE: AT91SAM3X8E 84MHz, 96KB RAM, 512KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink, stlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-arduinosam 4.2.190701, tool-openocd 2.1000.190422 (10.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
MethodWrapper(["checkprogsize"], [".pio\build\due\firmware.elf"])
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   2.6% (used 2576 bytes from 98304 bytes)
PROGRAM: [          ]   2.1% (used 11216 bytes from 524288 bytes)
.pio\build\due\firmware.elf  :
section             size        addr
.text              11216      524288
.relocate           1188   537329664
.bss                2576   537330852
.ARM.attributes       41           0
.comment             238           0
.debug_info       149696           0
.debug_abbrev      19246           0
.debug_aranges      1800           0
.debug_ranges       2056           0
.debug_macro      122627           0
.debug_line        84002           0
.debug_str        433213           0
.debug_frame        5064           0
.debug_loc         15056           0
Total             848019
<lambda>(["upload"], [".pio\build\due\firmware.bin"])
AVAILABLE: atmel-ice, blackmagic, jlink, sam-ba, stlink
CURRENT: upload_protocol = atmel-ice
openocd -d2 -s C:\Users\saez.gerardo\AppData\Roaming\SPB_Data\.platformio\packages\tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -f target/at91sam3XXX.cfg -c "program {.pio\build\due\firmware.bin}  verify reset; shutdown;"
GNU MCU Eclipse OpenOCD, 64-bitOpen On-Chip Debugger 0.10.0+dev-00593-g23ad80df4 (2019-04-22-20:25)
Licensed under GNU GPL v2
For bug reports, read
        
debug_level: 2
at91sam3X8E
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
adapter speed: 500 kHz
adapter_nsrst_delay: 100
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 01.00.0021
Info : CMSIS-DAP: Serial# = J41800117823
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91sam3X8E.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00086358 msp: 0x20088000
** Programming Started **
embedded:startup.tcl:479: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 538
at file "embedded:startup.tcl", line 479
*** [upload] Error 1

Could you make a photo of your wire connection?

I am experiencing the same issue. I will post the wiring when I can. We would really like to get this working.

Here is the output when I use the verbose upload command.

https://pastebin.com/jFcjct1a

Here is the output when I debug. I have disabled the default “main” breakpoint and have placed breakpoints in my setup and loop methods, but neither one seems to be called.

https://pastebin.com/gCFrVpUM

So uploading seems to fail. However I don’t see how the error could be produced

program [address] [verify] [reset] [exit]

Error: invalid subcommand “write_image erase .pio/build/due/firmware.bin”

embedded:startup.tcl:449: Error: ** Programming Failed **

Because the program is clearly invoked with the program command

openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c “set CHIPNAME at91sam3X8E” -f target/at91sam3XXX.cfg -c “program {.pio/build/due/firmware.bin} verify reset; shutdown;”

What happens when you do the following command in your shell?

 /Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -f target/at91sam3XXX.cfg -c "program {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin}  verify reset; shutdown;"  

I ran the command from the terminal in VSCode. This was the output.

et-laptop-mock:FSMotionController hackmodford$ /Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -f target/at91sam3XXX.cfg -c "program {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin}  verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
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 "swd". To override use 'transport select <transport>'.
cortex_m reset_config sysresetreq

Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 01.27.0082
Info : CMSIS-DAP: Serial# = J41800107410
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91sam3X8E.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00088f18 msp: 0x20088000
** Programming Started **
flash
  flash bank bank_id driver_name base_address size_bytes chip_width_bytes
            bus_width_bytes target [driver_options ...]
  flash banks
  flash init
  flash list
gdb_flash_program ('enable'|'disable')
mflash
  mflash bank soc_type base_addr pin_id target
  mflash init
nand
program <filename> [address] [verify] [reset] [exit]
Error: invalid subcommand "write_image erase /Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin"
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 508
at file "embedded:startup.tcl", line 449

OK so without any interaction of PlatformIO, openocd fails to program the firmware. Can you re-run the command but with -d3 instead of -d2 please? (log to pastebin.com if it’s too large)

Here is the result of using -d3

https://pastebin.com/t0yk4vND

Thank you. I’ve come across this thread (https://www.visualmicro.com/forums/YaBB.pl?num=1568359560/0) and the command there seems to work… But they have double {{}} in the program command. Does the following command produce the same error?

/Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -f target/at91sam3XXX.cfg -c "program {{/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin}}  verify reset; shutdown;"

Seems so.

et-laptop-mock:FSMotionController hackmodford$ /Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -f target/at91sam3XXX.cfg -c "program {{/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin}}  verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
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 "swd". To override use 'transport select <transport>'.
cortex_m reset_config sysresetreq

Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 01.27.0082
Info : CMSIS-DAP: Serial# = J41800107410
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91sam3X8E.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00088f18 msp: 0x20088000
** Programming Started **
flash
  flash bank bank_id driver_name base_address size_bytes chip_width_bytes
            bus_width_bytes target [driver_options ...]
  flash banks
  flash init
  flash list
gdb_flash_program ('enable'|'disable')
mflash
  mflash bank soc_type base_addr pin_id target
  mflash init
nand
program <filename> [address] [verify] [reset] [exit]
Error: invalid subcommand "write_image erase {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin}"
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 508
at file "embedded:startup.tcl", line 449

Ok one last try. Does this command produce a different error? It now uses the same source [find ..] command from the forum post.

/Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -c "source [find target/at91sam3ax_8x.cfg]" -c "telnet_port disabled; program {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin} verify reset; shutdown;"

I think it’s the same :frowning:

et-laptop-mock:FSMotionController hackmodford$ /Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -c "source [find target/at91sam3ax_8x.cfg]" -c "telnet_port disabled; program {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin} verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
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 "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 01.27.0082
Info : CMSIS-DAP: Serial# = J41800107410
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91sam3X8E.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00088f18 msp: 0x20088000
** Programming Started **
Error: couldn't open /Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 508
at file "embedded:startup.tcl", line 449
et-laptop-mock:FSMotionController hackmodford$

Does this file still exist? Or did you clear the project intermittenly? Please compile the project again and retry the last openocd command.

Interesting… the file wasn’t there so I rebuilt everything and verified it was there.
Now it’s saying that the checksum doesn’t match.

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
et-laptop-mock:FSMotionController hackmodford$ /Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -c "source [find target/at91sam3ax_8x.cfg]" -c "telnet_port disabled; program {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.bin} verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
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 "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 01.27.0082
Info : CMSIS-DAP: Serial# = J41800107410
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91sam3X8E.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00088f18 msp: 0x20088000
** Programming Started **
Warn : no flash bank found for address 0x00000000
** Programming Finished **
** Verify Started **
Error: checksum mismatch - attempting binary compare
embedded:startup.tcl:449: Error: ** Verify Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 494
at file "embedded:startup.tcl", line 449
et-laptop-mock:FSMotionController hackmodford$

Meh because it uses the .bin and not the .elf file, maybe it doesn’t know the memory maps. Can you try this command?

/Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -c "source [find target/at91sam3ax_8x.cfg]" -c "telnet_port disabled; program {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.elf} verify reset; shutdown;"

It looks like it worked!

et-laptop-mock:FSMotionController hackmodford$ /Users/hackmodford/.platformio/packages/tool-openocd/bin/openocd -d2 -s /Users/hackmodford/.platformio/packages/tool-openocd/scripts -f interface/cmsis-dap.cfg -c "set CHIPNAME at91sam3X8E" -c "source [find target/at91sam3ax_8x.cfg]" -c "telnet_port disabled; program {/Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.elf} verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)
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 "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 01.27.0082
Info : CMSIS-DAP: Serial# = J41800107410
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91sam3X8E.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000864b8 msp: 0x20088000
** Programming Started **
Info : sam3 auto-erases while programming (request ignored)
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

So the question now is how to invoke the modified command when I press the upload button. And then to figure out why debugging doesn’t seem to work.

Here’s the output I get when debugging.
It seems to work, but none of my breakpoints nor the default “main” breakpoint gets hit.

Reading symbols from /Users/hackmodford/Code/PlatformIO/FSMotionController/.pio/build/due/firmware.elf…

done.

PlatformIO Unified Debugger -> http://bit.ly/pio-debug

PlatformIO: debug_tool = atmel-ice

PlatformIO: Initializing remote target…

xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-15:21)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.org/doc/doxygen/bugs.html

at91sam3X8E

Info : auto-selecting first available session transport “swd”. To override use 'transport select '.

cortex_m reset_config sysresetreq

Info : tcl server disabled

Info : telnet server disabled

Info : CMSIS-DAP: SWD Supported

Info : CMSIS-DAP: JTAG Supported

Info : CMSIS-DAP: FW Version = 01.27.0082

Info : CMSIS-DAP: Serial# = J41800107410

Info : CMSIS-DAP: Interface Initialised (SWD)

Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1

Info : CMSIS-DAP: Interface ready

Info : clock speed 500 kHz

Info : SWD DPIDR 0x2ba01477

Info : at91sam3X8E.cpu: hardware has 6 breakpoints, 4 watchpoints

Info : accepting ‘gdb’ connection from pipe

target halted due to debug-request, current mode: Thread

xPSR: 0xa1000000 pc: 0x00082d3c msp: 0x20087f78

0x00082d3c in loadConfiguration () at src/main.cpp:160

160 }

Temporary breakpoint 1 at 0x88096: file /Users/hackmodford/.platformio/packages/framework-arduinosam/cores/sam/main.cpp, line 45.

target halted due to debug-request, current mode: Thread

xPSR: 0x01000000 pc: 0x000864b8 msp: 0x20088000

target halted due to debug-request, current mode: Thread

xPSR: 0x01000000 pc: 0x000864b8 msp: 0x20088000

Loading section .text, size 0xe6a8 lma 0x80000

Loading section .ARM.exidx, size 0x8 lma 0x8e6a8

Loading section .relocate, size 0xa70 lma 0x8e6b0

So it seems to put the breakpoint there but never hits it? Can you try this with a more simple blinky sketch which should be fairly compact?