<?xml version="1.0"?><rss version="2.0">
<channel>
  <title>Alan&#039;s Ramblings - avr-gcc tag</title>
  <link>http://bleaklow.com:80/tags/avr-gcc/</link>
  <description>My opinions may be incorrect, but they are my own</description>
  <language>en</language>
  <copyright>Alan Burlison</copyright>
  <lastBuildDate>Wed, 23 Nov 2011 16:42:03 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  <image>
    <url>http://bleaklow.com/images/misc/logo.gif</url>
    <title>Alan&#039;s Ramblings</title>
    <link>http://bleaklow.com:80/</link>
  </image>
  <item>
    <title>Updated Makefile.master</title>
    <link>http://bleaklow.com:80/2011/01/23/updated_makefile_master.html</link>
    <description>
          &lt;p&gt;
If you have been using my &lt;a href=&#034;/2010/06/04/a_makefile_for_arduino_sketches.html&#034;&gt;Makefile for Arduino sketches&lt;/a&gt; I&#039;ve been updating it regularly with bug fixes and improvements.  The latest version includes:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Arduino &lt;code&gt;bin&lt;/code&gt; directory, avrdude config file and avrdude path made configurable.&lt;/li&gt;
&lt;li&gt;Single-file sketches weren&#039;t building properly.&lt;/li&gt;
&lt;li&gt;Listing file now generated for the final binary image.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
You can find the current version of the Makefile.master &lt;a href=&#034;/files/2010/Makefile.master&#034;&gt;here&lt;/a&gt;.
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/01/23/updated_makefile_master.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/01/23/updated_makefile_master.html</guid>
    <pubDate>Sun, 23 Jan 2011 12:22:56 GMT</pubDate>
  </item>
  <item>
    <title>Updated Makefile.master</title>
    <link>http://bleaklow.com:80/2010/09/12/updated_makefile_master.html</link>
    <description>
          &lt;p&gt;
If you have been using my &lt;a href=&#034;/2010/06/04/a_makefile_for_arduino_sketches.html&#034;&gt;Makefile for Arduino sketches&lt;/a&gt; I&#039;ve been updating it regularly with bug fixes and improvements, the latest being automated header file dependency checking.  You can find the current version of the Makefile.master &lt;a href=&#034;/files/2010/Makefile.master&#034;&gt;here&lt;/a&gt;.
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2010/09/12/updated_makefile_master.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2010/09/12/updated_makefile_master.html</guid>
    <pubDate>Sun, 12 Sep 2010 20:39:00 GMT</pubDate>
  </item>
  <item>
    <title>Configuring NetBeans to use as an Arduino IDE</title>
    <link>http://bleaklow.com:80/2010/06/22/configuring_netbeans_to_use_as_an_arduino_ide.html</link>
    <description>
          As I&#039;ve said in an earlier post, I very quickly found the &lt;a href=&#034;http://www.arduino.cc/en/Guide/Environment&#034;&gt;Arduino IDE&lt;/a&gt; to be way too primitive for serious use, so I decided to switch to using &lt;a href=&#034;http://netbeans.org/&#034;&gt;NetBeans&lt;/a&gt; as an alternative.  First step was to create a &lt;a href=&#034;2010/06/04/a_makefile_for_arduino_sketches.html&#034;&gt;Makefile&lt;/a&gt;, once I had that done I needed to configure NetBeans to use the avg-gcc toolchain, which was pretty straightforward.  Ideally I&#039;d just be able export the relevant settings from NetBeans and provide a file you could download and install, but unfortunately NetBeans doesn&#039;t provide a way to do this for individual compilers, just all of them at once :-(
&lt;/p&gt;
&lt;p&gt;
First step is to set up a new compiler configuration, &lt;code&gt;Tools -&amp;gt; Options -&amp;gt; C/C++ -&amp;gt; Add&lt;/code&gt;.  Set the base directory to wherever you have avr-gcc installed, in my case this is under &lt;code&gt;/opt/arduino/hardware/tools/gcc-avr/avr/bin&lt;/code&gt;.  Set the compiler family to &lt;code&gt;GNU&lt;/code&gt; and save.
&lt;/p&gt;
&lt;a href=&#034;/images/2010/nb_setup_1.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_1.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_1.png&#034; alt=&#034;step 1&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&lt;p&gt;
Then in the &lt;code&gt;Build Tools&lt;/code&gt; tab, set the paths for the C compiler, the C++ compiler and for the assembler, i.e. the full paths to the AVR versions of &lt;code&gt;gcc&lt;/code&gt;, &lt;code&gt;c++&lt;/code&gt; and &lt;code&gt;as&lt;/code&gt;.  Also set the path for &lt;code&gt;gmake&lt;/code&gt;.  Clicking on the &lt;code&gt;Versions&lt;/code&gt; button should display the versions of the tools.
&lt;/p&gt;
&lt;a href=&#034;/images/2010/nb_setup_2.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_2.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_2.png&#034; alt=&#034;step 2&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&lt;p&gt;
Switch to the &lt;code&gt;Code Assistance&lt;/code&gt; tab, and for both the C and C++ compilers, click the &lt;code&gt;Reset Settings&lt;/code&gt; button.  This should fill in the default values, the include directories should be set to locations under your avr-gcc install tree.  You also need to manually add the directory containing the source of the Arduino libraries to each compiler configuration, in my case this is &lt;code&gt;/opt/arduino/hardware/cores/arduino&lt;/code&gt;, and them move it to the top of the include lists.
&lt;/p&gt;
&lt;a href=&#034;/images/2010/nb_setup_3.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_3.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_3.png&#034; alt=&#034;step 3&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;a href=&#034;/images/2010/nb_setup_4.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_4.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_4.png&#034; alt=&#034;step 4&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&lt;p&gt;
Finally, switch to the &lt;code&gt;Other&lt;/code&gt; tab, and add &lt;code&gt;pde&lt;/code&gt; to the list of C++ file extensions, and save.  That&#039;s the tools set up.
&lt;/p&gt;
&lt;a href=&#034;/images/2010/nb_setup_5.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_5.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_5.png&#034; alt=&#034;step 5&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&lt;p&gt;
The next steps apply when you are creating a new project and defining its properties.  Obviously you need to choose the avr-gcc toolchain to compile the project, and provide a &lt;a href=&#034;2010/06/04/a_makefile_for_arduino_sketches.html&#034;&gt;Makefile&lt;/a&gt; to build it with - don&#039;t use the standard NetBeans one, it won&#039;t work.
&lt;/p&gt;
&lt;p&gt;
The &lt;code&gt;Code Assistance&lt;/code&gt; sections for both the C and C++ compilers need setting up to refer to any additional library directories you are using, and if you want code completion to work properly you also need to define the requisite preprocessor macros.  Do this by setting up a new Configuration for each board type you use, and within that define the macros.  I have duemilanove and mega boards, so my settings are:
&lt;/p&gt;
&lt;h4&gt;duemilanove&lt;/h4&gt;
&lt;pre&gt;__AVR_ATmega328P__
F_CPU=16000000L
&lt;/pre&gt;
&lt;h4&gt;mega&lt;/h4&gt;
&lt;pre&gt;__AVR_ATmega1280__
F_CPU=16000000L
&lt;/pre&gt;
&lt;a href=&#034;/images/2010/nb_setup_6.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_6.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_6.png&#034; alt=&#034;step 6&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&lt;p&gt;
If you have different boards you&#039;ll have to figure out the correct &lt;code&gt;__AVR_ATXXX__&lt;/code&gt; and &lt;code&gt;F_CPU&lt;/code&gt; #defines.  First find &lt;code&gt;boards.txt&lt;/code&gt; in your Arduino install tree and find the section for your board.  The &lt;code&gt;f_cpu&lt;/code&gt; value is what you need for &lt;code&gt;F_CPU&lt;/code&gt;, the other setting is a little more fiddly to find.  Get the &lt;code&gt;mcu&lt;/code&gt; value, then look that up in the second table on &lt;a href=&#034;http://www.nongnu.org/avr-libc/user-manual/using__tools.html&#034;&gt;this page&lt;/a&gt; to find the corresponding macro that needs to be defined.
&lt;/p&gt;
&lt;p&gt;
As the generated code needs to be run on the Arduino, the normal &lt;code&gt;Run&lt;/code&gt; settings don&#039;t actually make much sense, but we can re-purpose them for our needs.  In the &lt;code&gt;Make&lt;/code&gt; section, set the &lt;code&gt;Build Result&lt;/code&gt; value to the path of your gmake executable, then in the &lt;code&gt;Run&lt;/code&gt; section, set the command-line argument to &lt;code&gt;upload&lt;/code&gt;.  By doing this, when you run the project with F6, NetBeans will run the &lt;code&gt;upload&lt;/code&gt; Makefile target which will build the project and upload it to the board.  If you want to build, upload and run the serial monitor, set the argument to &lt;code&gt;upload_monitor&lt;/code&gt; instead,.
&lt;/p&gt;
&lt;a href=&#034;/images/2010/nb_setup_7.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_7.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_7.png&#034; alt=&#034;step 7&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;a href=&#034;/images/2010/nb_setup_8.png&#034; onclick=&#034;window.open(&#039;/images/2010/nb_setup_8.png&#039;,&#039;popup&#039;,&#039;width=660,height=660,toolbar=no,directories=no,location=no,menubar=no,status=no&#039;); return false&#034; class=&#034;thumbnailLink&#034;&gt;&lt;img src=&#034;/images/2010/thumbnails/nb_setup_8.png&#034; alt=&#034;step 8&#034; class=&#034;thumbnailImage&#034;/&gt;&lt;/a&gt;
&lt;p&gt;
With all that in place you should be able to use NetBeans as your IDE for developing for the Arduino, including all the nice features such as cross-referencing and code completion.  The setup of projects is a little fiddly, so my suggestion is to set up an empty template project that you can copy and then change all the project name references in - I use &lt;code&gt;TEMPLATE&lt;/code&gt; as the project name so I can use a little script to clone the project then rename and batch-edit the files with the correct project name.
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2010/06/22/configuring_netbeans_to_use_as_an_arduino_ide.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2010/06/22/configuring_netbeans_to_use_as_an_arduino_ide.html</guid>
    <pubDate>Tue, 22 Jun 2010 19:09:00 GMT</pubDate>
  </item>
  <item>
    <title>A Makefile for Arduino Sketches</title>
    <link>http://bleaklow.com:80/2010/06/04/a_makefile_for_arduino_sketches.html</link>
    <description>
          When I started tinkering with &lt;a href=&#034;http://arduino.cc&#034;&gt;Arduinos&lt;/a&gt; I started out with the standard &lt;a href=&#034;http://arduino.cc/en/uploads/Guide/Arduino0018Blink.png&#034;&gt;Arduino IDE&lt;/a&gt;.  It&#039;s great for &lt;a href=&#034;http://arduino.cc/en/Guide/Environment&#034;&gt;getting started quickly&lt;/a&gt; but for more complex work, such as those involving libraries shared between Sketches, it quickly becomes limiting.  What I wanted was to continue using the standard Arduino &lt;a href=&#034;http://arduino.cc/en/Reference/Extended&#034;&gt;libraries&lt;/a&gt; but to switch to a more capable IDE.  I already use &lt;a href=&#034;http://netbeans.org/&#034;&gt;NetBeans&lt;/a&gt; so I wanted to try to use that if possible.  The first step was to come up with a way of building Arduino Sketches from outside the Arduino IDE.  The Arduino distribution includes a number of old, deprecated Makefiles, but nothing that was really usable.  I therefore set to and wrote my own.  I&#039;ve followed the standard layout we use at work, with a &#039;master&#039; Makefile that contains most of the logic, which is then included into a per-project Makefile that sets up the required configuration for the rules in the master Makefile.  It is available &lt;a href=&#034;http://bleaklow.com/files/2010/Makefile.master&#034;&gt;here&lt;/a&gt;.  An example project Makefile looks like this:
&lt;/p&gt;
&lt;pre&gt;BOARD = atmega328
PORT = /dev/term/0
LIB_DIRS = ../Common/Task ../Common/VirtualWire
include ../Makefile.master
&lt;/pre&gt;
&lt;p&gt;
Some notes about how to use the Makefile:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;
At the moment the Makefile is pretty Solaris-specific, because I haven&#039;t had the time to get it all going under a Linux VM, although the required changes are simple.  Patches are welcome :-)
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
You&#039;ll need the standard Arduino environment installed first, either version 0018 or 0019.
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
You must use &lt;a href=&#034;http://www.gnu.org/software/make/&#034;&gt;gmake&lt;/a&gt; as your make implementation - not usually a problem as it comes included in the Arduino environment.
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
The valid values for &lt;code&gt;BOARD&lt;/code&gt; are those found in the standard &lt;a href=&#034;http://code.google.com/p/arduino/source/browse/trunk/hardware/arduino/boards.txt&#034;&gt;boards.txt&lt;/a&gt; file, that file is parsed to extract the relevant values for the Makefile.  &lt;code&gt;PORT&lt;/code&gt; is the path of the USB port that the Arduino is attached to.  &lt;code&gt;LIB_DIRS&lt;/code&gt; is a list of directories containing any libraries that you want to use.
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
The following targets are provided in the Makefile:
&lt;br&gt;&lt;br&gt;
&lt;ul&gt;
  &lt;li&gt;
  &lt;strong&gt;all&lt;/strong&gt; - build everything (default).
  &lt;/li&gt;
  &lt;li&gt;
  &lt;strong&gt;clean&lt;/strong&gt; - remove all generated files.
  &lt;/li&gt;
  &lt;li&gt;
  &lt;strong&gt;upload&lt;/strong&gt; - build everything and upload to the board.
  &lt;/li&gt;
  &lt;li&gt;
  &lt;strong&gt;monitor&lt;/strong&gt; - run the serial monitor.
  &lt;/li&gt;
  &lt;li&gt;
  &lt;strong&gt;upload_monitor&lt;/strong&gt; - build everything, upload to the board and run the serial monitor.
  &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
You don&#039;t need to explicitly list the various &lt;code&gt;.c&lt;/code&gt;, &lt;code&gt;.cpp&lt;/code&gt; and &lt;code&gt;.pde&lt;/code&gt; files that make up your application, the makefile assumes that any such files it finds in the various source directories are all to be compiled.
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
The processing of the Sketch (.pde) files is very simplistic, much more so than the processing done by the Arduino IDE.  There&#039;s talk on the Arduino development list of splitting the Sketch-to-C++ processing out into a separate library so it can be reused, but it hasn&#039;t happened yet.  I&#039;ve actually stopped using .pde files and now just write my own &lt;code&gt;main.cpp&lt;/code&gt;, it&#039;s &lt;a href=&#034;http://code.google.com/p/arduino/source/browse/trunk/hardware/arduino/cores/arduino/main.cpp&#034;&gt;simple enough&lt;/a&gt; not to be any sort of an inconvenience to do so.
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
The output is all created in the &lt;code&gt;build&lt;/code&gt; subdirectory of the Sketch&#039;s directory.  That means it doesn&#039;t interfere with anything if you still want to be able to use the standard Arduino environment.
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
Unlike the Arduino IDE which rebuilds everything every time, the Makefile only builds files that have changed.  One caveat: if you change the board type in the Makefile, be sure to run &lt;code&gt;make clean; make&lt;/code&gt; afterwards to rebuild everything correctly.
&lt;/li&gt;
&lt;br&gt;
&lt;li&gt;
The Makefile builds three archive libraries in the &lt;code&gt;build&lt;/code&gt; directory:
&lt;br&gt;&lt;br&gt;
&lt;ul&gt;
  &lt;li&gt;
  libarduino.a - this contains the object code of the standard Arduino run-time libraries.
  &lt;/li&gt;
  &lt;li&gt;
  liblibrary.a - this contains the object code of any libraries you specified in the &lt;code&gt;LIB_DIRS&lt;/code&gt; Makefile variable.
  &lt;/li&gt;
  &lt;li&gt;
  libsketch.a - this contains the object code of the files that comprise your Sketch.
  &lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
The use of archive libraries allows the linker to only include object files that provide referenced symbols, which will result in smaller executables if you use libraries that contain code that you don&#039;t actually use in your Sketch.
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I tried offering the Makefile to the Arduino developers but they seem a little, ummm... &lt;i&gt;reluctant&lt;/i&gt; to take contributions in areas outside of their immediate goals.  I understand they want to concentrate their efforts on their priorities, but if they want to grow the pool of people developing the Arduino platform (as opposed to growing the community developing &lt;i&gt;on&lt;/i&gt; the platform) they are going to have to change their approach.  It&#039;s not just me that has had this experience, the changes for the &lt;a href=&#034;http://www.edplese.com/arduino-on-solaris.html&#034;&gt;Solaris Arduino port&lt;/a&gt; also haven&#039;t made their way back in.
&lt;/p&gt;
&lt;p&gt;
I&#039;ll write a followup post on how I&#039;ve used the Makefile to enable me to use NetBeans as my Arduino development environment, including all the nice features such as code completion, pre-compilation error checking and syntax highlighting, so please check back for more!
&lt;/p&gt;
&lt;h1&gt;Update&lt;/h1&gt;
&lt;p&gt;
Martin Oldfield has done more-or less the same thing, with more of a Linux slant.  His version can be found &lt;a href=&#034;http://mjo.tc/atelier/2009/02/arduino-cli.html&#034;&gt;here&lt;/a&gt;.
&lt;/p&gt;</description>
      <category>Solaris</category>
    <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2010/06/04/a_makefile_for_arduino_sketches.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2010/06/04/a_makefile_for_arduino_sketches.html</guid>
    <pubDate>Fri, 04 Jun 2010 15:19:00 GMT</pubDate>
  </item>
  </channel>
</rss>

