Help with PIO Debugger using Atmel ICE and Arduino Due

I created the blinky sketch and this was the results of the debugger.

Reading symbols from /Users/hackmodford/Code/PlatformIO/Test/.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 <transport>'.

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 : at91sam3X8E.cpu: external reset detected

Info : accepting 'gdb' connection from pipe

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

xPSR: 0x81000000 pc: 0x00080a88 msp: 0x20087fe0

0x00080a88 in USB_ISR () at /Users/hackmodford/.platformio/packages/framework-arduinosam/cores/sam/USB/USBCore.cpp:791

791 else if (GET_INTERFACE == r)

Temporary breakpoint 1 at 0x8016a: 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: 0x00080f14 msp: 0x20088000

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

xPSR: 0x01000000 pc: 0x00080f14 msp: 0x20088000

Loading section .text, size 0x2bd0 lma 0x80000

Loading section .relocate, size 0x4a4 lma 0x82bd0

If I randomly pause execution, it does seem to work. It just never stops at the breakpoints I specify.

I’ve reached the max number of replies for a new user today :astonished:

In response to the next post. It seems the same.

Reading symbols from /Users/hackmodford/Code/PlatformIO/Test/.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 <transport>'.

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 : at91sam3X8E.cpu: external reset detected

Info : accepting 'gdb' connection from pipe

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

xPSR: 0x81000000 pc: 0x00080bf0 msp: 0x20087fd8

__empty () at /Users/hackmodford/.platformio/packages/framework-arduinosam/cores/sam/hooks.c:30

30 }

Temporary breakpoint 1 at 0x8016a: 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: 0x000810fc msp: 0x20088000

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

xPSR: 0x01000000 pc: 0x000810fc msp: 0x20088000

Loading section .text, size 0x2bd0 lma 0x80000

Loading section .relocate, size 0x4a4 lma 0x82bd0

Start address 0x810fc, load size 12404

Transfer rate: 36 KB/sec, 6202 bytes/write.

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

xPSR: 0x01000000 pc: 0x000810fc msp: 0x20088000

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

xPSR: 0x01000000 pc: 0x000810fc msp: 0x20088000

PlatformIO: Initialization completed

PlatformIO: Resume the execution to `debug_init_break = tbreak main`

PlatformIO: More configuration options -> http://bit.ly/pio-debug

Could you add to your platformio.ini

build_unflags = -Os
build_flags = -Og -g3 -ggdb3

and see whether the result changes?

PS: You need to again flash this firmware manually with the command above

Hey maxgerhardt,

My name is Alex, I’m working with Hackmodford (Brandon) on the Arduino Due with the Atmel ICE debugger. Just want to let you know Brandon hit the “max # of replies for a new user” so he’s unable to reply at the moment. He is able to append to his old replies though, not sure if you saw it, but Brandon mentioned that he tried flashing the ATmel ICE manually but that did not seem to change the result. Do you have any other suggestions? Thank you for your help. We really want this debugger to work.

-Alex

Hm. Let’s first patch the corrected upload method via an extra script to make that more robust, maybe the pio debug command can then also upload the (right) firmware?

Add to the platformio.ini

extra_scripts = extra_script.py
upload_protocol = custom

Add a extra_script.py on the same level as the platformio.ini with:

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=["-c", "telnet_port disabled; program {$SOURCE} 0x80000 verify reset; shutdown"]
)
env.Replace(
    UPLOADER="openocd",
    UPLOADCMD="$UPLOADER $UPLOADERFLAGS"
)

Does then the normal upload button work?

I’ve upgraded your trust level so this should be solved.

1 Like

I’ll try again tomorrow around 2:00pm EST.
You’ve been a huge help!

I made the changes and uploading is working via the upload button now.

However, debugging still has the same issue.

Great!

Then let’s try the same openocd target for debugging, maybe things change. Still, the build_flag stuff should be kept in there to ensure a debug build for now. Add to the platformio.ini (adapted from docs):

build_unflags = -Os
build_flags = -Og -g3 -ggdb3
debug_tool = custom
debug_server =
	/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]" 

What’s the log now debugging? Does the behavior change?

I tried the changes. Now, I do not get the debugger stop/pause/step controls in VSCode.

Could you execute pio debug -v in a PIO terminal and post the output.

Here it is.

Put this corrected debug_server in the platformio.ini

debug_server =
	/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]" 

Then go `Debug → Start Debugging" . After that, what is the output in the “Debug Console”, especially since openocd is started?

1 Like

This is what I get now.

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 = custom
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
debug_level: 2

at91sam3X8E
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
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: 0x61000000 pc: 0x00083ff2 msp: 0x20087f40
SPIClass::transfer (this=this@entry=0x20070de8 <SPI>, _pin=_pin@entry=78 'N', _buf=_buf@entry=0x20087f64, _count=1, _count@entry=3, _mode=_mode@entry=SPI_LAST) at /Users/hackmodford/.platformio/packages/framework-arduinosam/libraries/__cores__/sam/SPI/src/SPI.cpp:260
260		while ((spi->SPI_SR & SPI_SR_RDRF) == 0)
Temporary breakpoint 1 at 0x88256: 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: 0x000892b0 msp: 0x20088000
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000892b0 msp: 0x20088000
Info : sam3 auto-erases while programming (request ignored)
Loading section .text, size 0xe868 lma 0x80000
Loading section .ARM.exidx, size 0x8 lma 0x8e868
Loading section .relocate, size 0xa70 lma 0x8e870
Warn : keep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (4293). Workaround: increase "set remotetimeout" in GDB
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000892b0 msp: 0x20088000
Start address 0x892b0, load size 62176
Transfer rate: 13 KB/sec, 10362 bytes/write.
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000892b0 msp: 0x20088000
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x000892b0 msp: 0x20088000
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.
Error: Can not find free FPB Comparator!
Error: can't add breakpoint: resource not available
Error: Can not find free FPB Comparator!
Error: can't add breakpoint: resource not available
Warning:
Cannot insert hardware breakpoint 2.
Cannot insert hardware breakpoint 1.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

Command aborted.

Any other ideas I can try?

Seems like the debugger is kinda overloaded with the breakpoint requests (no flash patch blocks / breakpoints free)? Can you try to remove all breakpoints, then start debugging, pause execution, place a breakpoint at loop(), then ‘continue’ and see if the breakpoint is hit? The logs for that would also be interesting.

Can you also try to again remove all breakpoints, add the line

debug_init_break = tbreak loop

to the platformio.ini (ref), then start debugging and see if it hits the breakpoint?

1 Like

I get some kind of breakpoint triggered in Reset_Handler.dbgasm (looks like assembly code) but it goes away.

Then it breaked in the loop function! I think we have a success!

Ok, so I had the same problem, and solved it exactly like you did. Thanks to maxgerhardt. Now I’m wondering if that’s a desired behaviour ? or does it get fixed in the future ?
If you tell me that’s the desired behaviour I’d be fine with that too, because it’s just a question of configuring openocd the right way. But still the question remains in my head.

Nonetheless thanks maxgerhardt for helping out noobs :stuck_out_tongue:

Do we have an issue in default debug configuration? If yes, please file a bug report here Issues · platformio/platform-atmelsam · GitHub and we will fix it. Thanks!

I have a space in my username, so I can’t reference to the path:

"Users\firstname lastname\.platformio\packages\tool-openocd\bin\openocd"

Any tips?
What I tried:
${USERPROFILE}/.platformio/packages/tool-openocd/bin/openocd
$USERPROFILE$/.platformio/packages/tool-openocd/bin/openocd
Users/firstname^ lastname/.platformio/packages/tool-openocd/bin/openocd
Users/"firstname lastname"/.platformio/packages/tool-openocd/bin/openocd

I couldn’t reproduce the issue with a whitespace character. What version of PlatformIO do you use?

Thank you very much for your post. You did not only help Hackmodford but also myself. I have opened a new topic that would have fitted into here, but I have linked to your solution.

Arduino Due (or other SAM3/4) upload fails with ATMEL ICE JTAG on VSCode with PlatformIO?

I have previously worked with a combination of notepad++ for editing, Arduino IDE for compiling, and Atmel Studio 7 for uploading .elf/.hex files. But I have obviously missed an integrated IDE that allows debugging with breakpoints. I have tried many times (and failed) to open Arduino Due projects directly in Atmel Studio, as not all of the paths were set correctly. So being able to use an integrated IDE is great!

However, I feel on really thin ice here, as I am not sure what exactly you did with these switch settings that fixed the problem, and I would be completely helpless if I found myself in a similar situation in the future. I hope that not all the debug/upload setups are that cumbersome for every single processor…