18f4550 and 18f2550 with Piklab and Ubuntu

Posted By Cantareus on August 14, 2009

I’ve been trying to compile some usb examples for my little 18F2550 micro-controller for the last few days and now I’ve finally got it working. Here’s a few things to watch out for.

Don’t try and port mcc18 code to hitech’s pic18 compiler. I tried without any success even trying to use examples other people had ported didn’t work at all.

Instead use Microchip’s MpLab C18 compiler under wine. Wine is a wrapper that lets you run Windows programs in Linux. Install wine using your package manager. There are some How To’s on the net for getting the c18 compiler to work with wine but I think they are old and they have many unnecessary steps. All I needed to do was install arial32.exe(search Google, download, right click “Open with wine…”) and download and install the latest MpLab C18 compiler.

When you select the C18 compiler in piklab use “configure toolchains” to tell piklab where to find everything. These are the paths I used:

Executable Directory :~/.wine/dosdevices/c:/MCC18/bin/
Header directory :~/.wine/dosdevices/c:/MCC18/h/
Linker directory :~/.wine/dosdevices/c:/MCC18/bin/LKR/
Library directory :~/.wine/dosdevices/c:/MCC18/lib/

Under “Configure compilation” there are a few things to change. piklab thinks the linker files for mplink are called <devicename>.lkr. To fix this change the linker configuration to Custom then change %LKR_NAME to %DEVICE_g.lkr.

The linker also needs _CRUNTIME defined so that it includes the correct libraries. Not sure why this isn’t defined already. Look in the .lkr files to see what I mean. You get errors like this if it isn’t:

Error – could not find definition of symbol ‘FSR2L’ in file ‘./mouse.o’.

Anyway just add /u_CRUNTIME to the linker parameters.

The usb examples that come with the Microchip Applications Library require a few extra c files to be compiled before they’ll run. If you don’t include these you’ll probably get an error like this:

Error – could not find definition of symbol ‘USBDeviceTasks’ in file ‘./mouse.o’.

They should be in

/home/<username>/.wine/dosdevices/c:/Microchip Solutions/Microchip/Usb

Just copy the relevant files into your project directory and add them to your piklab project.

If you try to compile one of the usb examples for the 18F2550 the HardwareProfile.h file wont find a demo board it can use. I renamed “HardwareProfile – PICDEM FSUSB.h” to “HardwareProfile.h” and got rid of all references to Port D.

If you’ve gotten this far you should be able to build the project and program your micro-controller. The pickit 2 programmer included with piklab doesn’t seem to work. I do get this warning saying it might not:

Connecting PICkit2 Firmware 2.x on USB Port with device 18F2550…
Firmware version is 2.32.0
The firmware version (2.32.0) is higher than the version tested with piklab (2.10.0). You may experience problems.

Instead I use pk2cmd. You can set up Piklab to program your chip using pk2cmd by selecting “Custom Programmer”

I hope this info is helpful to anyone else. If it is let me know.

HardwareProfile – PICDEM FSUSB.h

Comments

5 Responses to “18f4550 and 18f2550 with Piklab and Ubuntu”

  1. ususge says:

    very usefull info thanks…
    i was missing the CRUNTIME parameter but now everything works again with my Eclipse+Scons projects
    :]

  2. Liarod says:

    Thanks a lot!
    What a useful article!!!

  3. Ikis says:

    Grat tips! I had some trouble configuring piklab with mcc18. Folllowing your instructions it worked in the first attempt!
    Thanks

  4. Nicko says:

    Looks interesting. I am actually struggling with my ICD2 and 18F4520 chip. I tried to build the project without much success and I guess this post will be really helpful.
    Thanks, I’ll keep you informed

  5. do you post updates to facebook?

Leave a Reply