Difference between revisions of "NU32v2: The NU32v2 Serial Bootloader and PC Application"

From Mech
Jump to navigationJump to search
Line 1: Line 1:
Now that you have completed [[NU32v2: Starting a New Project and Putting it on the NU32v2]], we can take a look at the process used to program the NU32v2 in more detail.
'''**THIS PAGE IS UNDER CONSTRUCTION AND IS NOT COMPLETE**'''

'''**NDM 1/16/2011**'''


== What is a bootloader? ==
== What is a bootloader? ==
No code is installed on the PIC32 when it arrives from the factory. To put a program on the microcontroller, a programmer is used. There are a variety of programmers available, including many from Microchip, the manufacturer of the PIC32, [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2519&param=en534451&page=wwwdevMPLABEmulatorDebuggers listed here.] These programmers have many functions, including programming and debugging, with more functionality built into the more expensive programmers.
...

The NU32v2 can easily be programmed with any of these programmers, but has been designed to work with the [http://www.microchipdirect.com/productsearch.aspx?Keywords=PG164130 PICkit 3], available for around $45. To avoid the expense of providing a PICkit with every NU32v2 kit, we have opted to install a bootloading program on the NU32v2. A bootloader is code that communicates with an application on a computer (in our case NU32v2-serial_bootloader), which takes the code that you have compiled and writes it to the memory on the PIC32.

By not including the PICkit with your NU32v2, we have lost the ability to do "in-circuit debugging", such as adding breakpoints and watches to your code as was done in the simulator. We will discuss alternative ways of debugging your code as the course progresses.

Understanding the bootloading process will increase your understanding of how the PIC32 functions. How the NU32v2 bootloader works is described in the following sections.


== How the NU32v2 Bootloading Process is Structured ==
== How the NU32v2 Bootloading Process is Structured ==
There are two important parts to the bootloader process. The first is what happens when you write code, and what the PC bootloader application does to prepare the code for the PIC32. The second part is how the PIC32 programs itself.
...

When you compile code in MPLAB, your C and H files go through several steps to turn it into instructions at specific memory addresses. The PIC32 starts at a specific memory address, and follows the instructions it finds. You can view the instructions the PIC32 will undergo in your code by going to ''View->Disassembly Listing''. When compiled, this list of memory addresses and instructions is put into a file with a .hex extension. The [http://en.wikipedia.org/wiki/Intel_HEX hex file] has a format that needs to be further interpreted before it can be put onto the PIC32.

After connecting to the NU32v2 in the NU32v2_serial_bootlader app, the hex file is converted to a binary file. In this process, a block of memory on the PC is set aside that is the maximum size of program memory on the PIC32. As each line of the hex file is read, the instructions are placed into memory addresses, which are not necessarily in order. After each line of the hex file is interpreted, the entire block of memory is sent over to the PIC32, in 512 byte packets. After sending all of the packets, the app closes.

On the NU32v2 side of things, the bootloader has already been programmed onto the PIC32 with a PICkit 3. The bootloader code is the first thing that runs on the NU32v2 when power is applied. The code sets up the configuration of the PIC32, to run at 80MHz, then it checks to see if the G6 pin is being pulled low. If it is not, it skips to another portion of memory, effectively leaving the bootloader code to run the last code that was put on the PIC32 with the bootloader. If G6 is being pulled low, it knows to remain in bootloader mode and get ready to receive a series of 512 byte packets, which it will write to memory.

More specific details are provided below.




== NU32v2 bootloader source code ==
== NU32v2 bootloader source code ==

Revision as of 12:32, 20 January 2011

Now that you have completed NU32v2: Starting a New Project and Putting it on the NU32v2, we can take a look at the process used to program the NU32v2 in more detail.

What is a bootloader?

No code is installed on the PIC32 when it arrives from the factory. To put a program on the microcontroller, a programmer is used. There are a variety of programmers available, including many from Microchip, the manufacturer of the PIC32, listed here. These programmers have many functions, including programming and debugging, with more functionality built into the more expensive programmers.

The NU32v2 can easily be programmed with any of these programmers, but has been designed to work with the PICkit 3, available for around $45. To avoid the expense of providing a PICkit with every NU32v2 kit, we have opted to install a bootloading program on the NU32v2. A bootloader is code that communicates with an application on a computer (in our case NU32v2-serial_bootloader), which takes the code that you have compiled and writes it to the memory on the PIC32.

By not including the PICkit with your NU32v2, we have lost the ability to do "in-circuit debugging", such as adding breakpoints and watches to your code as was done in the simulator. We will discuss alternative ways of debugging your code as the course progresses.

Understanding the bootloading process will increase your understanding of how the PIC32 functions. How the NU32v2 bootloader works is described in the following sections.

How the NU32v2 Bootloading Process is Structured

There are two important parts to the bootloader process. The first is what happens when you write code, and what the PC bootloader application does to prepare the code for the PIC32. The second part is how the PIC32 programs itself.

When you compile code in MPLAB, your C and H files go through several steps to turn it into instructions at specific memory addresses. The PIC32 starts at a specific memory address, and follows the instructions it finds. You can view the instructions the PIC32 will undergo in your code by going to View->Disassembly Listing. When compiled, this list of memory addresses and instructions is put into a file with a .hex extension. The hex file has a format that needs to be further interpreted before it can be put onto the PIC32.

After connecting to the NU32v2 in the NU32v2_serial_bootlader app, the hex file is converted to a binary file. In this process, a block of memory on the PC is set aside that is the maximum size of program memory on the PIC32. As each line of the hex file is read, the instructions are placed into memory addresses, which are not necessarily in order. After each line of the hex file is interpreted, the entire block of memory is sent over to the PIC32, in 512 byte packets. After sending all of the packets, the app closes.

On the NU32v2 side of things, the bootloader has already been programmed onto the PIC32 with a PICkit 3. The bootloader code is the first thing that runs on the NU32v2 when power is applied. The code sets up the configuration of the PIC32, to run at 80MHz, then it checks to see if the G6 pin is being pulled low. If it is not, it skips to another portion of memory, effectively leaving the bootloader code to run the last code that was put on the PIC32 with the bootloader. If G6 is being pulled low, it knows to remain in bootloader mode and get ready to receive a series of 512 byte packets, which it will write to memory.

More specific details are provided below.


NU32v2 bootloader source code

NU32v2 bootloader project, written in MPLAB Assembly, with a "hello_world" type blinking LED tacked on. PIC32 code

NU32v2_serial_bootloader.exe source code

NU32v2 serial bootloader app, written in Processing. PIC32 code

Mac executable: NU32v2 serial bootloader for OSX

Other

The NU32v2 board has an FT232RL built on to allow for easy communication over USB with your computer using an RS232 connection on the PIC32 end. The communication is viewable as a "virtual com port" on you computer using the driver provided by FTDI.