Debugging Arduino Due using SAM-ICE JTAG (an approach)

Remarkable M4nu!. It's awesome to know that you have tested it and it works. It's an expensive solution ($100+) but it worth the price to be able to track inside SAM3X8E's intricate labyrinth. By the way, few weeks ago Massimo recommended another solution.

I haven't checked the price but it looks like a less expensive solution.

You guys seem to have a good background in arm, can you suggest a good resource for learning the platform - as an example where do you find out that you need to call TC_GetStatus inside a timer interrupt to reenable it and all of the other gotcha's that us AVR folks are going to struggle to find out ?

Duane B

@Palliser:
I bought a already used device for 30 euro and additionally the adapter form olimex for 10 euro with shipping. So I think the price is ok, but if ones would like to buy a new one then I agree with you. The price for a new "Black Magic Probe Mini" is 75$ by http://thequadshot.com/products/black-magic-probe-mini. Another solution is the jlink edu version from segger. I'm not abble to test it but it should be almost the same device like sam-ice. The only difference is that sam-ice can only debug atmel devices.

@DuaneB:
Hm... I read a lot in the data sheets, forums and tried to understand the examples from Atmel Framework.

Hi,
Trying to download the framework now, thanks

Duane

I do not regard myself as a good in ARM (specially in Cortex M core) but I would recommend a book: The Definitive Guide to the ARM Cortex-M3, Second Edition by ARM expert Joseph Yiu.
http://www.amazon.com/Definitive-Guide-ARM-Cortex-M3-Second/dp/185617963X.

I purchased it few weeks ago but to be honest, I've been busy these days to go through it. Please, read the Amazon.com comments and see. regards!

Hi All, I'm using the SAM-JTAG and Atmel Framework examples on a pvt SAM3X hw and also SAM3X-EK - I'm hoping to get a production Due when they arrive later this month at Digikey, Sparkfun etc.
I've brought in the Arduino DUE C++ framework to Atmel Studio 6, however when downloading through the JTAG I haven't bee able to put watches in the internal RAM.
I can get access to the peripheral memory map with the C drivers it seems - which is really nice

Anybody got the symbolics working and accessible with Atmels Studio C++ compiler?

You guys seem to have a good background in arm

The trouble is I'll bet almost nobody here actually programs the "ARM" as such, with the exception of the NVIC we deal with chip's peripherals which are different for every manufacturer. (OK don't ping me if you're an ARM assembly expert :))

FWIW I use the LPCXpresso and having a full debugger is fantastic, I know I've written a lot of code over the years without one but damned if I know how :slight_smile:


Rob

FYI I have symbolics working with Atmel Studio 6.0.1996 (released Nov 2012)
So the toolchain is DUEX powered externally with 9volts, DUE JTAG connector (10pin 0.05") -- cable ARM-JTAG-10-10 --(20pin 0.1") Atmel SAM-ICE JTAG emulator to USB port with Atmel Studio 6.0.1966 running on Win XP latest.
The SAM3X has something like 5 hardware breakpoints on chip, and as from AS6.0 Build 1996 supports symbolic decoding, watching internal variables.
I used it on the USB Host code, Uhi_cdc.c: so haven't tested it on any .cpp yet.
The SAM-ICE JTAG is happier connected directly to a USB port. When it goes through a hub it would periodically get upset.
Even connected directly to a hub sometimes the segger JLINK.exe has an exception.

DueWithJtag0_05inConnector.jpg

neil12:
FYI I have symbolics working with Atmel Studio 6.0.1996 (released Nov 2012)
So the toolchain is DUEX powered externally with 9volts, DUE JTAG connector (10pin 0.05") -- cable ARM-JTAG-10-10 --(20pin 0.1") Atmel SAM-ICE JTAG emulator to USB port with Atmel Studio 6.0.1966 running on Win XP latest.
The SAM3X has something like 5 hardware breakpoints on chip, and as from AS6.0 Build 1996 supports symbolic decoding, watching internal variables.
I used it on the USB Host code, Uhi_cdc.c: so haven't tested it on any .cpp yet.
The SAM-ICE JTAG is happier connected directly to a USB port. When it goes through a hub it would periodically get upset.
Even connected directly to a hub sometimes the segger JLINK.exe has an exception.

I have successfully configured the Arduino framework in Atmel Studio 6.0 and can execute programs on UNO and MEGA2560 using USB download.
BTW, I used the following tutorial: http://www.engblaze.com/tutorial-using-atmel-studio-6-with-arduino-projects/ and sourced working avrdude configuration parameters from: http://www.jayconsystems.com/tutorial/atmerpt1/

I have a similar setup as described above for DUE (except I'm using VMWare Fusion: Win XP SP3, Atmel Studio 6.0.1996, SAM-ICE, OLIMEX - ARM-JTAG-20-10).

I can use the Atmel Studio 6 predefined configuration for DUE and download/debug programs (not the Arduino framework) via the SAM-ICE. I used the program earlier in this thread for testing.

I then set up a standard GCC C++ Executable project for DUE using just the Arduino framework (using Arduino 1.5.2). Through trial and error I've managed to get the standard blink example to compile and link. However, on attempting to debug or download the programme via SAM-ICE, Atmel Studio launches a new tab that says "No Source Available" and does not execute the code. It does appear to be downloading. The Programme Counter value is 0x46204E16. I've spent significant time modifying things and searching for solutions with no success.

Neil12 - Would it be possible to provide access to a working Atmel Studio project to allow me to progress this? - I've hit a wall with this one!

Pete

I'll see what I can do. I haven't done much with Atmel DUE port since the post, though I did merge in the 1.5.2 update and it broke some of the hooks. I'd be happy to try and get something going - though might be a few days.
I'm very focused on the USB Host and also low power implementation, so there changes to the Arduino Due approach to support that.
I've also got a rain gauge - tipping bucket that I'm interfacing to an extension board that goes on the DUE + Ehternet board. This is using the Arduino Due framework.

Many thanks for your reply Neil. I will keep looking for obvious things that are wrong with my setup but any help is appreciated.

Well here is the reference on github.com
git@github.com:neilh10/at91sam3xaz01.git
It incorporates an Arduino compilable port for Atmel Studio 6.
I've ported through Arduino SAM release 1.5.2 (but not run it) but it doesn't incorporate all Arduino SAM libray files. I did download and run tests on a version that had release 1.5.1 - so not that different.
I've download the github zip file into a temporary directory, and in n AS6.0.1996 opened the project file sam3xApp01\sam3xApp01.atsln
and then build the solution.
It compiled and linked OK - but I haven't tested it by downloading it through the JTAG.
AS6.0.1996 is the lowest rev that supports JTAG/SAM-ICE through ATSAM3X JTAG.
It is "As Is" - a development snapshot for unit testing some of the hardware drivers.
See the "ReadMe-AboutThisBuild-SAM3XAZ.docx" - I intend to label any specific differences between my hw and this build as HWSAM3XAZA but not done yet.
Its also my first time through using github.com - and incredibly impressive as it is a fair number of files.
Last time I did such an impressive remote source control was in 2001 with a commerical system called "Continuus" that operated on a private network between two sites and that ended up supporting 50+ working programmers. The simplicity of GIT so far blows me away (though it took about 4 hours to get all of this uploaded). Thanks to all the people contributed to the gitHub online tutorials as well as the git cmd line utility and Git Gui and SSH to work.
Be interested in what you can share about the project you are working on. :slight_smile:

Neil, very many thanks for the time and effort to prepare and post this. Much appreciated.
BTW I'm supporting a number of Arduino development projects being undertaken my electronics students and attempting to get better debug facilities by utilising the SAM-ICE, but keeping the Arduino framework.

I built your project((in Version: 6.0.1996 - Service Pack 2) and got errors in adc.h (Part of the output is shown) - see below.
I can understand that some conditionally included definitions are not actually being included. Does the project build for you? Is there some definition that is missing? Have you had similar issues? I see that you have injected an error into this file previously to test a conditionally compiled macro definition...
clip from adc.c:
#if SAM3S_SERIES || SAM4S_SERIES || SAM3XA_SERIES
//error njh;
...

In file included from ../arduino/hardware/arduino/sam/system/libsam/chip.h:44:0,
from ../arduino/hardware/arduino/sam/cores/arduino/Arduino.h:34,
from ../arduino/hardware/arduino/sam/cores/arduino/cortex_handlers.c:19:
C:\at91sam3xaz01-master\sam3xApp01\arduino\hardware\arduino\sam\system\libsam\include\adc.h(170,48): 'enum adc_resolution_t' declared inside parameter list [enabled by default]
C:\at91sam3xaz01-master\sam3xApp01\arduino\hardware\arduino\sam\system\libsam\include\adc.h(170,48): its scope is only this definition or declaration, which is probably not what you want [enabled by default]

Error 8 use of enum 'adc_channel_num_t' without previous declaration C:\at91sam3xaz01-master\sam3xApp01\arduino\hardware\arduino\sam\system\libsam\include\adc.h 173 48 sam3xApp01
Error 9 use of enum 'adc_channel_num_t' without previous declaration C:\at91sam3xaz01-master\sam3xApp01\arduino\hardware\arduino\sam\system\libsam\include\adc.h 174 49 sam3xApp01
Error 10 use of enum 'adc_channel_num_t' without previous declaration C:\at91sam3xaz01-master\sam3xApp01\arduino\hardware\arduino\sam\system\libsam\include\adc.h 177 62 sam3xApp01
Error 11 use of enum 'adc_channel_num_t' without previous declaration C:\at91sam3xaz01-master\sam3xApp01\arduino\hardware\arduino\sam\system\libsam\include\adc.h 178 61 sam3xApp01
Error 7 use of enum 'adc_resolution_t' without previous declaration C:\at91sam3xaz01-master\sam3xApp01\arduino\hardware\arduino\sam\system\libsam\include\adc.h 170 48 sam3xApp01

Hmm yes I remember I got that problem as well and here is my correction -
The fix seems to be change AS6 to be the sames as the arduino-1.5.1r2 in
C:\Program Files\Atmel\Atmel Studio 6.0\extensions\Atmel\ARMGCC\3.3.1.128\ARMSupportFiles\Device\ATMEL\sam.h
/* Entire SAM3XA series */
#define SAM3XA_SERIES (SAM3X4 || SAM3X8 || SAM3A4 || SAM3A8)
from
#define SAM3XA_SERIES (SAM3A4 || SAM3A8)

I got it from
\My Documents\Arduino\arduino-1.5.1r2\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam.h
/* Entire SAM3XA series */
#define SAM3XA_SERIES ( SAM3X4 || SAM3X8 || SAM3A4 || SAM3A8)

Let me know if that works for you.

Background: The fix is in the AS6 toolchain so it makes me nervous.
I did send it through to Eric Weddington Jan 10th,2013 and though he responded, he didn't say if the fix I proposed was good.
I see from

that there is another release
Atmel Studio 6.1 beta (build 2440)
and 6.1 has an upgraded ARM Toolchain 4.7.2
from AS 6.0 ARM Toolchain 4.7.0.59 - GCC 4.7.0

Thanks again for all your help. Exactly right! I updated as suggested: #define SAM3XA_SERIES (SAM3X4 || SAM3X8 || SAM3A4 || SAM3A8)
The example builds, executes and is debuggable via SAM-ICE. I will now undertake some more testing.

BTW, I did try the Atmel Studio 6.1 beta (build 2440). I set up for ATSAM3X8E. I found that there appeared to be a problem when setting up the toolchain in Project Properties. Just by selecting the toolchain configuration to be "All Configurations" an application error was displayed: "Error occurred computing the All Configuration settings". I tried uninstalling, re-downloading and re-installing but the problem persisted. So, it seemed to be unusable. I wonder if anybody else has come across this? I then installed the earlier version: 6.0.1996 - Service Pack 2 that I am currently using.

Pete

Neil and Pete, you guys are awesome!
I was going through all the same problems. I had tried the two most recent releases of 6.1, neither of which worked. Not only was the recommendation for 6.0 excellent, but the sample project posted to github was a game changer. Thanks guys.
I'm now successfully getting my Due blinky test running while debugging with the SAM-ICE.

Hey glad it was useful. SAM3X has a lot of very nice opportunities with its internal ram and peripherals and low power.
Shame this fix hasn't made it in to the AS.
However it does seem the real productive programming is moving to anenvironment with python in it, and there is another productive OOPs paradigm that I've come across using www.squirrel-lang.org - one programsa 'nut' (ElectricImp.com is using it on WiFi SD card).
Neil

Hello,

I am working with custom SAM3X8C board using SAM-ICE to program it using Atmel STudio 6. i would like to know if there is a way to reset the microncontroller over SAM-ICE through Atmel Studio 6 with out programming it? I am trying to avoid unplugging the power to the board to do a reset.

Thanks.

For those interested in debugging Arduino Due and saving some money, I recommend to use an Atmel ICE that costs around $25 or a SWD CMSIS-DAP ($20) like the one from adafruit and shown in the following picture, instead of pay over $100 for a SAM-ICE. Of course, the mentioned cheap options have limited features but at least let you to perform debugging functions like stepping, breakpoints, watch points, and firmware downloads.

-p