<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Embedded Freaks.. &#187; pic</title>
	<atom:link href="http://embeddedfreak.wordpress.com/tag/pic/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedfreak.wordpress.com</link>
	<description>Daily embedded life tips and trick</description>
	<lastBuildDate>Sat, 14 Nov 2009 00:47:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='embeddedfreak.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/9f1113cc5558fcab720e54b7e5a379eb?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Embedded Freaks.. &#187; pic</title>
		<link>http://embeddedfreak.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://embeddedfreak.wordpress.com/osd.xml" title="Embedded Freaks.." />
		<item>
		<title>Compiling MPLAB C30 v3.11(b) Source Code under Linux</title>
		<link>http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/</link>
		<comments>http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 11:47:00 +0000</pubDate>
		<dc:creator>kunilkuda</dc:creator>
				<category><![CDATA[pic]]></category>

		<guid isPermaLink="false">http://embeddedfreak.wordpress.com/?p=205</guid>
		<description><![CDATA[Here&#8217;s my experiment with the MPLAB&#8217;s C30 source code. The original site for the patches (for C30 v3.00) can be viewed from Peter-Jan Randewijk page and piklab wiki.

System Prequisities
You will need GCC, Bison, Flex, and Tofrodos/Dos2unix utility. For Ubuntu users, just do:

# sudo apt-get install build-essential bison flex tofrodos

The autoconf of the MPLAB package seems [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=embeddedfreak.wordpress.com&blog=1740165&post=205&subd=embeddedfreak&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Here&#8217;s my experiment with the MPLAB&#8217;s C30 source code. The original site for the patches (for C30 v3.00) can be viewed from <a title="Microchip MPLAB C30 v3.00" href="http://staff.ee.sun.ac.za/pjrandewijk/wiki/index.php/Microchip_MPLAB_C30_v3.00">Peter-Jan Randewijk page</a> and <a href="http://piklab.wiki.sourceforge.net/Compilation+of+pic30+version+3.01">piklab wiki</a>.</p>
<p><span id="more-205"></span></p>
<p><strong>System Prequisities</strong></p>
<p>You will need GCC, Bison, Flex, and Tofrodos/Dos2unix utility. For Ubuntu users, just do:</p>
<pre class="brush: java;">
# sudo apt-get install build-essential bison flex tofrodos
</pre>
<p>The autoconf of the MPLAB package seems like doesn&#8217;t check the bison and flex availability, causing the compilation failure at certain point. If the compilation failure due to *.y and/or *.l file, make sure your bison (yacc) and flex in on the system path.</p>
<p><strong>Getting The Source Code</strong></p>
<p>Download:</p>
<ul>
<li>PIC30-Binutis (mplabalc30_v3_11B.tar.gz from <a href="http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en023073&amp;lang=en&amp;ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023073#">Microchip&#8217;s site</a>)</li>
<li>PIC30-GCC (mplabc30_v3_11B.tar.gz from <a href="http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en023073&amp;lang=en&amp;ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;nodeId=1406&amp;dDocName=en023073#">Microchip&#8217;s site</a>)</li>
</ul>
<p>You need to register yourself before you can download it from Microchip.</p>
<p><strong>Compiling PIC30-Binutils</strong></p>
<p>Untar mplabalc30_v3_11B.tar.gz</p>
<pre class="brush: java;">
# tar xvzf mplabalc30_v3_11B.tar.gz
</pre>
<p>You&#8217;ll find two directories extracted: acme/ and c30_resource/. Since Microchip is using Windows, you need to convert the files into Unix files (ie. replace Windows newline with Unix&#8217;s).</p>
<pre class="brush: java;">
# find . -type f -exec dos2unix '{}' ';'
</pre>
<p>Then apply modified John Steele Scott&#8217;s patch (<a href="http://www.4shared.com/file/75582162/7a251aaf/pic30-binutils-311btar.html">here</a>)</p>
<pre class="brush: java;">
# tar xvjf pic30-binutils-3.11b.tar.bz2
# patch -p0 &lt; pic30-binutils-3.11b/patches/allow-empty-device-info-file.diff
# patch -p0 &lt; pic30-binutils-3.11b/patches/binutils-makefile_in.diff
# patch -p0 &lt; pic30-binutils-3.11b/patches/search-path-fix.diff
</pre>
<p>Configure the package, make, and make install</p>
<pre class="brush: java;">
# cd acme/
# CFLAGS=-DMCHP_VERSION=&quot;v3.11b-Debian&quot; ./configure --prefix=/usr/local/pic --target=pic30-coff
# make
# sudo make install
</pre>
<p>The binary that you&#8217;ve just compiled can only produces/modify COFF executables. You might need the ELF one too.</p>
<pre class="brush: java;">
# make distclean
# CFLAGS=-DMCHP_VERSION=&quot;v3.11b-Debian&quot; ./configure --prefix=/usr/local/pic --target=pic30-elf
# make
# sudo make install
</pre>
<p>And that&#8217;s the end for the PIC30-Binutils. <strong>Note:</strong> Under Ubuntu 8.10, if the compilation complaints about &#8220;<em>ylwrap : line xx -d not found</em>&#8220;, install bison first (eg. &#8220;sudo apt-get install bison&#8221;), before you configure the package.</p>
<p><strong>Compiling PIC30-GCC</strong></p>
<p>Untar mplabc30_v3_11B.tar.gz</p>
<pre class="brush: java;">
# tar xvzf mplabc30_v3_11B.tar.gz
</pre>
<p>It will extract two subdirs: gcc-4.0.2/ and c30_resource/. The next step is similar with PIC30-Binutils, replace the Windows newline with Unix&#8217;s.</p>
<pre class="brush: java;">
# find . -type f -exec dos2unix '{}' ';'
</pre>
<p>Then apply John Steele Scott&#8217;s patch and mine into the GCC source.</p>
<pre class="brush: java;">
# tar xvjf pic30-gcc-3.11b.tar.bz2
# patch -p0 &lt; pic30-gcc-3.11b/patches/libiberty-testsuite.diff
# patch -p0 &lt; pic30-gcc-3.11b/patches/pic30-standard-prefix.diff
# patch -p0 &lt; pic30-gcc-3.11b/patches/search-path-fix.diff
# patch -p0 &lt; pic30-gcc-3.11b/patches/make-relative-prefix.diff
# patch -p0 &lt; pic30-gcc-3.11b/patches/resource-path.diff
# patch -p0 &lt; pic30-gcc-3.11b/patches/t-pic30.diff
</pre>
<p>Now, the PIC30-GCC doesn&#8217;t like you to build the source code inside the directory itself. Create different directory to configure and compile the PIC30-GCC, then install it.</p>
<pre class="brush: java;">
# mkdir gcc-build
# cd gcc-build
# CFLAGS=-DMCHP_VERSION=&quot;v3.11b-Debian&quot; ../gcc-4.0.2/gcc-4.0.2/configure --prefix=/usr/local/pic --target=pic30-coff --enable-languages=c
</pre>
<p>Additional note from Michal Demin:</p>
<blockquote><p>The semantic analyzer in gcc package (c-parse.c file) is not generated correctly. Therefore the pic30-gcc will not recognize standard C keywords (void, return..etc). You have to force the Makefile to regenerate it by</p>
<p>touch ../gcc-4.0.2/gcc-4.0.2/gcc/c-parse.y</p>
<p>before executing the make.</p></blockquote>
<pre class="brush: java;">
# make
# sudo make install
</pre>
<p><strong>Note:</strong> Under Ubuntu 8.10, install flex if the compilation is error due to &#8220;gcc: gengtype-lex.c: No such file or directory&#8221;.</p>
<p>Now, due to my time limitation, I cannot fix the default path for the binutils directory (I hope someday someone will..It&#8217;s pretty easy). Therefore, you will need to copy binutils&#8217; assembler (pic30-coff-as) and linker (pic30-coff-ld) into PIC30-GCC&#8217;s default program path ($PREFIX/libexec/gcc/pic30-coff/$GCC-VERSION). Like this:</p>
<pre class="brush: java;">
# sudo cp /usr/local/pic/bin/pic30-coff-as /usr/local/pic/libexec/gcc/pic30-coff/4.0.3/
# sudo cp /usr/local/pic/bin/pic30-coff-ld /usr/local/pic/libexec/gcc/pic30-coff/4.0.3/
</pre>
<p>That&#8217;s it. Your PIC30-GCC is ready. But suppose you want to build ELF executable (instead of COFF), do it again with &#8211;target=pic30-elf</p>
<pre class="brush: java;">
# cd .. &amp;&amp; rm -fdr gcc-build &amp;&amp; mkdir gcc-build &amp;&amp; cd gcc-build
# CFLAGS=-DMCHP_VERSION=&quot;v3.11b-Debian&quot; ../gcc-4.0.2/gcc-4.0.2/configure --prefix=/usr/local/pic --target=pic30-elf --enable-languages=c
# touch ../gcc-4.0.2/gcc-4.0.2/gcc/c-parse.y
# make
# sudo make install
</pre>
<p>Don&#8217;t forget to copy the pic30-elf-as and pic30-elf-ld.</p>
<pre class="brush: java;">
# sudo cp /usr/local/pic/bin/pic30-elf-as /usr/local/pic/libexec/gcc/pic30-elf/4.0.3/
# sudo cp /usr/local/pic/bin/pic30-elf-ld /usr/local/pic/libexec/gcc/pic30-elf/4.0.3/
</pre>
<p><strong>Simple Test for The Compiler</strong></p>
<p>Here&#8217;s some simple test for the newly built compiler:</p>
<pre class="brush: java;">
# echo &quot;int main(void) { return 0; }&quot; &gt; test.c
# /usr/local/pic/bin/pic30-coff-gcc-4.0.3 -c test.c
</pre>
<p>You cannot link the program without the linker files (*.gld files from Microchip&#8217;s libc). But you can check the compilation result by:</p>
<pre class="brush: java;">
# /usr/local/pic/bin/pic30-coff-objdump -S test.o
test.o:     file format coff-pic30

Disassembly of section .text:

00000000 :
   0:	00 00 fa    	lnk       #0x0
   2:	00 00 eb    	clr.w     w0
   4:	00 80 fa    	ulnk
   6:	00 00 06    	return
</pre>
<p><strong>Adding Microchip&#8217;s Library</strong><br />
Here&#8217;s the hint. Issue this command to get the PIC30-GCC&#8217;s default library path:</p>
<pre class="brush: java;">
# /usr/local/bin/pic30-coff-gcc-4.0.3 -print-search-dirs
</pre>
<p>By looking the default library path, you should know which directory in Microchip&#8217;s &#8220;Program Files/Microchip&#8221; that needs to be copied. Also, you will know where to put it (Hint: $prefix/pic30-nonfree or /usr/local/pic/pic30-nonfree if you follow this guide).</p>
<p><strong>Does It Realy Work ?<br />
</strong></p>
<p>You tell me. I&#8217;m newbies in PIC MCUs, and I haven&#8217;t got any Microchip&#8217;s libc so far. Microchip said that the libc (and C start-up anf linker files) are belong to them. So, they are not the part of the GPL-ed code.</p>
<p>Anyway, if you find this build guide works, please post me the sample code that you are using. I can use it to learn PIC24 <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/embeddedfreak.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/embeddedfreak.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/embeddedfreak.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/embeddedfreak.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/embeddedfreak.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/embeddedfreak.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/embeddedfreak.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/embeddedfreak.wordpress.com/205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/embeddedfreak.wordpress.com/205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/embeddedfreak.wordpress.com/205/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=embeddedfreak.wordpress.com&blog=1740165&post=205&subd=embeddedfreak&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://embeddedfreak.wordpress.com/2008/10/10/compiling-mplab-c30-v311b-under-linux/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/13b3ee554fe96a750148b9819d734843?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">kunilkuda</media:title>
		</media:content>
	</item>
	</channel>
</rss>