Skip navigation.
Home
Tech for Linux Users

Programming PIC Microcontrollers under Linux

Programming microcontrollers under Linux can be some what of a complicated task. The manufacturers of microcontrollers generally sell tools and provide software to program their devices, but these tools are produced only for one operating system. This operating system is not Linux...

To add to the problem further many of the tools that they sell, whilst being reasonably feature rich (allowing for in-circuit debugging and alike), they are also quite pricey. Many alternative low cost designs have sprung up offering varying features, device compatibility and cost. Some of these devices have software written to cater to the Linux market, sometimes by the providers themselves, often by other groups and individuals. There are therefore many choices to make, some which will lead to success, others to failure.

I wanted to find a low cost solution, that would satisfy my needs as a hobbyist whom runs Linux as the sole operating system on his computer(s). My requirements were therefore:

  • All software and hardware must be low cost, software preferably opensource.
  • Software should allow me to program in a reasonably high level language (preferably C)
  • Hardware and software must be usable under Linux
  • Simple Programmer acceptable - I don't tend to use in-circuit debugging
  • The Programmer must be capable of programming a number of different models of microcontroller (though not necessarily makes)

Software

Finding software capable of creating hex files for programming the microcontrollers with was actually quite simple compared to the task of finding a programmer to put the code in the hex file onto the device it's self!

Programming in ASM

This is the method I first used when I was taught to program microcontrollers - programming in assembly language. Microchip, the manufacturers of the PIC microcontroller, provide an application suite known as MPLAB. This application provides a assembler and IDE and is freely downloadable. This however is not natively available for Linux. Luckily SourceForge host a project called gputils which aims to provide an assembler for Linux. I have already covered the installation of this application from source (as part of installing sdcc), alternatively check to see if this is available for install in your package manager.

Programming in C

This is my preferred method of programming. The compilers are getting reasonably good at writing optimised code, especially compared to the code I am likely to write! This method also makes it easier to move code and target other devices.

When I first started programming PIC's I was using the CCS PCH C compiler. This software, though conciderably cheaper than some of it's competators, is not open source and neither are the included libraries. A number of bugs were found in the code it created by friends on projects I have worked on and thus I decided to look for an open source solution.

This is when I discovered SDCC. I have already covered the installation of this application from source, as well as providing some test apps. The only downside to SDCC is that it doesn't have a set of well documented libraries, however they are becoming available.

Hardware

As I have stated previously, there are a number of programmers available for the PIC line of microcontrollers. I have tried a number with varying degrees of success.

Which interface?

I have found devices which are connected to the host PC via three different interfaces:

  • Parallel
  • Serial
  • USB

Out of these I have tried a number of devices which are connected via serial and parallel. I decided to concentrate on those programmers which utilise the serial port over those that use the parallel port. I have fond that those using the parallel port generally "bit bash" the port to control aspects of the programming procedure. Whilst this works, to obtain the requisite low-level access to the parallel port, superuser privileges are required and thus I might find myself unable to program if using a box for which I do not have superuser privileges. Unfortunately it also seems to be the case that some of the simpler serial programmers also need superuser privileges in order to run the serial port in a non-standard baud rate.

Parallel Port Programmers

I have attempted unsuccessfully to use a P16PRO40, a Tait derivative, under Linux using Brian Lanes picprog. The main cause for my lack of success is that picprog was written to work initially with the Linux 2.2 and was later updated for the 2.4 kernel. The driver makes some low-level calls to alter the state of the parallel port pins, which are not compatable with the 2.6 kernel. I attempted to alter picprog to utilise standard API calls, however my attempts proved unsuccessfull.

I also have access to a galep-4 programmer. Conitec, the makers of the galep-4 programmer have an alpha linux software available on their site, however it hasn't been updated in well over a year at time of writing and did not run correctly on the systems that I tried compiling it on.

Serial Port Programmers

If you are lucky enough to be able to afford a Microchip PicStart Plus then this has a good opensource driver called picp. I have written a short description of how to use the Picstart Plus with Picp.

A low-cost solution is available in the form of Jaakko Hyvätti's Picprog (this is a different application from Brian Lane's Picprog). I have build a device from the schematic he provides (based on the jdm84v23) and have found it to be slow, though acceptable for my needs. I have created some boards using this schematic.