Visual In-Circuit Debugging for Due in Eclipse on Mac OS X (for $13)
Topic: Visual In-Circuit Debugging for Due in Eclipse on Mac OS X (for $13)
(Read 408 times)
Visual In-Circuit Debugging for Due in Eclipse on Mac OS X (for $13)
Oct 12, 2014, 02:25 am
: Oct 13, 2014, 10:57 pm by gobftald
PART I of III
Step1/a download Arduino 1.5.2 BETA Mac OS X from
Step1/b unzip and copy the resulting Arduino(.app) into "Applications" folder
Step2 follow Jantje's instructions on
, or follow my method:
Step2/a download Eclipse Kepler 32 bit version from
(as Jantje suggests Kepler and 32 bit version is important)
Step2/b unarchive then copy the resulting "eclipse" folder into "Applications" folder
Step2/c launch Eclipse from /Applications/eclipse (waiting several seconds after previous copy operation it can be launched from Spotlight as well)
Step2/d "Select a workspace" (mine is /Users/xxxx/Documents/Arduino) and be sure that there are not an old eclipse workspace directory with the same name in that directory
Step2/e close "Welcome screen" then install "Arduino Eclipse Plugin V2.2" as follows:
Arduino Eclipse plugin
Step3 Jantje's Arduino Eclipse plugin can be installed based on his instructions (see step 2 above) or from "Eclipse Marketplaces" as well:
Step3/a click on "Help/Eclipse Market Places...", search for "arduino" in "Find:" field, then "Install" "Arduino Eclipse IDE V2" (press "Confirm", check "I accept...", press "Finish", OK for "Security Warning", Yes for "... restart ...")
Step3/b after Eclipse IDE restarting you should "integrate" Arduino plugin into Eclipse: click on "Eclipse/Preferences...", then chose "Arduino". On the left side the only missing parameter is where Eclipse can find Arduino. If you copied "Arduino" (in step 1) into "Applications" folder, you should give this information. Click "Browse" then navigate to "/Applications/Arduino(.app)". The warning at top of the panel disappears, the "Library" and "Hardware" path has already show into our Arduino workspace, so you can click OK.
Step3/c now you have a full function Arduino Eclipse development environment but "equipped" with only the classical (and stupid) Serial "debugging" println function.
Step3/d there is very useful information about Workspace preferences in
. It is almost mandatory for every Arduino Eclipse developer.
Step4 buy a cheap J-Link adapter like "USB-MiniJTAG J-Link JTAG/SWD" for USD $13 (
) or for USD $22 (eBay) or their famous original non-hacked version for 60 USD (
J-Link GDB server
Step5 for communication with this little adapters you need their GDB server program from SEGGER (
Step5/a for the latest version click the "Download" button on the "J-Link software & documentation pack for MAC" section
Step5/b install the downloaded "JLink_MacOSX_Vxxx.pkg": "Continue", "Continue", "Agree", "Continue", "Install", "Password", "Install Software", "Close")
5(c) It makes a SEGGER directory in "Applications", the GDB server in its "JLink" subdirectory, called "JLinkGDBServer"
Connecting J-Link adapter to Arduino Due
Step6 connecting J-Link adapter to Arduino Due is simple. The board has two debug connectors which have almost the same pins. A bigger one with 4 pins close to GND,13,12,11 pins with DEBUG label below it. It is the so called JTAG/SWD connector (JTAG means a debugging standard [
]. SWD means Serial Wire Debug, a 2-pin alternative of JTAG with only a clock [SWDCLK] and data line [SWDIO]. The other two pins are Reset, and GND pins.
There is also a smaller 10-pin Cortex connector, at the bottom left corner of the previous one, implementing full JTAG with TMS,TCK,TDO,TDI and Reset pins. Insisting to the USD $13 budget, and based on the fact that JTAG/SWD connector has most of these and all necessary pins for debugging, it is absolutely not necessary to buy, but it is worth to mention that there are "20-pin Standard to 10-pin Cortex Adapters for ARM JTAG Programmer" which can connect your J-Link adapters and this 10-pin debug connector of Arduino Due more elegantly (e.g.:
Good overview about these pins and connectors can be found in this forum as well on page
Step6/a my cheap solution based on a 4 wire strip/flat cable with 2.54 mm pin connectors (OK, it is an additional cost of USD 1$) and some clever cross-connections based on
but only to the 4-pin debug connector (
See the first picture below
Step6/b pin1 of JTAG/SWD (close to GND pin above) is Master-Reset which should be connected to pin 15 of the 20-pin connector of J-Link adapter (pin 1 of the 20-pin connector is marked with a tiny triangle, numbering can be learned from the drawing of the previous link).
Step6/c pin2 of JTAG/SWD (close to pin 13 above) is SWDIO, connected to pin 7 of J-Link adapter
Step6/d pin3 of JTAG/SWD (close to pin 12 above) is SDWCLK, connected to pin 9 of J-Link adapter
Step6/e pin4 of JTAG/SWD (close to pin 11 above) is GND, connected to any even numbered pin of J-Link adapter
See the second picture below
6(f) finally plug the USB connector of J-Link adapter into you Mac computer which detects and connects to it automatically and seamlessly.
Connecting J-Link GDB server to adapter
Step7 you can check your adapter and server connection by starting GDB server from command line: open a "Terminal" program either from "Applicaton/Utilities" or from "Spotlight", then launch the earlier installed SEGGER's JLinkGDBServer. Type the following command after the prompt of the Terminal program:
/Applications/SEGGER/JLink/JLinkGDBServer -if SWD
" option tells GDBServer to use SWD protocol instead of the default JTAG protocol. There are many information scrolling across the display: telling that "GDB Server Listening port number" is 2331; "J-Link Host Interface" is the earlier plugged USB; our adapter, the "Target interface" communicates via the specified SWD protocol; and if everything went well the final line of the Terminal shows "Waiting for GDB connection". Your GDB server is working and waiting for commands from a GDB client. GDB client will be launched, used, programmed and commanded by/from Eclipse performing our long waited "visual in-circuit" debugging functionalities.
Step7/a leave "Terminal" program with the waiting GDBServer alone and setup Eclipse debug functions:
Eclipse GDB Hardware Debugging plugin
Step8 Although Jantje's Arduino Eclipse plugin brings all C/C++ compiling, building and Arduino sketch uploading functions into Eclipse environment it lacks of the desired "visual in-circuit" debug functions. So you should install Eclipse GDB Hardware plugin:
Step8/a click on "Help/Install New Software", choose "Kepler - ..." in the "Work with:" field, choose "Mobile and Device Development", then select/check "C/C++ GDB Hardware Debugging" from the list.
Step8/b click "Next", then "Next" again, check "I accept ...", press "Finish", then "Yes" for "... restart ...".
145.4 KB, 425x319
viewed 3 times
158.38 KB, 425x318
viewed 3 times
Visual In-Circuit Debugging for Due in Eclipse on Mac OS X (for $13)
Oct 12, 2014, 02:36 am
: Oct 12, 2014, 09:43 pm by gobftald
PART II of III
Step9 There are other methods/plugins interfacing Eclipse with a J-Link adapter. I've tried many of them, especially the most promising J-Link and OpenOCD plugins (their installation and setup is described on page
. In that J-Link plugin "GDBServer" can be launched from Eclipse, therefore it's not necessary to run it in a separate "Terminal" window. There are other "promising" parameters in J-Link plugin, like "Enable semihosting" or "Enable SWO". This latter one is necessary for the famous "Trace functions", but needs an additional SWO pin from the 10-pin Cortex JTAG Adapter. But the working of this J-Link plugin was not stable. Many times it halted, and the only solution was to pluging out/in the USB of adapter. Although I'm going to experiment further, finally I made this blog/tutorial about the most simple but stable setup procedure.
Make a program
Step10/a make a new Arduino sketch: click on "Arduino/New Sketch", then give a "Project name:", "Next", select "/Applications/Arduino.app/Contents/Resources/Java/harware/arduino/sam/boards.txt", then select "Arduino Due (Programming Port)", then select "Port" something similar to "tty.usbmodemxxxxx" (in my case it was "/dev/tty.usbmodemfa131"), then click on the "Finish" button.
Step10/b design, write, verify (compile, and build) your code/sketch. It is not necessary to upload it to the Arduino Due board. It will be uploaded via the J-Link adapter and JTAG/SWE connector. If Arduino Due board can get power from other source, connection to Programming USB would not even be necessary.
Step10/c it is important to verify/build your (first) code before starting Debug Configuration in the next step, since my limited Eclipse knowledge was not able to setup a general "Debugging Environment" for all of your future Arduino projects. But I was happy to set it up for the current project then it can be transferred for the future ones. The transferring method in Step11/h.
Eclipse Debugger configuration
Step11 click on "Run/Debug Configurations...", then double click on "GDB Hardware Debugging".
Step11/a on the left side give a name (e.g. GDB HW) for the Configuration.
Step11/b in the "C/C++ Application:" field you should see the following: "Release/[your project name].elf. if not, type it in.
Step11/c in the "Project:" field you should see only [you project name]. If not, type it in.
Step11/c on the second "Debugger" tab you should setup our GDB client mentioned earlier. It is the program which will be called by Eclipse and via this program Eclipse can send command (e.g. setting a breakpoint) to the waiting GDB server (who send them to the J-Link adapter, who send them to "Atmel SAM3X8e MCU" of Arduino Due. When there is a response from Arduino Due MCU they will come back on the same "channel-chain".
Step11/d you can get and setup a GDB client from your Arduino IDE. It is there, but deep in Arduino.app (in OS X every .app is a directory). So click on the "Browse" button then navigate to
. There is a tiny trick: when you click on "Applications" then "Arduino" you cannot step into Arduino directory. But putting a trailing "/" after "/Applications/Arduino/" then click on "Browser" again, you can navigate further. Alternatively you can copy and paste
text into the "GDB Command" field.
Step11/e then set up the "Remote Target", the J-Link adapter, or more precisely its "J-Link Gdb server" front-end program. Leave "JTAG Device" on "Generic TCP/IP", and the "Hostname" on localhost (GDB servers and clients can be on different machines, communicating via TCP/IP, but in our case they are on the same one, on the "local host"). Then set up "Port number:" to the familiar "2331". It is the port from where GDB Server is waiting for the incoming connections. Click "Apply" then go to the next tab.
Step11/f there are some necessary "Initialisation Commands" which I "borrow" also from the Arduino IDE. There is a file in
. It defines a GDB "reset" command, but its subcommands contains those magic initialisation commands for GDB client (and some of them refers and send to GDB server as well). So either you check that file and copy those commands from it or copy and paste them into the "Initialisation Commands" area from here:
monitor flash device = AT91SAM3X8E
monitor flash download = 1
and there are some for copying into the "Run Commands" area below, also from the same .gdb file:
mon reg sp=(0x80000)
mon reg pc=(0x80004)
You can set up the first breakpoint at "Set breakpoint at" checkbox, given one of your function names into the empty field (e.g. main, setup, loop, or any of you own). It can be left empty, and after starting the debug session you can set breakpoints in the source code itself.
Finally you should click on "Apply" button
Step11/g for the time being there is nothing to setup in the "Source" tab, but later it is where you can define the source code files for unknown code segments
Re: Visual In-Circuit Debugging for Due in Eclipse on Mac OS X (for $13)
Oct 12, 2014, 09:02 pm
: Oct 12, 2014, 09:46 pm by gobftald
PART III of III
Step11/h there are important settings in "Common" tab. Click on "Shared file". You should see "/[your project name]. If not, type it in or navigate to it by the "Browser" button. If you click on "Apply" this "Debug Configuration" will be saved in your project tree by the name in the "Name:" field at the top.
In order to transfer and personalise this previously saved "Debug Configuration" for any other -- for example new -- projects, you should follow the following steps:
-- the project which currently contains the saved "Debug Configuaration" file should be opened
-- click on "Run/Debug Configurations...", then modify the following three fields with the name of the project which you want to debug:
-- on the "Main" tab, in the "C/C++ Application:" field replace the [project name] between "Release/" and ".elf" strings
-- in the ""Project:" field replace the [project name], then press "Apply"
-- on the "Common" tab, in the "Shared file:" field replace the [project name] or with the "Browse" button navigate to your [project name], then press "Apply"
You can see in the "C/C++" Perspective that the "Debug Configuration" file is saved/transfered into the new project. From that time it can be used from there.
Please be aware that breakpoints are saved into "Debug Configuration", so when this file transferred and used in other projects there can be funny breakpoints from earlier debug sessions. It is not a problem either you maintain or delete them.
I'm absolutely sure that there should be a much clever solution for this migration or using a common Configuration. I have been playing a lot with "project variables" like "resource_path", "project_name", etc, but was not able to find a better solution. Eclipse gurus wanted.
Visual in-circuit debugging
Step12 You are ready. If "Debug Configuration" windows is open yet, you can launch the debug session pressing the "Debug" button at the bottom right, or pressing the "green bug" menu icon later in the "Debug" Perspective. The sketch will be uploaded to the Arduino Due board via J-Link adapter, then execution is started. If not there yet, "Debug" Perspective appears on Eclipse window. It contains a "Debug" window, showing program call threads; another window containing "Variables" and "Breakpoints" tabs; a "Source code" window containing the opened source code tabs, showing breakpoints and the program pointer. Another window contains "Outline" and "Disassembler" tabs (if latter don't appears it can be opened with "Window/Show View/Disassembly") showing the same information in a mixed source and assembly view. Finally the bottom window contains the usual status tabs like "Console".
See the third picture below
Although I'm a beginner in Eclipse environment. here are some of my very early experiences using this new debug feature. I hope there is much skilled developers around here who can extend this description about Eclipse's other debugging features and settings.
Step12/a at the beginning generally the program pointer goes to the Reset_Handler(). Don't worry, press the "green arrow" Resume (F8) and program pointer will run until your first breakpoint.
Step12/b double click on a line in the source or assembly view put a breakpoint into the code, appearing in the Breakpoints tab as well
Step12/c you can navigate across the code with "Resume (F8)", "Suspend", "Step Into (F5)", "Step Over (F6)", "Step Return (F7)". If you toggle "Instruction Setting Mode" these "Step" commands refer to assembler instructions.
Step12/d you can switch between the "C/C++" and "Debug" Perspectives in the top right corner. But be careful and don't click on the "green bug" to start a new debug session in the "C/C++" Perspective. If you did and a dialog appears "Cancel" it. You can start debug session from "C/C++" Perspectives if you click on the list arrow of that "green bug", then choose the "Debug Configuration" at top of the menu. In "Debug" Perspectives you can start debugging with pressing the "green bug". In both Perspectives you can start debugging if you click "Debug" button in the familiar "Run/Debug Configurations..." dialog.
Step12/e after every debugging session it is useful to "Terminate" the program with the "red square" "Terminate" button, then close the "Call threads" and "Consoles" by clicking on its the "double X" buttons. Otherwise there can be too many "call threads" in the "Debug" window.
Step12/f if something does not work it is worth to check the GDB server in the "Terminal" program and restart it if it is dead or exited.
88.49 KB, 1436x818
viewed 6 times