Friday 26 February 2016

How to compile RepRapFirmware-dc42 for Duet on Mac OS X

(Guest post by Michael Hackney, SublimeLayers.blogspot.com and www.EclecticAngler.com)

As RepRapFirmware gains momentum, more users will want to contribute to its development. There are some good resources for setting up a development environment for Windows computers but very few resources for developing on Mac OS X. I tried for several months to setup my environment and wasn't able to, so I pushed forward and started with a clean slate and documented every step along the way.  Now that it's done, I can install the development environment from scratch in about 15 minutes.

As I discovered, one of the more significant challenges I confronted was the interdependence of specific versions of the various tools and even the operating system. I worked through each of these with the goal of using the most up-to-date version for each component possible, starting with the operating system. Please pay particular attention to these versions as you work through the setup process - they are highlighted in bold. I highly recommend starting with the specific versions I used and once you have your environment running, update components one at a time if necessary. And if you do that successfully, please leave a comment here so others can benefit.

The reference date for this process is 2/14/2016.

Start with your Macintosh updated to Mac OS X: El Capitan 10.11.3 I have not attempted this on earlier versions of OS X so if you are successful, please leave a comment. I'll also leave comments when new versions of OS X come out.

1) Get the tools and setup the basic environment

The first step is to download the development tools. This development environment is based on the Open Source Eclipse IDE. However, a special plug-in to integrate the Arduino tools is required. Putting together this environment was a big challenge but now there is a pre-built Arduino Eclipse  IDE that eliminates the grunge work. A big thanks goes out to Jantje for this work!
Create a folder to use for the root of everything. Please note, once you start this process you can not change the path later. Eclipse is very finicky about installation path so pick something you can live with. Also, DO NOT include spaces in the pathname. NONE!  I created a folder named "Development" on my desktop and will use that for this document. My path looks like:

/Users/mhackney/Desktop/Development

Now copy the Eclipse tar file and Arduino file into Development and unpackage them (on OS X you can simply double-click the tar file to untar it). You can delete the tar file once you've unpackaged it.

Next, open the Arduino.app package (by control-clicking it's icon) and navigate to /Contents/Resources/Java
  • Copy the /libraries and /hardware folders into your Development folder.
At this point, your Development folder should look like:
  • Create a folder named workspace inside the eclipseArduino folder.
2) Configuring Eclipse

Now you can launch he Eclipse application - called eclipseArduinoIDE in the eclipseArduino folder. When Eclipse asks you for the workspace, click [Browse...] and navigate to your Development/eclipseArduino/workspace folder and click the [Open] button. Check the "Use this as default" box and click [OK].

Click the EclipseArduinoIDE menu and choose "Preferences..." then select the Arduino tab in the list on the left. 
  • Set the "Arduino IDE path" to your Arduino.app
  • Set the "Private Library path" to the library folder you copied to your Development folder
  • Set the "Private Hardware path" to the hardware folder you copied to your Development folder
  • Click Apply then [OK] (choose [OK] for the dialogs that tell you Arduino is newer than the plugin)
Here's what the dialog should look like (with your Development path substituted of course) when you are done:


Next, click the Arduino menu and select New Sketch. Set the project name to RepRapFirmware and then make sure sam/boards.txt is selected. Select Arduino Due (Native USB Port) for board. You can set the COM port now also but if you don't know it, it can be set later.

Quit Eclipse.

3) Setup the RepRapFirmware

Download the latest version of dc42 dev branch of RepRapFirmware: https://github.com/dc42/RepRapFirmware (Click the [Download ZIP] button at the upper right). At this writing version 1.09r-dc4 is the latest). Copy all of the files to the RepRapFirmware folder in your workspace folder.

Copy the patched libraries out of RepRapFirmware/ArduinoCorePatches into the Arduiuno.app package. The path is Arduino.app/Contents/Resources/Java/hardware/arduino/sam. Use the "Merge" option and "Apply to All" when the copy dialog asks what to do. Remove the ArduinoCorePatches folder from the RepRapFirmware folder (you can delete it).

Launch EclipseArduinoIDE and setup the project like this:
  • Remove the RepRapFirmware.ino file from the RepRapFirmware Project list on the left - this will delete it from the filesystem too.
  • Select the RepRapFirmware project in the Project Explorer and control-click and select Refresh. All of the source files should appear in the list.
  • Select the RepRapFirmware project in the Project Explorer and control-click and select Index->Rebuild. 
Select the RepRapFirmware project in the Project Explorer and control-click and select Properties... at the bottom of the menu.
    • Find the C/C++ General/Paths and Symbols page. Now you need to add each of the library folders in the workspace/RepRapFirmware/Libraries folder to the GNU C list. Do this by clicking the [Add...] button. Then check the Add to all languages box and click the [File system...] button to navigate to the workspace/RepRapFirmware/Libraries/EMAC (the first folder library to add). Do this for each of the folders in the Libraries folder. It's a little tedious but gets the job done. 
    • You also have to explicitly add SD_HSMC/utility the same way.
    • You also have to add hardware/arduino/sam/system/libsam/include (this is the hardware folder you copied to your Development folder)
    • Then click [Apply] and click [Yes] to rebuild the indexes.
    When you are finished, your list should look like this:
    • Next click the C/C++ Build/Environment tab on the left list. 
      • Set JANTE.EXTRA.C.COMPILE to -std=gnu99 
      • Set JANTJE.EXTRA.CPP.COMPILE to -std=gnu++11
      • Find the A.BUILD.USB FLAGS variable and remove the manufacturer and product part - it looks like this: 
        • '-DUSB_MANUFACTURER=${A.BUILD.USB_MANUFACTURER}' '-DUSB_PRODUCT=${A.BUILD.USB_PRODUCT}'
      • Now find all occurances of the compiler flag "-Os" and change them to "-O2". This is in:
        • A.COMPILER.C.ELF.FLAGS
        • A.COMPILER.C.FLAGS
        • A.COMPILER.CPP.FLAGS
      • Remove the '-w' option in A.COMPILER.C.FLAGS and A.COMPILER.CPP.FLAGS
      • Click the [Apply] button and click [OK] to exit the dialog
    That's It!

    It might seem a little tedious but you'll be rewarded with a RepRapFirmware development environment when you are done. I've successfully installed on four different Mac computers.

    If you have any questions, comments or additions please post a comment.












    No comments:

    Post a Comment

    Comments are now moderated to reduce spam, please excuse the additional time this will entail.

    Note: only a member of this blog may post a comment.