How To Information for PIC32 Starter Kit

Updates

9/15/09; 2:50pm; Added a note on device drivers.
9/21/09; 2:15pm; Install MPLAB IDE from web, not from CD.
9/23/09; 1:35pm; Revised links for C32 compiler to Academic version.

Hardware

In this course, we will be using the PIC32 Starter Kit board to run our assembly language programs. This board has a Microchip PIC32MX processor which itself has a MIPS "core"-- i.e., the instruction set architecture of the processor is the same MIPS type instruction architecture we will be covering in the class.

This PIC32 Starter Kit board is described online here (see also this link).

       Microchip, the company that makes this board, calls the processor a PIC32MX.

This board can be purchased through Microchip (the manufacturer), or through Digikey (link).

Instruction set for PIC32; this is from pp. 49-54 of the datasheet for the PIC32.


MIPS Corp. calls the PIC32MX by a different name-- MIPS M4K.

    MIPS Page for M4K processor (link)

    M4K data sheet (link): Includes desciption of instruction set

One thing you should know about the MIPS chip on the PIC32 board is that it runs with no operating system. Your program, and any libraries that you use, will be downloaded to the MIPS chip RAM and executed. This is typical of microcontroller hardware-- it has no operating system.


IDE & Assembler software

The PIC32 can be programmed in the C language and in assembly language. We will be using assenbly language. We will use an IDE (Integrated Development Environment) provided by Microchip to do our programming. The IDE is called the MPLAB IDE, and it is freely available. We will be using the C32 assembler to assemble our programs into machine language. The MWAH 177 lab will have these pieces of software installed. If you want to install this software on your computer, they are freely available:

MPLAB IDE page at Microchip (link)

    Version 8.36 of IDE (download)

C32 Academic Version Compiler & Assembler (link; login required to download compiler-- free account)
    Version 1.05 also available here.

Microsoft Vista: Vista may pose some installation issues for the MPLAB IDE and the driver software for the Starter Kit.

Make sure you install the version of MPLAB from the Web, and not from a PIC32 Starter Kit CD. The CD will probably not have the most recent version of MPLAB and likely will not work with Vista.

MPLAB IDE page at Microchip (link)

    Version 8.36 of IDE (download)

If you are installing on a Vista system, you can try following the instructions in this video.

Documentation on C32 libraries.

    From C language

    From assembly language: Section 5.6 of this document has calling conventions.

If you use Linux or Mac OS, it appears to be possible to use the assembler on these platforms. See this link. I'm not sure how to use Linux or Mac OS to download your machine language code to the Starter Kit, however.

Using MPLAB on Linux:

Here's some more information about VirtualBox from Sun that I use to emulate windows XP.
http://www.virtualbox.org/wiki/Downloads

I did something along this line to get my USB working, tho this isn't the exact page I used (can't find it).
http://www.hooto.com/home/rui/blog/archives/1326.html

Although it looks like this might work as well
http://news.softpedia.com/news/How-to-Fix-VirtualBox-USB-Support-111715.shtml

Also I had to install VirtualBox guest add-ons in the virtual Windows to get everything working.

On my virtual Windows I can access all my connected USB devices, including the PIC32, and from there I can program it and everything works correctly.

Robert Nelson

Assembler documentation

The assembler within the C32 compiler is the GNU assembler.

Some documentation on this assembler is here.

And here (easier to access).

See also the references of this Wiki page.

One more reference

Other MIPS documentation

MIPS architecture documentation

MIPS Assembly Language Programming CS50 Discussion and Project Book

See MIPS Run (Book)


Drivers

Once you have installed the MPLAB IDE and the C32 compiler & assembler, you can then connect the PIC32 Starter Kit board via its USB cable. Windows will go through a process of installing a USB driver for this PIC32 board.

Assembling your own assembly language programs

Now that you have the MPLAB IDE installed, and the C32 assembler installed, let's see about actually getting an assembly language program to assemble into machine language and download that program to the PIC32 board.

The first step in this process is to get an assembly language program ready, and prepared as an MPLAB IDE project. Here is a sample assembly language program that will run on the PIC32 board.

Creating a project

1) Create a folder, and place your .s assembly language program in that folder.

2) Start the MPLAB IDE

3) Select Project -> Project Wizard...

4) Click "Next"

5) Device should be "PIC32MX360F512L"; then click "Next"

6) For language toolsuite, select  Microchip PIC32 C-Compiler Toolsuite, then click "Next".

Note: Even though we are using the assembler, we will be using libraries provided by the C compiler, so make this choice for toolsuite.

7) Create a new project file, and select the Browse button to place this new project file in the folder you created at the start of this project creation process. Click "Next".

8) Next, add your assembly language program by selecting your .s file on the right column and click "Add>>". Then, click "Next".

9) Click "Finish".

This may open your new project or it may not. If it does not open your new project use Project -> Open... to open your project (open the .mcp file associated with your new project).

10) Now, you should add the console I/O library db_utils.a into the Library files of your project. First, copy the db_utils.a file into your new project folder.

11) Next, right click on the Library Files folder within the MPLAB IDE file explorer in your project, and select "Add Files...", and navigate do the db_utils.a file within your new project folder, finally clicking on "Open".

12) Select Project -> Build Configuration -> Debug

13) Click "OK" on the message window.

Building the assembly language program

Once you have a project, with an assembly language program contained within it (and the db_utils.a file in the Library Files), you can assemble your program. To do this, use Project -> Build All.

Downloading your machine language to the PIC32

1) First, launch the MPLAB IDE and connect the Starter Kit

If this is the first time you have connected the PIC32 Starter Kit to your computer, you will likely need to install a device driver. You can point the Windows device driver installer to:

C:\Program Files\Microchip\PIC32MXSKit\Drivers


2) Select Debugger -> Select Tool -> PIC32 Starter Kit.

Your may need to re-build your program at this point.

3) Select Debugger -> Programming -> Program All Memories.

This may say "You're attempting to program an image built for a different debugger. Do you want to rebuild?" Click "Yes".

This may also confirm that you want to program all memories. You want to program all memories, so click "Yes".

Running your program

1) After downloading your machine language program to the PIC32, you can run it. To do this, select Debugger -> Run.

2) To halt your program, select Debugger -> Halt

3) To run it again,

a) Select Debugger -> Reset -> Processor Reset, and then

b) Debugger -> Run

Resetting board state

Sometimes you can get yourself into strange appearing states with the PIC32 board. If the sequence:

1) Debugger -> Halt

2) Debugger -> Reset -> Processor Reset

does not work, try the following to reset the board state:

1) Unplug the PIC32 board from the USB port

2) Plug it back in

3) Debugger -> Clear Memory -> All Memory

4) Unplug the PIC32 again

5) Close the MPLAB IDE

6) Plug the PIC32 board back in

7) Start MPLAB IDE

8) Download your program again to the board