ElectricRock Blog

Building Microchip’s C30 Compiler v3.20 on Ubuntu 9.10

by matt on Jan.03, 2010, under How To

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 adapted for the latest version of C30.

These instructions also work for v3.22 and are reported to work with v3.23.

Installation

Install prerequisite software

  • Install packages from the Ubuntu repositories:
    sudo aptitude install build-essential bison flex tofrodos
  • Install wine (instructions available from the Wine website: http://www.winehq.org/download/deb). I used the following steps to install the latest version (you can just install the one in the Ubuntu repositories if you aren’t worried about being bleeding edge):
    sudo add-apt-repository ppa:ubuntu-wine/ppa
    sudo aptitude install wine

Setup paths

The exports below can be varied depending on where you prefer things to be put. At the risk of stating the obvious I’ll outline what each of the exports is for:

  • C30BUILD is the temporary directory where the C30 tool suite is built.
  • C30INSTALL is  where it will be installed to.
  • DOWNLOADDIR is where you save files to when downloading.
  • WINEPREFIX is where you want to install the proprietary tool suite.
export C30BUILD=$HOME/c30-build
export C30INSTALL=$HOME/Apps/pic30
export DOWNLOADDIR=$HOME/Downloads
export WINEPREFIX=$HOME/Apps/pic30-wine

Download sources, etc.

Building Binutils

  • Unzip the sources.
    mkdir -p $C30BUILD/binutils
    cd $C30BUILD/binutils
    tar -zxvf $DOWNLOADDIR/mplabalc30v3_20.tar.gz
    tar -jxvf $DOWNLOADDIR/pic30-binutils-3.20.tar.bz2
    
  • The microchip sources have been edited on windows, so we need to convert files to unix line endings so that they can be patched.
    find . -type f -exec dos2unix '{}' ';'
  • 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.
    for i in pic30-binutils-3.20/patches/*.diff; do echo "Applying patch $i..."; patch -p0 < $i; done
  • Build it, the version number in DMHCP_VERSION needs to match the version of the non-free compiler you install.
     cd acme/
    CFLAGS=-DMCHP_VERSION="v3.20-Debian" ./configure --prefix=$C30INSTALL --target=pic30-coff
    make
  • Install, if you install to a location that you don’t have write permission to (e.g. /usr/local) you will need to use sudo.
     make install 

Building GCC

  • Similar process to binutils above for building GCC.
    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 "Applying patch $i..."; patch -p0 < $i; done
  • 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.
    mkdir build
    cd build
    CFLAGS=-DMCHP_VERSION="v3.20-Debian" ../gcc-4.0.2/gcc-4.0.2/configure --prefix=$C30INSTALL --target=pic30-coff --enable-languages=c
  • Then we have to touch c-parse.y cause (according to embeddedfreak) it doesn’t get generated correctly, so we need it to be recreated. I just followed the instructions and it worked.
    touch ../gcc-4.0.2/gcc-4.0.2/gcc/c-parse.y
  • Build it and install it (again, use sudo for make install if you have to).
    make
    make install
  • Link the binutils into GCC’s tool path so it can find them, and create a link to GCC itself so we don’t have to type the version number every time:
    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

Next Steps

The rest of the steps are just the same as for building v3.12.  I won’t repeat myself here, just check out my previous tutorial and follow the steps from Setup the non-free part onward.

:, , , ,

5 Comments for this entry

  • Billyonthemountain

    Hey thanks for the tutorial, very useful… wanted to give it a try it on the latest version (3.22) but your link for the gcc patches is broken… Could you fix it please ?

    Thanks

    Billy

  • matt

    Whoops, I didn’t have the right url in there. It’s fixed now.

    Let us know how it goes with v3.22.

    Cheers,
    Matt

  • Billyonthemountain

    Haven’t done any extensive testing but it compiles with the 3.20 patches (nor did I setup the non-free part)… :-)

    Tried to compile a small testcase but gcc couldn’t find cc1 nor as :
    “pic30-coff-gcc: installation problem, cannot exec ‘pic30-cc1′: No such file or directory” (same with pic30-as)
    ln -s $C30INSTALL/libexec/gcc/pic30-coff/4.0.3/pic30-coff-cc1 $C30INSTALL/libexec/gcc/pic30-coff/4.0.3/pic30-cc1 (same for as) did the trick…

  • matt

    Thanks for the feedback Billy.

    There was a bit of a delay between when I actually built the compiler and when I wrote the tutorial, and in that time I forgot about one of the files I had patched. It was config.gcc which is responsible for the program prefix (e.g. pic30-coff- or pic30- ). For some reason in the v3.20 sources they had hardcoded the prefix to pic30-. I have fixed this so that it will be pic30-coff- (or whatever binary type you choose). I have updated pic30-gcc-3.20.tar.bz2 with this patch now.

    Cheers

  • Kemp

    Build process confirmed to work for 3.23. The names for files on the Microchip website are slightly different now, but it’s fairly easy to spot what you need.

1 Trackback or Pingback for this entry

Leave a Reply

Pages