Monday 31 March 2014

Setting up Eclipse for Arduino Due to allow for compilation and upload of RepRap Firmware on the Duet

UPDATE: Have a look at the comments below- Jantje, the author of the Arduino plugin for eclipse has posted some updated advice, the key piece being:
First of all I advice "people not using eclipse already" to use the Product version. This is one install that includes eclipse and the plugin. You can find a download link for your os here: I advise to us the latest version. Mac users must install the latest version due to a change in arduino folder policy on mac.
This is a guide to installing and configuring the Eclipse environment on Windows in order to modify and compile the RepRap Firmware for Duet electronics. It may be generally useful for getting Eclipse to play nicely with the Arduino Due board as well.

Note that many printer settings can be changed in g-code within the RepRap firmware and you may not need to edit and compile a new firmware binary to run the RepRap firmware on your printer.

This guide draws from a number of sources: Adrian's initial guide, 3D-ES's post on the RepRap forum and personal experience. I would really appreciate comments and feedback on how this works on other versions of Windows. If anyone is able to do a similar guide for Mac/Linux that would be greatly appreciated.


32 Bit. Throughout this guide I have stuck with using the 32bit version of Eclipse. This should work in more situations than the 64 bit version however let me know if you are successful with the 64 bit versions.

Paths. To keep it simple I have used C:\arduino, C:\eclipse and C:\workspace\RepRapFirmware as directory paths in this example - other paths should work but ensure you substitute the new paths in the instructions below.

Install Arduino: download 1.5.6-rc2, Extract and move to C:\arduino

Install Eclipse: download Juno C/C++ SR2. Extract and move into C:\eclipse

Create workspace: make directories:  C:\workspace,  C:\workspace\RepRapFirmware and C:\workspace\RepRapFirmware\Libraries

Run Eclipse: C:\eclipse\eclipse.exe. When prompted for the workspace enter C:\workspace and choose not to be prompted again. Close the welcome help window.

Install the Arduino Eclipse plugin: Select the Help Menu, Install new software. Paste in the "work with" field and click "Add". It will prompt you to name the repository, use "Arduino Plugin". Uncheck "Group items by category" checkbox then select "Arduino eclipse extensions" item. Click through Next a few times then accept the agreement and finish. Yes to unsigned content, then restart Eclipse.

Setup the Arduino Eclipse plugin:  Select Window menu, "Preferences",  "General",  "Workspace" Check "Save automatically before build". Then click "Arduino" and enter C:\arduino  in the Arduino IDE path and C:\workspace\RepRapFirmware\Libraries in the Arduino Library path. Apply the changes.

Note the "bossac" port number: With your Duet board plugged into USB (but not 12V) press the "erase" button (next to the ethernet port), then the reset button (next to the USB port). If you have not done this before on your PC it may start to install the driver for the native USB port. One this is done go to Control Panel, Devices and Printers and you will see the native USB port. For some reason Windows thinks this is a GPS camera for me:

This shows the port as COM8, note this for the next step

Setup the RepRap Firmware project: Select Arduino menu, "New Sketch". Set the project name to "RepRapFirmware". go next then select C:\arduino\hardware\arduino\sam\boards.txt and select Arduino Due (Native USB Port) as the board.
             NOTE the Arduino Due (Programming Port) will not work with the Duet. 
Set the port to "COM8" or whatever you found in the previous step.
Exit Eclipse

Get the RepRap Firmware source:  Get the version of RepRapFirmware you want to work with. Good options are:

The choice depends on what you are using the firmware for, and you can change to a different branch later. Whichever version you choose, click "Download ZIP" button on the right side of the page and copy the contents of the zip file into  C:\workspace\RepRapFirmware
Only overwrite "RepRapFirmware.cpp" and "RepRapFirmware.h" do not overwrite the other files.

Copy the Libraries: Download the Libraries (click download zip on the right hand side). Copy the sub directories of "Arduino-libraries-master" into the C:\workspace\RepRapFirmware\Libraries\
directory. Next copy C:\arduino\hardware\arduino\sam\libraries\Wire
to C:\workspace\RepRapFirmware\Libraries\

Setup the Paths: Open eclipse, in the Project Explorer window on the left click on the "RepRapFirmware" project and select refresh. All the source files should now appear in the project explorer tree. Next right click on the RepRapFirmware project again and select properties. Navigate to C/C++ General, Paths and Symbols:

the core and variant entries will already be there, add the rest making sure you select "Is a workspace path" and "Add to all languages":

Except the "C:\arduino\hardware\arduino\sam\system\libsam\include" path which needs to be added as a filesystem path:

Note If using the Dc42 version on the firmware you must add the "flash" directory as well:

Once they are all added click apply, choose to rebuild the index and select OK to close the window.

Eclipse is now setup and ready to compile the firmware.

Compiling RepRap Firmware: The compilation output is visible on the console tab selected at the bottom center. Choose the Project menu, clean, clean all, OK. Then click on the green tick to "Verify", ie compile the code.

The progress of the compilation will show in the console window and when complete there will output something like this:

Uploading the Firmware: With the Duet plugged into USB if you have not erased the loaded firmware click the erase button, then the reset button on the Duet. Then click the green arrow on the toolbar "Upload Sketch". The upload will start, shoose "always run in background". In the console windown the upload progress and then the verify progress will be shown:

The compiles firmware is now uploaded to the Duet board. Note if you look in devices and printers the port will have changed to the Arduino Due port:

With a different com port, this is the one you use in Pronterface to talk to the firmware over USB.

Firmware Modification

Detailed information modifying the firmware is outside the scope of this blog post. Printer configuration defaults are in Platform.h:

The screenshot above shows part of the platform.h for the Multi Extruder branch which defines all 8 channels for the Duet and Duex4.

I hope this post has been useful!