Saturday, May 21, 2011

Installing MPLABX on Ubuntu 11.04

As promised these are the instructions for installing MPLABX on Ubuntu Linux. Nothing is really too tricky just a few gotchas along the way that hopefully these instructions will help you avoid. These instructions were performed on a fresh install of Ubuntu 11.04 but they should work on previous versions of Ubuntu and even other Linux distros. If you know of differences or tips for other environments please send them in and I'll post them here. NOTE: These instructions pertain to a 32-bit installation of Ubuntu.

Get the Files

Before we do anything we'll need the files from Microchip. Go to http://ww1.microchip.com/downloads/mplab/X_Beta/index.html and accept the license agreement and you'll be taken to the download page.
  1. Select the platform of Linux
  2. Select the items you want to download and install. I chose:
    • MPLAB IDE X
    • MPLAB C18 Lite Compiler for PIC18 MCUs
    • HI-TECH C Lite Compiler for PIC18 MCUs
    • HI-TECH C Lite Compiler for PIC10/12/18 MCUs
  3. Click Download Now and it will start 4 separate downloads.

Install Java

MPLAB X requires Java to be installed in order to run. To install Java in my Ubuntu environment I ran the following commands from a terminal window. You can find the full instructions at http://www.multimediaboom.com/how-to-install-java-in-ubuntu-11-04-natty-narwhal-ppa/

sudo add-apt-repository ppa:ferramroberto/java


sudo apt-get update


sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

With java installed we can begin installing pieces of MPLAB. I decided to install the compilers first but don't know if that's required.

Open a terminal window and browse to the folder where you downloaded the MPLAB files. Before you can run any of the installers you will need to verify that they have execute permissions. Execute the following commands in the terminal window:

chmod 755 mplabc18.bin


chmod 755 mplabx-ide-beta60-linux-32-bit-installer.bin


chmod 755 picc-18-pro-linux.run


chmod 755 picc-pro-linux.run


Install the Compilers

C18

Enter the following command:

sudo ./mplabc18.bin


An installer will launch. Follow the prompts through. Nothing special here.

HI-TECH for PIC18

sudo ./picc-18-pro-linux.run


This is a more traditional linux install script and will have you read the license agreement in the terminal window. Hit enter to scroll down through that and accept it at the end.

After the license agreement it will ask you where you want to install the compiler and suggests a path of /usr/hitech/picc-18/pro/9.63PL3. I didn't feel like I needed the pro layer in there so I just used /usr/hitech/picc-18/9.63PL3. It will then prompt you to enter the serial number, "demo", or "lite". Type "lite" and hit Enter. The install will finish.

HI-TECH for other PICs

sudo ./picc-pro-linux.run

This install is practically identical to the one for PIC18 devices. The only thing different is the install path. I used /usr/hitech/picc/9.80a. You're free to use whatever you want. Now that the compilers are installed we're ready to install MPLABX.

Installing MPLABX

From the terminal window run:

sudo ./mplabx-ide-beta60-linux-32-bit-installer.bin


An installer will launch. I accepted all of the defaults and let it install. When it's done you will get a message saying you will need to reboot your system for the changes to take affect. In reading the Microchip forums this was suggested because certain USB programmers may not work until you do so. However, I was able to do:

sudo restart udev


and have MPLABX correctly recognize my Pickit 3. You may or may not need a reboot.

With MPLABX installed we need to make it aware of the HI-TECH compilers. For some reason it recognizes C18 right out of the box but not the HI-TECH ones.
  1. Launch MPLABX
  2. Go to Tools->Options
  3. On the Build Tools tab click Add under the Toolchain box.
  4. Browse to the path of the compilers and MPLABX should detect them. I was not able to get it to recognize the PICC-18 compiler. If anyone has any luck with that let me know.
Once that is finished we are ready to test things out. I was fortunate because I have two projects out on github that I could pull down and use for testing. One will test that the C18 compiler is working correctly and the other will test the HI-TECH compiler for non-PIC18 devices.

If you don't have git installed I suggest you do that now. I won't cover the instructions for that here because there is no lack of documentation for it online. Just google "install git on Ubuntu."

Compile EmbeddedFun

The EmbeddedFun project uses the C18 compiler so we can use it to test whether everything is set up properly. Pull that project down from github into a directory of your choosing.

git clone git@github.com:<username>/EmbeddedFun.git

I've already updated the project to follow the new MPLABX layout of files. There are no longer .mcp files with MPLABX and builds are done with makefiles.
  1. Launch MPLABX.
  2. Go to File->Open Project
  3. Browse to the firmware folder of the EmbeddedFun project and select the make object and click Open Project
  4. Test your installation by performing a "Clean and Build" action.

Compile FMBomb

The EmbeddedFun project uses the C18 compiler so we've tested the installation of that but we haven't tested the installation of the HI-TECH compiler. Well, we're in luck because that's what the FMBomb project uses so let's pull that project down.

git clone git@github.com:<username>/FMBomb.git

Open the FMBomb project in MPLABX.

One thing I had to change in the Project Properties to make the HITECH compiler work was to remove the PRO option. To do so select your project in MPLABX and go to File->Project Properties. Expand the Conf: [default] section and the HI-TECH PICC section and select Compiler. Select Operation from the dropdown and change the Operation Mode to "Lite".

Now try to build the project. Everything should be working and you should be all set to create your own projects.

8 comments:

  1. I'm also getting ready to install MPLAB X on Ubuntu 11.04 right now so thanks for the post.

    Is your USB programmer working? Everywhere else I have read seems to indicate that you need the 32 bit version of the JRE to get the programmers to work. It seems however, that you only installed the standard 64 bit version or are you running this on a 32 bit install of Ubuntu?

    I was actually searching for the best way to install the 32 bit version of Java on a 64 bit system when I came across this post.

    -Eric

    ReplyDelete
  2. I actually did a straight 32 bit install of everything. Thanks for pointing that out, I'll update the post to reflect that. Unfortunately that means that I can't offer much help on the 32 bit JRE situation. My Pickit3 is working great with the 32 bit setup though. When you figure it out send me a note and I'll post the info here.

    ReplyDelete
  3. Okay, as with a lot of things, this turns out to be much easier than I had originally feared it would be once I figured everything out.

    First, you need to install the Sun(Oracle) 32bit JRE. This is assuming a you have a 64bit install of 11.04 and so some 64bit JRE installed. There is actually already a package to do this. In Synaptic Package Manager type "sun-java6" in the quick filter field. The package you want is the ia32-sun-java6-bin so, select and then install this package.

    The second part is configuring MPLAB X to use the 32bit JRE instead of the system default Java which you will want to leave set to a 64bit JRE. (Use "sudo update-alternatives --config java" to set the default.) The hint for this part came from:
    http://elco.crsndoo.com/wordpress/2011/03/how-to-make-mplab-x-work-properly-on-64bit-linux/

    For Ubuntu and the ia32-sun-java6-bin package we need slightly different paths than shown. So, create a shell script that contains the following:

    #!/bin/sh
    JAVA_HOME=/usr/lib/jvm/ia32-java-6-sun
    PATH=/usr/lib/jvm/ia32-java-6-sun/bin:$PATH
    /opt/microchip/mplabx/mplab_ide/bin/mplab_ide

    Then make it executable and change the launcher to point to this script.

    MPLAB X now sees my ICD3.


    -Eric

    ReplyDelete
  4. Awesome, thanks for the info. I'll add it to the post. Glad you got it working.

    ReplyDelete
  5. I've installed mplabx on ubuntu 11.04 but when I try to build my project I got this error:

    Error: File not found - /opt/microchip/mplabx/mpasmx/8bit_device.info

    I didn't install any C compiler since I do not need it. Currently I am using mpasmx since I need work with assemble code.

    Does anyone have a clue of what's going on here? Thanks.

    ReplyDelete
  6. irving, not sure how helpful this would be but I found this. http://www.microchip.com/forums/tm.aspx?m=592671&mpage=1&tree=true Seems like a missing file is causing the error. If you find an answer post it here in case others are having similar issues. Thanks.

    ReplyDelete
  7. Thanks a lot K-Sid!! I can finally develop codes with pickit3, although I have MPlab Beta 7.12 .

    Good tuto!

    I know it is probably too late but for Irving Vladimir, try to download MPLAB C18 Lite Compiler for PIC18 MCUs then install it somewhere on your computer. Take the 8bit_device.info and paste it in your /opt/microchip/mplabx/mpasmx/ . Or install directly MPLAB C18 Lite Compiler for PIC18 MCUs in your /opt/microchip .

    ReplyDelete
  8. Thanks for the comment and thanks for the tip on irving's post.

    ReplyDelete

Keep it clean and civil. That's all I ask.