ElectricRock Blog

Using C30 with Piklab

by matt on Aug.31, 2009, under How To

This post follows on from my previous post on building Microchip’s C compiler for PIC24 and dsPIC (C30) onUbuntuPiklab 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.

Configuring the Toolchain

NB: The following assumes <C30-base> is the directory where C30 was installed (if you followed my previous tutorial this will be whatever you set for the C30INSTALL environment variable).

  • Open up Piklab and go to Settings->Configure Toolchains…
  • In the Configure Toolchains window select PIC30 Toolchain from the sidebar.
  • Fill out the fields as follows:
    • Executable directory<C30-base>/bin
    • Header directory<C30-base>/pic30-nonfree/support/dsPIC30F/h/ (assuming you are using C30 to compile for dsPIC30F series–I haven’t tried any other series, so YMMV).
    • Linker script directory<C30-base>/pic30-nonfree/support/dsPIC30F/gld/
    • Library directory<C30-base>/pic30-nonfree/lib/
  • The other fields can be left as the default.

Configuring the Project

For each project you will also have to do some configuration. After creating a new project, bring up the Project Options window (Project->Project Options…), and fill in as follows:

  • Toolchain tab
    • Make sure PIC30 Toolchain is the active toolchain.
  • Compiler tab
    • In the Custom options field enter: -mresource=<C30-base>/info/c30_device.info
  • Linker tab
    • In the Custom libraries field enter: -lpic30

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’t work for you, or if you have had some luck using a different family of PICs with C30, then please leave a comment.

:, , , ,

27 Comments for this entry

  • Abhijit Biswas

    Thanks for this information. I was trying to make this thing working for a long time. I am using PIC30F4011 and with this tips it worked perfectly. Only I have changed “/info/c30_device.info” to “/bin/c30_device.info”.

    I am using my own handmade parallel port programmer for dsPIC30Fxxxx and dspicprg and dspicdmp utilities. Now I am quite happy because everything is working perfectly in Linux (F11).

  • student

    Hi, I tryed to do your configuration but …
    I installed the microchip compiler for p30 using wine on ubuntu 9.04…

    When I try to configure the toolchain … he recognize correctly the exe in …/bin/bin and not in /bin… anyway

    the other 3 voice below… include, linker etc…
    I try to set it up but… when I see again the configuration it are changed in the same /bin…

    AHHH why? Do I make some mistake?

    Thanks in advice.

  • matt

    Hi, if you are using the windows version of c30 under wine (ie haven’t built a linux native version from the microchip sources) then I’m afraid I can’t offer any help because I have never tried this myself. Try using a native version (e.g. by following these instructions http://www.electricrock.co.nz/blog/2009/08/installing-microchips-c-compiler-for-pic24-mcus-and-dspic-dscs-c30-on-ubuntu-9-04 )

  • Netfoot

    Hi!

    I built the C30 tools *exactly* as described in your articles, except I used v3.22 instead of v3.20 as described. After setting up the toolchain in PikLab by again following your instructions *precisely*, I can now compile but get the following message when I press F8:

    /home/netfoot/pic30/bin/pic30-coff-ld:built in linker script:6: syntax error
    *** Exited with status: 1 ***

    I’d really like to get this to work, so if anyone has any tips toward success…

  • matt

    Hmmm… I think I have encountered this problem before, but it was a while ago. From memory I just copied the appropriate linker script into my project directory then added it to the project. Then you can edit it and fix whatever is causing issues on line 6. If this doesn’t help let me know, including which linker script is giving you issues, and I’ll look into it further. Cheers.

  • Netfoot

    I added -verbose to the linker options which (according to ‘man ld’) should display the linker script. When I build, I now get:

    /home/netfoot/pic30/bin/pic30-coff-ld:built in linker script:6: syntax error
    GNU ld version 2.14 – Microchip v3.22 (A) ÷·C;LCA Build date: Jan-16-2010
    *** Exited with status: 1 ***

    No sign of the linker script but note the strange symbols afer the (A). building twice more, I get:

    /home/netfoot/pic30/bin/pic30-coff-ld:built in linker script:6: syntax error
    GNU ld version 2.14 – Microchip v3.22 (A) ¸C;LCA Build date: Jan-16-2010
    Supported emulations:
    pic30_coff
    *** Exited with status: 1 ***

    and:

    /home/netfoot/pic30/bin/pic30-coff-ld:built in linker script:6: syntax error
    GNU ld version 2.14 – Microchip v3.22 (A) î·C;LCA Build date: Jan-16-2010
    Supported emulations:
    pic30_coff
    *** Exited with status: 1 ***

    More (but *different*) strange symbols. I also added a new line #1 to every *.gld file in the tree, guaranteed to produce a syntax error, yet the error remains on line 6.

    Is the linker trying to use some non-existent linker script? I am at a loss here now!

  • matt

    I would assume the linker has a default linker script built into it that it falls back on when it isn’t given, and can’t find, any other linker script. Did you try explicitly adding the appropriate linker script to the project? I think that is what fixed it for me in the past. If that’s that case it might be something to do with the path to the linker scripts being set incorrectly.

    Which device are you trying to build for? Also, it would help if I could see the command line that piklab is using to invoke the linker (you may have to enable extra debug messages by right clicking in the ‘Compile Log’ window).

  • Netfoot

    I’m trying to compile for the dsPIC30F4011 using code retrieved from Google Code for a project which is operational elsewhere. PikLab generates the .s and .o files and then the linker runs as follows:

    /home/netfoot/pic30/bin/pic30-coff-ld -Map MatrixPilot.map -oMatrixPilot.cof -L/home/netfoot/Desktop/UAV devboard/MatrixPilot-2_0_1/ -L/home/netfoot/pic30/pic30-nonfree/lib/ -verbose altitudeCntrl.o analog2digital.o background.o cameraCntrl.o estYawDrift.o gpsParseCommon.o gpsParseSTD.o gpsParseUBX.o main.o mathlibNAV.o navigate.o pitchCntrl.o radioIn.o rmat.o rollCntrl.o serialIO.o servoMix.o servoOut.o states.o variables.o waypoints.o yawCntrl.o -lpic30

    This gives the output you have seen, example:

    /home/netfoot/pic30/bin/pic30-coff-ld:built in linker script:6: syntax error
    GNU ld version 2.14 – Microchip v3.22 (A) ¸C;LCA Build date: Jan-16-2010
    Supported emulations:
    pic30_coff
    *** Exited with status: 1 ***

    I copied the default p30f4011.gld script into the project directory and set it as the script to use. The linker command then becomes:

    /home/netfoot/pic30/bin/pic30-coff-ld -Map MatrixPilot.map -oMatrixPilot.cof -L/home/netfoot/Desktop/UAV devboard/MatrixPilot-2_0_1/ -L/home/netfoot/pic30/pic30-nonfree/lib/ -T/home/netfoot/Desktop/UAV devboard/MatrixPilot-2_0_1/p30f4011.gld -verbose altitudeCntrl.o analog2digital.o background.o cameraCntrl.o estYawDrift.o gpsParseCommon.o gpsParseSTD.o gpsParseUBX.o main.o mathlibNAV.o navigate.o pitchCntrl.o radioIn.o rmat.o rollCntrl.o serialIO.o servoMix.o servoOut.o states.o variables.o waypoints.o yawCntrl.o -lpic30

    Note the -T option! The output now becomes:

    /home/netfoot/pic30/bin/pic30-coff-ld:/home/netfoot/Desktop/UAV devboard/MatrixPilot-2_0_1/p30f4011.gld:6: syntax error
    *** Exited with status: 1 ***

    Adding 5 blank lines to the top of that script changes the error to line 11. The original line 6 is as follows:

    CRT0_STARTUP(crt0_standard.o)

    I’m at a loss.

  • matt

    OK, well that narrows it down a bit. What version of the non-free part (ie headers/libraries/linker scripts) do you have installed? It may be that you have different versions of free (the part you compiled yourself) and non-free installed. The reason I wrote my tutorial for v3.20 (even though v3.22 sources were available) was that the highest available version of the academic edition was v3.20.

  • matt

    Another possibility is the fact that the linker script has DOS line endings. Try running dos2unix on the linker script you copied to your project dir (ie ‘dos2unix p30f4011.gld’).

  • Netfoot

    The trial version I installed was “MPLAB C Compiler for dsPIC v3.22 Standard-Eval Version” which came in a file called MPLABCdsPICStdEval_v3_22.exe. All the other files which I installed were also v3.22 with the exception of the patches, for which the most recent version I could find was v3.20 as per your documentation. I ran the patches one by one and they all applied without error. Might there be something in one of the patches that is version-specific? I’ve read through the .diff files and nothing obvious leaps out at me, although remove-omf.diff is something to do with the linker. Still, I am hardly an expert and the problem might not be obvious to the uneducated anyway.

    I already converted the script from CRLF to NL so that isn’t the cause of the error.

  • matt

    I just went through and built v3.22 of the compiler (using the lite version for the non-free part, ie MPLABC30ComboLite_v3_22.exe). I then used it to build a 30F4013 project and it seems fine. Off hand I can’t think of anything else that could be causing issues. Clutching at straws here, but have you tried either opening the linker script in an editor such as emacs and checking for any hidden characters that shouldn’t be there, or removing the offending line and seeing what happens?

  • Netfoot

    I did a hex dump on the file and examined it for strange, invisible characters that might be generating the error, but saw none.

    I commented out lines 6 and 7, but continued to get an error. 8 was blank, but after commenting out 9, the link process went considerably further before finding several new warnings/errors culminating is another

    *** Exited with status: 1 ***

    New warnings/errors include:

    /home/netfoor/pic30/bin/pic30-coff-ld: Warning: linker script did not specify CRT0_STARTUP file, default for this device: crt0_standard.o

    CRT0_STARTUP was specified in line 6 which was commented out because it generated a syntax error!

    /home/netfoot/Desktop/UAV devboard/MatrixPilot-2_0_1/p30f4011.gld:1685: undefined symbol `__reset’ referenced in expression

    At this point I think it’s obvious I’ve totally hosed the installation on my end. Unless you can suggest a better alternative, I will rm the lot and start again, using the ‘lite’ version instead of the ‘Standard-Eval’ version.

  • Netfoot

    Ok, I rebuilt from scratch using the ‘Lite’ version of the non-free compiler and I’m still getting:

    /home/netfoot/pic30/bin/pic30-coff-ld:/home/netfoot/Desktop/UAV devboard/MatrixPilot-2_0_1/p30f4011.gld:6: syntax error
    *** Exited with status: 1 ***

    Now what? :-(

  • Netfoot

    I’ve rolled back to v3.20 and reinstalled. In fact I’ve done it so many times I now have a bash script to do the heavy lifting! Still getting a syntax error on line 6 of the linker script.

    Only one more question: The install instructions set MCHP_VERSION=”v3.12-Debian” whereas I only use “v3.20″ (no -Debian since I don’t use Debian). Is that likely to be significant?

  • matt

    Sorry to hear it’s been such a mission for you bro. I’m really stumped as to what the problem is.

    As for the “-Debian” thing, I think that could explain why you see those funny characters after the version number when you run it. I don’t think it matters what’s after the dash, there needs to be something there. Have a look at line 277 onwards of acme/bfd/cpu-pic30.c in binutils. Just having glanced at it quickly, it looks to me like it doesn’t have a check in place to make sure that there is something after the dash, overrunning the end of the string when there isn’t anything there (explaining those funny characters you got).

    I don’t see why this would have an impact on the linker script, but I suggest you try compiling again with something after the dash (not necessarily “Debian”). When I get some time I will incorporate a fix for this in the patches.

  • Netfoot

    Using “v3.20-Slackware” gets rid of the strange symbols (the word “Slackware” appears instead). Unfortunately, it doesn’t get rid of the syntax error in line 6…

  • Netfoot

    Ok, Matt! With help from some friends (thanks Adam & Peter) I’ve made some progress by adding

    find . -name “*.y” -o -name “*.l” -exec touch ‘{}’ ‘;’

    just before making binutils. Still got some errors to deal with (undefined references due to a missing library, it looks like), but not script syntax related.

  • matt

    Sweet, glad to hear you’ve made progress :D . When you say undefined references, do you mean within the PIC peripheral libraries? I found when I was trying to use I2C with the 30F4013, that support for it was missing from the library. If this is the case, they supply the sources so you can either recompile the library yourself (by running a two hundred thousand line DOS .BAT script :P — I was going to write a makefile but never got around to it), or just include the appropriate files into your project.

    Anyway, good luck with your project. I’m gonna be away from the computer for a couple of days but keep us posted with your progress. Cheers

  • Netfoot

    Matt, I can’t seem to find the libgcc library. Any suggestions?

  • matt

    Hey, sorry about the delay replying, I am in the US attending a conference. Not sure about libgcc, I have never had issues with it. Do you need it to build the c30 compiler, or to build firmware with the c30 compiler?

    Also, on a side node I found out how I solved previously solved the syntax error in the linker scripts. I was just looking through an old project, in which I had copied over the linker script and had just deleted the two CRT0_STARTUP and CRT1_STARTUP lines ;) .

  • Kemp

    Compiling for PIC24F seems to work fine with instructions as given and v3.23 of Microchip’s side of things. Will report back on programming soon.

  • Kemp

    Scratch that, I’m getting that default linker script error as posted by someone else above. v3.23 of everything with the Lite (academic) compiler. Also occurs with the the p24FJ64GA002.gld linker script selected instead of the default one. Did anyone find a consistently working resolution for this?

  • Chris

    Kemp, I just got it to work using the above instructions. You need to rebuild binutils. You can just do a make clean, then run the command supplied by
    netfoot above:

    find . -name “*.y” -o -name “*.l” -exec touch ‘{}’ ‘;’

    When I copied and pasted it, it messed up the quotes, so make sure it’s typed in correctly. Next, make and make install. Revert any changes you made to the linker script. It worked for me at this point:

    pic30-coff-gcc -mcpu=24FJ128GA010 -mresource=./pic30/info/c30_device.info ./test.c

    Chris

  • Kemp

    I’ve rebuilt using the new command before making binutils, but I’m now getting undefined references to PORTB and all of the I2C1* sort-of-variables. I have -I/home/kemp/pic30/pic30-nonfree/support/PIC24F/h/ in the GCC calls (that’s the PIC I’m targetting) but the error occurs when linking. It worked prior to the rebuild. I’m wondering if this is a similar issue to the one Netfoot had after rebuilding.

  • Nicolas

    Do you know how to resolve the problem of encoding in Piklab ? It always prints strange characters in the console of Piklab even though when I use directly pic30-coff-gcc it prints fine. I suspect a problem of encoding (UTF-8 …).

  • Justin

    For the ‘__reset’ error make sure you include the following libraries -lpic30-coff -lm-coff -lc-coff

1 Trackback or Pingback for this entry

Leave a Reply