<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ElectricRock Blog &#187; Ubuntu</title>
	<atom:link href="http://www.electricrock.co.nz/blog/tag/ubuntu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.electricrock.co.nz/blog</link>
	<description>Electronic Ramblings</description>
	<lastBuildDate>Tue, 10 Aug 2010 03:37:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sample Makefile for C30</title>
		<link>http://www.electricrock.co.nz/blog/2010/07/sample-makefile-for-c30/</link>
		<comments>http://www.electricrock.co.nz/blog/2010/07/sample-makefile-for-c30/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 22:00:11 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[C30]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.electricrock.co.nz/blog/?p=157</guid>
		<description><![CDATA[To simplify the process of starting a new C30 project I have created a sample Makefile that takes care of most of the hard work of library paths, linker scripts, etc. Check it out at http://www.electricrock.co.nz/blog/microchip-c30/#makefile and let me know if you run into any problems.
]]></description>
			<content:encoded><![CDATA[<p>To simplify the process of starting a new C30 project I have created a sample Makefile that takes care of most of the hard work of library paths, linker scripts, etc. Check it out at <a href="http://www.electricrock.co.nz/blog/microchip-c30/#makefile">http://www.electricrock.co.nz/blog/microchip-c30/#makefile</a> and let me know if you run into any problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricrock.co.nz/blog/2010/07/sample-makefile-for-c30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated C30 build script for C30 v3.23b</title>
		<link>http://www.electricrock.co.nz/blog/2010/07/updated-c30-build-script-for-c30-v3-23b/</link>
		<comments>http://www.electricrock.co.nz/blog/2010/07/updated-c30-build-script-for-c30-v3-23b/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 21:26:26 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[C30]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.electricrock.co.nz/blog/?p=151</guid>
		<description><![CDATA[I have made a minor update to the C30 install script so that it can build/install C30 v3.23b. The only real change (apart from updating filenames) is a new unattended install script for the non-free part.
Instructions and download here: http://www.electricrock.co.nz/blog/microchip-c30/.
]]></description>
			<content:encoded><![CDATA[<p>I have made a minor update to the C30 install script so that it can build/install C30 v3.23b. The only real change (apart from updating filenames) is a new unattended install script for the non-free part.</p>
<p>Instructions and download here: <a href="http://www.electricrock.co.nz/blog/microchip-c30/">http://www.electricrock.co.nz/blog/microchip-c30/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricrock.co.nz/blog/2010/07/updated-c30-build-script-for-c30-v3-23b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated C30 build script for Ubuntu 10.04</title>
		<link>http://www.electricrock.co.nz/blog/2010/05/updated-c30-build-script-for-ubuntu-10-04/</link>
		<comments>http://www.electricrock.co.nz/blog/2010/05/updated-c30-build-script-for-ubuntu-10-04/#comments</comments>
		<pubDate>Sun, 02 May 2010 21:25:50 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[C30]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.electricrock.co.nz/blog/?p=143</guid>
		<description><![CDATA[Ubuntu 10.04 is hot off the press, so I have uploaded an update to the C30 build script to run on it.  Apparently the dos2unix command is no longer supported in 10.04 so the script now uses fromdos (thanks to Nicolas for the info).
Latest version of the script can be found here: http://www.electricrock.co.nz/blog/microchip-c30/
]]></description>
			<content:encoded><![CDATA[<p>Ubuntu 10.04 is hot off the press, so I have uploaded an update to the C30 build script to run on it.  Apparently the dos2unix command is no longer supported in 10.04 so the script now uses fromdos (thanks to Nicolas for the info).</p>
<p>Latest version of the script can be found here: <a href="http://www.electricrock.co.nz/blog/microchip-c30/">http://www.electricrock.co.nz/blog/microchip-c30/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricrock.co.nz/blog/2010/05/updated-c30-build-script-for-ubuntu-10-04/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Building Microchip&#8217;s C30 Compiler v3.20 on Ubuntu 9.10</title>
		<link>http://www.electricrock.co.nz/blog/2010/01/building-c30-v32/</link>
		<comments>http://www.electricrock.co.nz/blog/2010/01/building-c30-v32/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 06:06:04 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[C30]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.electricrock.co.nz/blog/?p=87</guid>
		<description><![CDATA[NOTE: This page is now outdated, please go to http://www.electricrock.co.nz/blog/microchip-c30/
This an update to my previous tutorial for building Microchip’s C Compiler for PIC24 MCUs and dsPIC DSCs (herein referred to as C30). This update covers building v3.20 of the compiler (as opposed to v3.12) under Ubuntu 9.10.  Again, this is mostly gleaned from  http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux, but [...]]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE: This page is now outdated, please go to <a href="http://www.electricrock.co.nz/blog/microchip-c30/">http://www.electricrock.co.nz/blog/microchip-c30/</a></strong></p>
<p>This an update to my <a href="http://www.electricrock.co.nz/blog/2009/08/installing-microchips-c-compiler-for-pic24-mcus-and-dspic-dscs-c30-on-ubuntu-9-04">previous tutorial</a> for building Microchip’s C Compiler for PIC24 MCUs and dsPIC DSCs (herein referred to as C30). This update covers building v3.20 of the compiler (as opposed to v3.12) under Ubuntu 9.10.  Again, this is mostly gleaned from  <a href="http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/">http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux</a>, but adapted for the latest version of C30.</p>
<p>These instructions also work for v3.22 and are reported to work with v3.23.</p>
<p><span id="more-87"></span></p>
<h3>Installation</h3>
<h4>Install prerequisite software</h4>
<ul>
<li> Install packages from the Ubuntu repositories:
<pre class="brush: bash;">sudo aptitude install build-essential bison flex tofrodos</pre>
</li>
<li>Install wine (instructions available from the Wine website: <a href="http://www.winehq.org/download/deb">http://www.winehq.org/download/deb</a>). I used the following steps to install the latest version (you can just install the one in the Ubuntu repositories if you aren&#8217;t worried about being bleeding edge):
<pre class="brush: bash;">sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo aptitude install wine</pre>
</li>
</ul>
<h4>Setup paths</h4>
<p>The exports below can be varied depending on where you prefer things to be put. At the risk of stating the obvious I&#8217;ll outline what each of the exports is for:</p>
<ul>
<li>C30BUILD is the temporary directory where the C30 tool suite is built.</li>
<li>C30INSTALL is  where it will be installed to.</li>
<li>DOWNLOADDIR is where you save files to when downloading.</li>
<li>WINEPREFIX is where you want to install the proprietary tool suite.</li>
</ul>
<pre class="brush: bash;">export C30BUILD=$HOME/c30-build
export C30INSTALL=$HOME/Apps/pic30
export DOWNLOADDIR=$HOME/Downloads
export WINEPREFIX=$HOME/Apps/pic30-wine</pre>
<h4>Download sources, etc.</h4>
<ul>
<li>From Microchip&#8217;s website download the sources for the compiler and binutils.  They can be found on this page: <a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023073">http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023073</a>. You will need to login to download.  You want to get:
<ul>
<li><em>GCC Code for MPLAB ASM30 for dsPIC/PIC24 v3.20</em></li>
<li><em>MPLAB C30 v3.20 GCC Source</em></li>
</ul>
</li>
<li>Download the academic or evaluation version of the proprietary compiler from the C30 website (<a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en010065">http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en010065</a>)</li>
<li>Download the patches. I have adapted these from those provided by John Steele Scott (see my previous post) to work with v3.20.
<ul>
<li>Binutils: <a href="http://www.electricrock.co.nz/c30/pic30-binutils-3.20.tar.bz2">http://www.electricrock.co.nz/c30/pic30-binutils-3.20.tar.bz2</a></li>
<li>GCC: <a href="http://www.electricrock.co.nz/c30/pic30-gcc-3.20.tar.bz2">http://www.electricrock.co.nz/c30/pic30-gcc-3.20.tar.bz2</a></li>
</ul>
</li>
</ul>
<h4>Building Binutils</h4>
<ul>
<li>Unzip the sources.
<pre class="brush: bash;">
mkdir -p $C30BUILD/binutils
cd $C30BUILD/binutils
tar -zxvf $DOWNLOADDIR/mplabalc30v3_20.tar.gz
tar -jxvf $DOWNLOADDIR/pic30-binutils-3.20.tar.bz2
</pre>
</li>
<li>The microchip sources have been edited on windows, so we need to convert files to unix line endings so that they can be patched.
<pre class="brush: bash;">find . -type f -exec dos2unix '{}' ';'</pre>
</li>
<li>Apply the patches.  So far as I can tell, these fix a few compile issues with the microchip compiler and make it play nicer under Linux.
<pre class="brush: bash;">for i in pic30-binutils-3.20/patches/*.diff; do echo &quot;Applying patch $i...&quot;; patch -p0 &lt; $i; done</pre>
</li>
<li>Build it, the version number in DMHCP_VERSION needs to match the version of the non-free compiler you install.
<pre class="brush: bash;"> cd acme/
CFLAGS=-DMCHP_VERSION=&quot;v3.20-Debian&quot; ./configure --prefix=$C30INSTALL --target=pic30-coff
</pre>
<li>Before we can make it we need to touch some files otherwise it doesn&#8217;t get built properly.
<pre class="brush: plain;">find . -name &quot;*.y&quot; -o -name &quot;*.l&quot; -exec touch '{}' ';'</pre>
<li>Make it.
<pre class="brush: plain;">make</pre>
</li>
<li>Install, if you install to a location that you don&#8217;t have write permission to (e.g. /usr/local) you will need to use sudo.
<pre class="brush: bash;"> make install </pre>
</li>
</ul>
<h4>Building GCC</h4>
<ul>
<li>Similar process to binutils above for building GCC.
<pre class="brush: bash;">mkdir -p $C30BUILD/gcc
cd $C30BUILD/gcc
tar -zxvf $DOWNLOADDIR/mplabc30v3_20.tar.gz
tar -jxvf $DOWNLOADDIR/pic30-gcc-3.20.tar.bz2
find . -type f -exec dos2unix '{}' ';'
for i in pic30-gcc-3.20/patches/*.diff; do echo &quot;Applying patch $i...&quot;; patch -p0 &lt; $i; done</pre>
</li>
<li>We take a slight deviation from binutils here as we create a separate directory for GCC to build in, apparently it likes it that way.
<pre class="brush: bash;">mkdir build
cd build
CFLAGS=-DMCHP_VERSION=&quot;v3.20-Debian&quot; ../gcc-4.0.2/gcc-4.0.2/configure --prefix=$C30INSTALL --target=pic30-coff --enable-languages=c</pre>
</li>
<li>Then we have to touch c-parse.y cause (according to <a href="http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/">embeddedfreak</a>) it doesn&#8217;t get generated correctly, so we need it to be recreated. I just followed the instructions and it worked.
<pre class="brush: bash;">touch ../gcc-4.0.2/gcc-4.0.2/gcc/c-parse.y</pre>
</li>
<li>Build it and install it (again, use sudo for make install if you have to).
<pre class="brush: bash;">make
make install</pre>
</li>
<li>Link the binutils into GCC&#8217;s tool path so it can find them, and create a link to GCC itself so we don&#8217;t have to type the version number every time:
<pre class="brush: bash;">ln -s $C30INSTALL/bin/pic30-coff-as $C30INSTALL/libexec/gcc/pic30-coff/4.0.3/pic30-coff-as
ln -s $C30INSTALL/bin/pic30-coff-ld $C30INSTALL/libexec/gcc/pic30-coff/4.0.3/pic30-coff-ld
ln -s $C30INSTALL/bin/pic30-coff-gcc-4.0.3 $C30INSTALL/bin/pic30-coff-gcc</pre>
</li>
</ul>
<h4>Next Steps</h4>
<p>The rest of the steps are just the same as for building v3.12.  I won&#8217;t repeat myself here, just check out my <a href="http://www.electricrock.co.nz/blog/2009/08/installing-microchips-c-compiler-for-pic24-mcus-and-dspic-dscs-c30-on-ubuntu-9-04/">previous tutorial</a> and follow the steps from <em>Setup the non-free part</em> onward.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricrock.co.nz/blog/2010/01/building-c30-v32/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using a Xilinx DLC5 Parallel Cable to program an AT89S52</title>
		<link>http://www.electricrock.co.nz/blog/2009/09/using-a-xilinx-dlc5-parallel-cable-to-program-an-at89s52/</link>
		<comments>http://www.electricrock.co.nz/blog/2009/09/using-a-xilinx-dlc5-parallel-cable-to-program-an-at89s52/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 22:31:01 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[at89s52]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.electricrock.co.nz/blog/?p=56</guid>
		<description><![CDATA[While working on my control 16 project I realised I would need to replace the firware of the onboard microcontroller, an AT89C52.  Unfortunately, the AT89C52 is a mission to program (as it is parallel programmable only) so I have replaced it with an AT89S52, which supports in-circuit serial programming.  What I still lacked was an [...]]]></description>
			<content:encoded><![CDATA[<p>While working on my control 16 project I realised I would need to replace the firware of the onboard microcontroller, an AT89C52.  Unfortunately, the AT89C52 is a mission to program (as it is parallel programmable only) so I have replaced it with an AT89S52, which supports in-circuit serial programming.  What I still lacked was an ISP programmer; however, instead of building one I made use of an old Xilinx DLC5 parallel port JTAG cable (<a href="http://www.xilinx.com/itp/xilinx4/data/docs/pac/appendixb.html">schematic</a>).  This was fairly straight forward under Ubuntu 9.04, using <a href="http://www.nongnu.org/uisp/">UISP</a> AVR and AT89S programming software.  The following instructions assume the target is self powered and has an oscillator/crystal connected if required. NB these instructions are written from memory, so if you find a mistake please post a comment.</p>
<p><span id="more-56"></span></p>
<h3>Setup</h3>
<ol>
<li>Add yourself to the lp group so that you can access the parallel port without needing to be superuser (you will need to log out and back in again after this command):<br />
<span style="color: #0000ff;"><em>sudo usermod -a -G lp &lt;username&gt;<br />
</em></span></li>
<li>Install uisp:<br />
<span style="color: #0000ff;"><em>sudo aptitude install uisp</em></span></li>
<li>Connect the JTAG cable to your target device as follows:<br />
<table border="0">
<tbody>
<tr>
<td><strong>JTAG</strong></td>
<td><strong>Target</strong></td>
</tr>
<tr>
<td>Vcc</td>
<td>Vcc</td>
</tr>
<tr>
<td>GND</td>
<td>GND</td>
</tr>
<tr>
<td>TDI</td>
<td>MOSI</td>
</tr>
<tr>
<td>TDO</td>
<td>MISO</td>
</tr>
<tr>
<td>TCK</td>
<td>SCK</td>
</tr>
<tr>
<td>TMS</td>
<td>RST</td>
</tr>
</tbody>
</table>
</li>
</ol>
<h3>Some useful UISP commands</h3>
<p>These are given for AT89S52, but for other AVR series it should work if you just drop the <em>-d89</em> flag and use the appropriate part number.  The main thing to note here is that the <em>dprog</em> flag is set to <em>xil</em> to indicate we are using a DLC5 for programming.</p>
<table border="0">
<tbody>
<tr>
<td>Erase</td>
<td><span style="color: #0000ff;"><em>uisp -d89 -dprog=xil -dpart=at89s52 &#8211;erase</em></span></td>
</tr>
<tr>
<td>Program</td>
<td><em><span style="color: #0000ff;">uisp -d89 -dprog=xil -dpart=at89s52  &#8211;upload if=[input filename (in intel hex or motorolla srec format)]</span></em></td>
</tr>
<tr>
<td>Read back</td>
<td><em><span style="color: #0000ff;">uisp -d89 -dprog=xil -dpart=at89s52 &#8211;download of=[output filename (in srec format)]</span></em></td>
</tr>
</tbody>
</table>
<p>If you have issues try adding <em>-v=3</em> or <em>-v=4</em> for more verbose output from UISP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricrock.co.nz/blog/2009/09/using-a-xilinx-dlc5-parallel-cable-to-program-an-at89s52/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using C30 with Piklab</title>
		<link>http://www.electricrock.co.nz/blog/2009/08/using-c30-with-piklab/</link>
		<comments>http://www.electricrock.co.nz/blog/2009/08/using-c30-with-piklab/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 21:11:08 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[C30]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Piklab]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.electricrock.co.nz/blog/?p=47</guid>
		<description><![CDATA[This post follows on from my previous post on building Microchip's C compiler for PIC24 and dsPIC (C30) onUbuntu.  Piklab is a great IDE for PIC development, and IMHO much nicer to use than MPLAB.  Piklab has support for the dsPIC30 series of PICs using the C30 toolchain.  However, I found the default settings need a little bit of tweaking to make the the toolchain that I built work. The following post details how I setup Piklab to make use of this toolchain.]]></description>
			<content:encoded><![CDATA[<p>This post follows on from my previous post on <a href="http://www.electricrock.co.nz/blog/2009/08/installing-microchips-c-compiler-for-pic24-mcus-and-dspic-dscs-c30-on-ubuntu-9-04/">building Microchip&#8217;s C compiler for PIC24 and dsPIC (C30) onUbuntu</a>.  <a href="http://piklab.sourceforge.net/">Piklab</a> is a great IDE for PIC development, and IMHO much nicer to use than MPLAB.  Piklab has support for the dsPIC30 series of PICs using the C30 toolchain.  However, I found the default settings need a little bit of tweaking to make the the toolchain that I built work. The following post details how I setup Piklab to make use of this toolchain.</p>
<p><span id="more-47"></span></p>
<h3>Configuring the Toolchain</h3>
<p>NB: The following assumes <em>&lt;C30-base&gt;</em> is the directory where C30 was installed (if you followed my previous tutorial this will be whatever you set for the <em>C30INSTALL</em> environment variable).</p>
<ul>
<li>Open up Piklab and go to <em>Settings-&gt;Configure Toolchains&#8230;</em></li>
<li>In the <em>Configure Toolchains</em> window select <em>PIC30 Toolchain</em> from the sidebar.</li>
<li>Fill out the fields as follows:
<ul>
<li><em>Executable directory</em> &#8211; <em>&lt;C30-base&gt;/bin</em></li>
<li><em>Header directory</em> &#8211; <em>&lt;C30-base&gt;/pic30-nonfree/support/dsPIC30F/h/</em> (assuming you are using C30 to compile for dsPIC30F series&#8211;I haven&#8217;t tried any other series, so YMMV).</li>
<li><em>Linker script directory</em> &#8211; <em>&lt;C30-base&gt;/pic30-nonfree/support/dsPIC30F/gld/</em></li>
<li><em>Library directory</em> &#8211; <em>&lt;C30-base&gt;/pic30-nonfree/lib/<br />
</em></li>
</ul>
</li>
<li>The other fields can be left as the default.</li>
</ul>
<h3>Configuring the Project</h3>
<p>For each project you will also have to do some configuration. After creating a new project, bring up the <em>Project Options</em> window (<em>Project-&gt;Project Options&#8230;</em>), and fill in as follows:</p>
<ul>
<li>Toolchain tab
<ul>
<li>Make sure <em>PIC30 Toolchain</em> is the active toolchain.</li>
</ul>
</li>
<li>Compiler tab
<ul>
<li>In the <em>Custom options</em> field enter: <em>-mresource=&lt;C30-base&gt;/info/c30_device.info</em></li>
</ul>
</li>
<li>Linker tab
<ul>
<li>In the <em>Custom libraries</em> field enter: <em>-lpic30</em></li>
</ul>
</li>
</ul>
<p>That should be enough to build coff files in Piklab.  I have successfully programming the dsPIC30F4013 from Piklab using the above toolchain to build the firmware and an Microchip ICD2 to download it to the PIC.  If you have any issues, if this doesn&#8217;t work for you, or if you have had some luck using a different family of PICs with C30, then please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricrock.co.nz/blog/2009/08/using-c30-with-piklab/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Installing Microchip&#8217;s C Compiler for PIC24 MCUs and dsPIC DSCs (C30) on Ubuntu 9.04</title>
		<link>http://www.electricrock.co.nz/blog/2009/08/installing-microchips-c-compiler-for-pic24-mcus-and-dspic-dscs-c30-on-ubuntu-9-04/</link>
		<comments>http://www.electricrock.co.nz/blog/2009/08/installing-microchips-c-compiler-for-pic24-mcus-and-dspic-dscs-c30-on-ubuntu-9-04/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 03:49:25 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[C30]]></category>
		<category><![CDATA[PIC]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.electricrock.co.nz/blog/?p=3</guid>
		<description><![CDATA[Microchip's C Compiler for PIC24 MCUs and dsPIC DSCs (herein referred to as C30) is a GCC derivative and therefore the sources are freely available to build it on any platform.  However, the documentation for getting a working setup seems to be sparse.  This blog entry details the steps I followed to install it under Ubuntu 9.04.]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE: This page is now outdated, please go to <a href="http://www.electricrock.co.nz/blog/microchip-c30/">http://www.electricrock.co.nz/blog/microchip-c30/</a></strong></p>
<p>Microchip&#8217;s C Compiler for PIC24 MCUs and dsPIC DSCs (herein referred to as C30) is a GCC derivative and therefore the sources are freely available to build it on any platform.  However, the documentation for getting a working setup seems to be sparse.  This blog entry details the steps I followed to install it under Ubuntu 9.04, mostly gleaned from  <a href="http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/">http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux</a>. There are some small changes from the embeddedfreak version, I am using v3.12 of the compiler (the most recent version at the time of writing) and I will provide details of how to setup the non-free part.</p>
<p><span id="more-3"></span></p>
<p>Code lines in blue are to be executed at the terminal, sorry that they look so ugly at the moment&#8211;I will pretty up the formatting at some point.</p>
<p>Disclaimer: These instructions are provided as a guide only, you use them at your own risk&#8211;I accept no responsibility if something goes wrong <img src='http://www.electricrock.co.nz/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h3>Installation</h3>
<h4>Install prerequisite software</h4>
<ul>
<li> Install packages from the Ubuntu repositories:<br />
<span style="color: #0000ff;"><code>sudo aptitude install build-essential bison flex tofrodos</code></span></li>
<li>Install wine (instructions available from the Wine website: <a href="http://www.winehq.org/download/deb">http://www.winehq.org/download/deb</a>).</li>
</ul>
<h4>Setup paths</h4>
<p>The exports below can be varied depending on where you prefer things to be put. At the risk of stating the obvious I&#8217;ll outline what each of the exports is for:</p>
<ul>
<li>C30BUILD is the temporary directory where the C30 tool suite is built.</li>
<li>C30INSTALL is  where it will be installed to.</li>
<li>DOWNLOADDIR is where you save files to when downloading.</li>
<li>WINEPREFIX is where you want to install the proprietary tool suite.</li>
</ul>
<p style="padding-left: 30px;"><span style="color: #0000ff;"><code>export C30BUILD=$HOME/c30-build<br />
export C30INSTALL=$HOME/Apps/pic30<br />
export DOWNLOADDIR=$HOME/Downloads<br />
export WINEPREFIX=$HOME/Apps/pic30-wine</code></span></p>
<h4>Download sources, etc.</h4>
<ul>
<li>From Microchip&#8217;s website download the sources for the compiler and binutils.  They can be found on this page: <a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023073">http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023073</a>. You will need to login to download.  You want to get:
<ul>
<li><em>GCC Code for MPLAB ASM30 for dsPIC/PIC24 v3.12</em></li>
<li><em>MPLAB C30 v3.12 GCC Source</em></li>
</ul>
</li>
<li>Download the academic or evaluation version of the proprietary compiler from the C30 website (<a href="http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en010065">http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en010065</a>)</li>
<li>Download John Steele Scott&#8217;s patches
<ul>
<li>Binutils: <a href="http://www.4shared.com/file/75582162/7a251aaf/pic30-binutils-311btar.html ">http://www.4shared.com/file/75582162/7a251aaf/pic30-binutils-311btar.html</a></li>
<li>GCC: <a href="http://www.4shared.com/file/76025702/9eb06aad/pic30-gcc-311btar.html">http://www.4shared.com/file/76025702/9eb06aad/pic30-gcc-311btar.html</a></li>
</ul>
</li>
</ul>
<h4>Building Binutils</h4>
<ul>
<li>Unzip the sources.<br />
<span style="color: #0000ff;"><code><br />
mkdir -p $C30BUILD/binutils<br />
cd $C30BUILD/binutils<br />
tar -zxvf $DOWNLOADDIR/mplabalc30v3_12.tar.gz<br />
tar -jxvf $DOWNLOADDIR/pic30-binutils-3.11b.tar.bz2</code></span></li>
<li>The microchip sources have been edited on windows, so we need to convert files to unix line endings so that they can be patched.<br />
<span style="color: #0000ff;"><code>find . -type f -exec dos2unix '{}' ';'</code></span></li>
<li>Apply John Steele Scott&#8217;s patches.  So far as I can tell, these fix a few compile issues with the microchip compiler and make it play nicer under Linux.<br />
<span style="color: #0000ff;"><code>for i in pic30-binutils-3.11b/patches/*.diff; do echo "Applying patch $i..."; patch -p0 &lt; $i; done</code></span></li>
<li>Build it, the version number in DMHCP_VERSION needs to match the version of the non-free compiler you install.<br />
<span style="color: #0000ff;"><code>cd acme/<br />
CFLAGS=-DMCHP_VERSION="v3.12-Debian" ./configure --prefix=$C30INSTALL --target=pic30-coff<br />
make</code></span></li>
<li>Install, if you install to a location that you don&#8217;t have write permission to (e.g. /usr/local) you will need to use sudo.<br />
<span style="color: #0000ff;"><code>make install</code></span></li>
</ul>
<h4>Building GCC</h4>
<ul>
<li>Similar process to binutils above for building GCC.<br />
<span style="color: #0000ff;"><code>mkdir -p $C30BUILD/gcc<br />
cd $C30BUILD/gcc<br />
tar -zxvf $DOWNLOADDIR/mplabc30v3_12.tar.gz<br />
tar -jxvf $DOWNLOADDIR/pic30-gcc-3.11b.tar.bz2<br />
find . -type f -exec dos2unix '{}' ';'<br />
for i in pic30-gcc-3.11b/patches/*.diff; do echo "Applying patch $i..."; patch -p0 &lt; $i; done</code></span></li>
<li>We take a slight deviation from binutils here as we create a separate directory for GCC to build in, apparently it likes it that way.<br />
<span style="color: #0000ff;"><code>mkdir build<br />
cd build<br />
CFLAGS=-DMCHP_VERSION="v3.12-Debian" ../gcc-4.0.2/gcc-4.0.2/configure --prefix=$C30INSTALL --target=pic30-coff --enable-languages=c</code></span></li>
<li>Then we have to touch c-parse.y cause (according to <a href="http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/">embeddedfreak</a>) it doesn&#8217;t get generated correctly, so we need it to be recreated. I just followed the instructions and it worked.<br />
<span style="color: #0000ff;"><code>touch ../gcc-4.0.2/gcc-4.0.2/gcc/c-parse.y</code></span></li>
<li>Build it and install it (again, use sudo for make install if you have to).<br />
<span style="color: #0000ff;"><code>make<br />
make install</code></span></li>
<li>Link the binutils into GCC&#8217;s tool path so it can find them, and create a link to GCC itself so we don&#8217;t have to type the version number every time:<br />
<span style="color: #0000ff;"><code>ln -s $C30INSTALL/bin/pic30-coff-as $C30INSTALL/libexec/gcc/pic30-coff/4.0.3/pic30-coff-as</code><br />
<code>ln -s $C30INSTALL/bin/pic30-coff-ld $C30INSTALL/libexec/gcc/pic30-coff/4.0.3/pic30-coff-ld<br />
ln -s $C30INSTALL/bin/pic30-coff-gcc-4.0.3 $C30INSTALL/bin/pic30-coff-gcc</code></span></li>
</ul>
<h4>Setup the non-free part</h4>
<ul>
<li>Install the downloaded non-free version of the compiler using WINE. Make sure you run this from the terminal after setting the WINEPREFIX environment variable (as opposed to e.g. double clicking the EXE icon).<br />
<span style="color: #0000ff;"><code>wine {path to installer.exe}</code></span></li>
<li>Copy required directories and files, it would probably be tidier to fix the search path for the info files in the source, but instead I just make some links where necessary.<br />
<span style="color: #0000ff;"><code>cp $WINEPREFIX/drive_c/Program\ Files/Microchip/MPLAB\ C30/bin/c30_device.info $C30INSTALL/info<br />
ln -s $C30INSTALL/info/c30_device.info $C30INSTALL/c30_device.info<br />
ln -s $C30INSTALL/info/c30_device.info $C30INSTALL/libexec/gcc/pic30-coff/c30_device.info<br />
mkdir $C30INSTALL/pic30-nonfree<br />
cp -r $WINEPREFIX/drive_c/Program\ Files/Microchip/MPLAB\ C30/support $C30INSTALL/pic30-nonfree<br />
cp -r $WINEPREFIX/drive_c/Program\ Files/Microchip/MPLAB\ C30/include $C30INSTALL/pic30-nonfree<br />
cp -r $WINEPREFIX/drive_c/Program\ Files/Microchip/MPLAB\ C30/lib $C30INSTALL/pic30-nonfree</code></span></li>
</ul>
<h3>Troubleshooting</h3>
<h4>Provide Resource File</h4>
<p>When running the compiler you may find that it baulks when running a command such as:<br />
<code>$C30INSTALL/bin/pic30-coff-gcc -mcpu=30F4013  -o test test.c</code><br />
with the error<br />
<code>pic30-coff-cc1: warning: Provide a resource file<br />
pic30-coff-cc1: error: Invalid -mcpu option.  CPU 30F4013 not recognized.</code></p>
<p>To solve this add <code>-mresource=$C30INSTALL/info/c30_device.info</code> to your GCC command line.</p>
<h4>Unknown Processor</h4>
<p>If you get the error:<br />
<code>Unknown processor 30F4013.</code><br />
Then you haven&#8217;t created the links to the info file correctly. I found from running gcc with the <em>-v</em> (verbose) flag that this error is actually generated by the assembler, which is being called from under the libexec directory (hence the need for the info file to be linked there also.)</p>
<h3>Next Step</h3>
<p>Now that you have built a working toolchain, it&#8217;s time to setup an IDE to use with it (if you are that way inclined).  I recommend <a href="http://piklab.sourceforge.net">Piklab</a>. You can find instructions for using the C30 toolchain with Piklab in <a href="http://www.electricrock.co.nz/blog/2009/08/using-c30-with-piklab/">this post</a>.</p>
<h3>References</h3>
<p>You should now have a working C30 compiler installed in $C30INSTALL.  Thanks to KUNILKUDA <a href="http://embeddedfreak.wordpress.com">Embedded Freaks</a> for the <a href="http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/">tutorial</a> which I followed  and from which these instructions are mostly derived.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricrock.co.nz/blog/2009/08/installing-microchips-c-compiler-for-pic24-mcus-and-dspic-dscs-c30-on-ubuntu-9-04/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
