ElectricRock Blog

New C30 page, now with automated goodness

by matt on Mar.21, 2010, under Informational

I have just created a new page to put all my C30 related tutorials, etc. on. It can be found at http://www.electricrock.co.nz/blog/microchip-c30/.

The most notable update is that my previous C30 building tutorials are now deprecated in favor of a new bash script that does it automagically. Check out the page for more details.

:, ,

29 Comments for this entry

  • Luke

    Thank you so much for this resource. It is invaluable, but for some reason your script isn’t working for me. In the binutils phase of compiling I have an error at some point in the linking phase. This is probably just something that isn’t attached properly for the build environment, but I was wondering if there was a particular package beyond typical build tools and those mentioned in your build page for C30 v3.20?

  • matt

    Hi Luke,

    It is entirely possible I missed a necessary package from the dependencies as I haven’t built the compiler on a freshly installed system before. If you could paste the output from the link stage that’d probably help in tracking down the problem. In the meantime, I’ll try to replicate the problem on a fresh Ubuntu 9.10 install.

    Cheers

  • matt

    OK, just tried building on a fresh Ubuntu 9.10 install. I ran
    sudo aptitude install build-essential bison flex tofrodos wine checkinstall
    as per the instructions in the script and then ran the script (only as far as building binutils, as I understand this was where you had issues.) It seemed to build fine and didn’t come up with any obvious errors.

    Which distro are you running? If you are running something other than Ubuntu maybe there is a library that is not provided out of the box by your distro.

  • Luke

    I had gotten wine, when I loaded up checkinstall the error went away (although why check install affects the linking stage is beyond me). If I wipe /tmp/c30/ and run the script again the system runs until it reaches the wine install phase, prints out various wine errors, and simply says the install of the compiler failed on the prefix in /tmp/c30/non-free/drive_c/C30.

  • Luke

    The specific errors are as follows.

    fixme:system:SetProcessDPIAware stub!
    fixme:dwmapi:DwmIsCompositionEnabled 0x33cf24
    fixme:file:MoveFileWithProgressW MOVEFILE_WRITE_THROUGH unimplemented
    fixme:advapi:SetNamedSecurityInfoW L”C:\\windows\\system32\\gecko\\1.0.0\\wine_gecko\\components\xpti.dat” 1 536870916 (nil) (nil) 0x1a1f64 (nil)
    fixme:iphlpapi:NotifyAddrChange (Handle 0xa60e8d8,overlapped 0xa60e8e0): stub
    fixme:file:MoveFileWithProgressW MOVEFILE_WRITE_THROUGH unimplemented
    L”C:\\windows\\system32\\gecko\\1.0.0\\wine_gecko\\components\compreg.dat” 1 536870916 (nil) (nil) 0x1d8a4b4 (nil)
    wine: configuration in ‘/tmp/c30/non-free’ has been updated.
    Generating unattended install file.

    Running unattended install of /home/luke/Downloads/MPLABC30ComboLite_v3_23.exe
    (this might seem to hang, but it just takes a little hwile.)

    fixme:storage:StgCreateDocfile Storage share mod not implemented.
    fixme:reg:GetNativeSystemInfo (0x32284c) using GetSystemInfo()

    C30 Install in /tmp/c30/non-free/drive_c/C30 failed.

    then I’m dumped back to the prompt. This is just after mplabc30_3.23-1_i386.deb has been generated. I also noted, that the system says that that package has been installed, but dpkg -r mplabc30 indicates that it has not been installed yet.

  • matt

    My first guess re the wine issue is that that the installer doesn’t work on the stable version of wine that is installed by default in Ubuntu. I have actually been using the latest PPA version of wine (v1.1.41). Run
    sudo add-apt-repository ppa:ubuntu-wine/ppa
    sudo apt-get update
    sudo apt-get upgrade

    to install the latest version of wine and try again. Please let me know if it works, cause I will update my script.

    In terms of mplabc30 being installed, if you run apt-cache policy mplabc30 what does it show? Also, if you try running pic30-coff-gcc does it work?

  • Luke

    I had run the Wine install command as part of the install prior to the build as it was recommended in your 3.20 walkthrough. A rebuild after running it again just in case yielded no change in the output.

    apt-cache says that this time it was installed. It must have been a fluke from earlier that said it wasn’t.

  • Luke

    pic30-conf-gcc complains about not being able to use the linker flag -lpic30-coff but that’s probably just due to the fact that the last parts of the script weren’t able to do full clean up.

  • matt

    Strange, I don’t know what the problem is then. I suggest deleting /tmp/c30/non-free and then trying an attended install of MPLABC30ComboLite_v3_23.exe by running
    export WINEPREFIX=/tmp/c30/non-free
    wine $HOME/Downloads/MPLABC30ComboLite_v3_23.exe
    That you should hopefully give you a better idea of why it’s failing. If it works and you install to C:\C30 then you can just run the later lines of the install script to copy the files over, ie.

    export C30INSTALL=/usr/local # or whatever you set it to
    export SUDO_CMD=sudo

    $SUDO_CMD cp -r $WINEPREFIX/drive_c/C30/support $C30INSTALL/share/pic30-nonfree
    $SUDO_CMD cp -r $WINEPREFIX/drive_c/C30/include $C30INSTALL/share/pic30-nonfree
    $SUDO_CMD cp -r $WINEPREFIX/drive_c/C30/lib $C30INSTALL/share/pic30-nonfree
    $SUDO_CMD cp $WINEPREFIX/drive_c/C30/bin/c30_device.info $C30INSTALL/lib
    $SUDO_CMD ln -s $C30INSTALL/lib/c30_device.info $C30INSTALL/bin
    $SUDO_CMD ln -s $C30INSTALL/lib/c30_device.info $C30INSTALL/lib/gcc
    $SUDO_CMD ln -s $C30INSTALL/lib/c30_device.info $C30INSTALL/libexec/gcc/pic30-coff/4.0.3

    Or something like that.

  • Luke

    When I ran the wine command, A GUI opened up and an error box opened saying “the current version of the application could not be determined. The setup will now terminate.”

  • matt

    OK, I just tried it again and got that error too. Maybe it’s a wine regression because it used to work on my computer. Anyway, I’ll look into and let you know if I come up with a fix. A temporary fix is to run the installer on a Windows machine and just copy the necessary files.

  • matt

    Yes, it looks like this is a wine regression. If you remove wine 1.1.41 (apt-get remove wine1.2) and remove update-wine-ppa-karmic.list from /etc/apt/sources.list.d then reinstall wine it appears to work.

  • Nicolas

    Hello, thank you so much for your bash it’s perfect ! I built v3.23 on Ubuntu 10.04 with just a little tweak. The command dos2unix doesn’t work on 10.04 even if tofromdos is installed. I had to replace dos2unix by fromdos in the bash and it worked perfectly.

  • matt

    Great, thanks for the feedback. I will update the script for 10.04 in the next couple of days.

  • Nicolas

    Do you know how to compile a libgcc.a for pic30 ? I need it for sprintf and udivsi3.

  • matt

    Hi Nicolas,

    Sorry I can’t offer much help in the way of libgcc.a. I believe it is a part of the gcc distribution, and you can try to build it by changing into the build/gcc directory created by the build script and running make libgcc.a. However, for me this failed with an internal compiler.

    Unfortunately I don’t have the time to look into this further right now.

    Cheers,
    Matt

  • Peter

    With only a little pain got everything to install properly using the build-c30.sh script. However it won’t compile the simple test.c code and replies with
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/h/p30f4013.h:2121: error: syntax error before ‘__attribute__’
    or similar for all lines in the header file

    and

    test.c:6: error: syntax error before ‘}’ token
    Maybe a dos to unix conversion problem?

    Using: Ubuntu 9.10 with a 64 bit intel processor
    (the amd64 architecture?)
    Thanks for your help

  • matt

    Hi Peter,

    That sounds strange. What issues did you run into during the install?

    I have tried compiling the test.c file again on an Ubuntu 9.10 32bit VM and under 10.04 on amd64 hardware, and it worked fine on both.

    Which version of the C30 did you build (3.23?) and which version of the patches did you use (v01?).

    ~ Matt

  • Peter

    Matt: Thanks for the quick response.
    First I completely uninstalled anything remotely related to Microchip including MPlab IDE in Wine. Then got fresh downloads on 5/5/10 of
    mplabalc30v3_23.tar.gz
    mplabc30v3_32.tar.gz
    MPLABC30comboLite_V3_23.exe
    pic30-binutils-v01.tar.bz2
    pic30-gcc-v01.tar.bz2
    edited build-c30.sh to reflect where I filed my downloads under $HOME and corrected the typo in “while” near the end. And ran it. The first time through it baulked at my choice of “x86″ architecture but then I remembered the Ubuntu distro is the amd64 architecture. Ran the second time through and sucessfully installed the debian packages. Freshly type in using gedit – not copied – the test.c file as
    #include

    int main()
    {
    while(1);
    }
    Even checked Kernighan and Richie to make sure the syntax was correct. I get a few dozen syntax errors from the header file which I had not edited. Thanks again, hope this helps and I do appreciate your work.

  • matt

    Hmm…. that’s strange. As far as I can tell, your setup is basically the same as what I have and unfortunately I haven’t been able to reproduce the error.

    I have uploaded a test script to http://www.electricrock.co.nz/c30/test-30.sh. It’s basically the same as what you’ve been doing, but with verbose output from pic30-coff-gcc. Try running that and, if it fails, post the log file that it generates (/tmp/test-c30.log) and we’ll see if it gives any clues.

  • Peter

    Matt:
    Below is the result. It gives the same errors if I change the included header file to some other existing header file. If the include statement is dropped I only get the error from the main code.

    Look forward to hearing from you.

    Compile failed with error code 1

    Compile log:
    Target: pic30-coff
    Configured with: ../gcc-4.0.2/gcc-4.0.2/configure –prefix=/usr/local –target=pic30-coff –enable-languages=c
    Thread model: single
    gcc version 4.0.3 (dsPIC30, Microchip v3.23-Debian) Build date: May 6 2010
    /usr/local/bin/../libexec/gcc/pic30-coff/4.0.3/pic30-coff-cc1 -quiet -v -iprefix /usr/local/bin/../lib/gcc/pic30-coff/4.0.3/ /tmp/test-c30.c -mresource=/usr/local/bin/../lib/gcc/c30_device.info -quiet -dumpbase test-c30.c -mcpu=30f4013 -auxbase test-c30 -version -o /tmp/ccBn5zxd.s
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/sys-include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/include”
    ignoring duplicate directory “/usr/local/lib/gcc/pic30-coff/4.0.3/include”
    ignoring nonexistent directory “/usr/local/lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/sys-include”
    ignoring nonexistent directory “/usr/local/lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/generic/h”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/dsPIC30F/h”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/peripheral_30F_24H_33F”
    #include “…” search starts here:
    #include search starts here:
    /usr/local/bin/../lib/gcc/pic30-coff/4.0.3/include
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/include
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/generic/h
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/h
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/peripheral_30F_24H_33F
    End of search list.
    GNU C version 4.0.3 (dsPIC30, Microchip v3.23-Debian) (0) Build date: May 6 2010 (pic30-coff)
    compiled by GNU C version 4.4.1.
    GGC heuristics: –param ggc-min-expand=100 –param ggc-min-heapsize=131072
    In file included from /tmp/test-c30.c:1:
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/h/p30f4013.h:71: error: syntax error before ‘__attribute__’

    (edited: lots of lines removed due to size)

    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/h/p30f4013.h:2121: error: syntax error before ‘__attribute__’
    /tmp/test-c30.c: In function ‘main’:
    /tmp/test-c30.c:6: error: syntax error before ‘}’ token

  • matt

    Strange, apart from the errors the log is basically identical to the one generated by the working compiler on my computer. So I’m still at a loss as to why it doesn’t work for you. I’ll give it some more thought.

  • Peter

    Matt:
    Let me know and thanks for the effort. I’ll probably try an upgrade to 10.04 LTS and see if that helps. Guess it’s back to windoz in the meantime.
    Peter

  • Dan

    Hi Matt,
    I used your build script (with a few minor modifications) to install the C30 toolchain on OS X. Unfortunately, I get the same error as Peter when I try to compile anything. Running your test-30.sh script gives the following:

    Target: pic30-coff
    Configured with: ../gcc-4.0.2/gcc-4.0.2/configure –prefix=/usr/local –target=pic30-coff –enable-languages=c
    Thread model: single
    gcc version 4.0.3 (dsPIC30, Microchip v3.23-OSX) Build date: May 22 2010
    /usr/local/bin/../libexec/gcc/pic30-coff/4.0.3/pic30-coff-cc1 -quiet -v -iprefix /usr/local/bin/../lib/gcc/pic30-coff/4.0.3/ /tmp/test-c30.c -mresource=/usr/local/bin/../lib/gcc/c30_device.info -quiet -dumpbase test-c30.c -mcpu=30f4013 -auxbase test-c30 -version -o /var/tmp//ccMazmtx.s
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/sys-include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/include”
    ignoring duplicate directory “/usr/local/lib/gcc/pic30-coff/4.0.3/include”
    ignoring nonexistent directory “/usr/local/lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/sys-include”
    ignoring nonexistent directory “/usr/local/lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/generic/h”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/dsPIC30F/h”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/peripheral_30F_24H_33F”
    #include “…” search starts here:
    #include search starts here:
    /usr/local/bin/../lib/gcc/pic30-coff/4.0.3/include
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/include
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/generic/h
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/h
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/peripheral_30F_24H_33F
    End of search list.
    GNU C version 4.0.3 (dsPIC30, Microchip v3.23-OSX) (b) Build date: May 22 2010 (pic30-coff)
    compiled by GNU C version 4.2.1 (Apple Inc. build 5659).
    GGC heuristics: –param ggc-min-expand=100 –param ggc-min-heapsize=131072
    In file included from /tmp/test-c30.c:1:
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/h/p30f4013.h:71: error: syntax error before ‘__attribute__’

    #I removed many identical errors

    /tmp/test-c30.c: In function ‘main’:
    /tmp/test-c30.c:6: error: syntax error before ‘}’ token

    Do you also get the ‘ignoring nonexistent directory’ output when you run this script on your working system?

  • matt

    Hi Dan. It sounds like there are a few people that are having this issue, but I still have no idea what’s causing it. In reply to your question, I also get the `ignoring nonexistent’ directory output–in fact the output I get is more or less identical to yours (aside from the version numbers). For comparison’s sake here is the output I get after a successful run:

    Using built-in specs.
    Target: pic30-coff
    Configured with: ../gcc-4.0.2/gcc-4.0.2/configure –prefix=/usr/local –target=pic30-coff –enable-languages=c
    Thread model: single
    gcc version 4.0.3 (dsPIC30, Microchip v3.23-Debian) Build date: May 13 2010
    /usr/local/bin/../libexec/gcc/pic30-coff/4.0.3/pic30-coff-cc1 -quiet -v -iprefix /usr/local/bin/../lib/gcc/pic30-coff/4.0.3/ /tmp/test-c30.c -mresource=/usr/local/bin/../lib/gcc/c30_device.info -quiet -dumpbase test-c30.c -mcpu=30f4013 -auxbase test-c30 -version -o /tmp/ccqXXk6I.s
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/sys-include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/include”
    ignoring duplicate directory “/usr/local/lib/gcc/pic30-coff/4.0.3/include”
    ignoring nonexistent directory “/usr/local/lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/sys-include”
    ignoring nonexistent directory “/usr/local/lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/include”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/generic/h”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/dsPIC30F/h”
    ignoring nonexistent directory “/usr/local/bin/../lib/gcc/../../pic30-nonfree/support/peripheral_30F_24H_33F”
    #include “…” search starts here:
    #include search starts here:
    /usr/local/bin/../lib/gcc/pic30-coff/4.0.3/include
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/include
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/generic/h
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/h
    /usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/peripheral_30F_24H_33F
    End of search list.
    GNU C version 4.0.3 (dsPIC30, Microchip v3.23-Debian) (0) Build date: May 13 2010 (pic30-coff)
    compiled by GNU C version 4.4.3.
    GGC heuristics: –param ggc-min-expand=100 –param ggc-min-heapsize=131072
    /usr/local/bin/../libexec/gcc/pic30-coff/4.0.3/pic30-coff-as –relax -p30f4013 -o /tmp/ccn9OD62.o /tmp/ccqXXk6I.s
    /usr/local/bin/../libexec/gcc/pic30-coff/4.0.3/pic30-coff-ld -p30f4013 -o /tmp/test-c30.coff -L/usr/local/bin/../lib/gcc/pic30-coff/4.0.3 -L/usr/local/bin/../lib/gcc -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/lib -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/generic/gld -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/lib/PIC24F -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/PIC24F/gld -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/lib/PIC24H -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/PIC24H/gld -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC30F/gld -L/usr/local/bin/../lib/gcc/../../share/pic30-nonfree/support/dsPIC33F/gld -L/usr/local/lib/gcc/pic30-coff/4.0.3 -L/usr/local/bin/../lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/lib -L/usr/local/lib/gcc/pic30-coff/4.0.3/../../../../pic30-coff/lib /tmp/ccn9OD62.o -start-group -lpic30-coff -lm-coff -lc-coff -end-group

  • Peter

    All:
    I solved my problem although my solution needs confirmation.

    Ubunutu 9.10 uses the link to the library
    /lib64/libc.so.6 -> /lib64/libc-2.10.1.so
    and the compile fails. The Synaptic manager in Ubuntu 9.10 wont let you upgrade to latest version libc-2.11.1.so. But when I upgraded to Ubuntu 10.04 LTS the link was
    /lib64/libc.so.6 -> /lib64/libc-2.11.1.so
    and everything compiled just fine.

    So apparently there are some incompatibilities in the libc files between the two Ubuntu versions and if you have a 64 bit machine you must(??) upgrade to 10.04 LTS. I noted that the link to the 32 bit library /lib/libc.so.6 -> libc-2.11.1.so also changed but in my ignorance I assume that this is not an issue on my machine.

    Sorry for being tardy in replying. Peter

  • Jon Wash

    Thanks so much for this resource!

  • AMX

    Hi, I build the 3.23 binutils following your instructions and had to modify the resource.c and cpu-pic30.c in order to get rid of some segfault. Anyway, my version doesn’t seem to know ihex format. Does the pic30-coff target not support ihex?
    Otherwise I seem to get valid output, I checked it with “pic30-coff-objdump -D”.

  • AMX

    Okay, I found a solution:

    in “acme/bfd/targets.c” I removed the “#ifndef”:
    //#ifndef PIC30
    /* Always support S-records, for convenience. */
    &srec_vec,
    &symbolsrec_vec,
    /* And tekhex */
    &tekhex_vec,
    /* Likewise for binary output. */
    &binary_vec,
    /* Likewise for ihex. */
    &ihex_vec,
    //#endif

Leave a Reply