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.

Saturday, May 14, 2011

MPLAB X with Ubuntu

Well, first of all I'm back....I think. I haven't posted in a while because I've been busy on some side projects for pay which, understandably, take precedence over this fun stuff. Gotta put that food on the table. Anyway, I've been dying to get back on this project and have had tons of ideas swimming around in my head. I'm hoping to spend a lot more time working on this now that most of my side projects have just about wrapped up.

On the Ubuntu Kick

So about 6 months ago I gave linux another twirl. I've tried it several times over the last decade and have had fun but never felt is was practical to switch from Windows. Well, Ubuntu 10 changed my mind. I created an Ubuntu image in a virtual machine to work on a Rails website and was instantly hooked. If you haven't tried Linux in a few years it's worth taking another look. I've since switched my family PC over to Ubuntu and, believe it or not, it was fairly smooth with the wife and kids. I've been thinking about making the complete switch on my development machines but haven't been able to take the plunge yet.

New Dev Machine

Why am I telling you all of this? Currently I do all of my hardware development and chip programming from a 2002 Toshiba Satellite Laptop running XP. Seeing how my new "thing" is linux and I'm just getting back into the sensor project I wanted to see if I could set up a complete hardware dev machine with Ubuntu. Enter MPLAB X which has downloads for Linux distros so you don't even need to use Wine. After a few hours of googling and fiddling with Ubuntu 11.04 I've successfully pulled down the EmbeddedFun project from github, compiled it, and programmed a chip with the Pickit3 all from a 7 year old P4 630MB RAM frankenstein PC running Ubuntu. Perhaps mostly for my own documentation purposes I'm going to do a post with the steps in the next few days. Windows is great but seriously, we're not doing anything Windows-specific here so why pay for an extra copy of Windows when you can set up a pretty sweet hardware dev machine with Linux.