Difference between revisions of "NU32: Quickstart"

From Mech
Jump to navigationJump to search
Line 1: Line 1:
This is a quick-start guide to programming the NU32, using the bootloader and the PICkit3.
This is a quick-start guide to programming the NU32, using the bootloader and the PICkit3.


Follow this guide to test your NU32 with the bootloader application, and test your installation of MPLAB X.
If you are looking for more details, take a look at [[NU32: Starting a New Project and Putting it on the NU32]] and [[NU32: A Detailed Look at Programming the PIC32 on the NU32]]

If you are looking for more details about programming the PIC32, take a look at [[NU32: Starting a New Project and Putting it on the NU32]] and [[NU32: A Detailed Look at Programming the PIC32 on the NU32]]


== Before you start ==
== Before you start ==


You should complete the instructions in [[NU32: Software to Install]] if you have not already. Specifically, you need to
You should complete the instructions on [[NU32: Software to Install]] if you have not already. Specifically, you need to at least:


* download and install the MPLAB X IDE and the MPLAB XC32 Compiler
* download and install the MPLAB X IDE and the MPLAB XC32 Compiler
Line 11: Line 13:
* install drivers for the FTDI USB-to-Serial chip
* install drivers for the FTDI USB-to-Serial chip


You can download all of the code on this page here:
You can download all of the code that is used on this page here:
*[[NU32test.zip | NU32test.hex]] - Precompiled .hex "Hello World!" to test your NU32
*[[NU32test.zip | NU32test.hex]] - Precompiled .hex "Hello World!" to test your NU32
*[[Media:SimplePIC.c | SimplePIC.c]] - C code for a different version of "Hello World!" to test your installation of MPLAB X
*[[Media:SimplePIC.c | SimplePIC.c]] - C code for a different version of "Hello World!" to test your installation of MPLAB X
Line 21: Line 23:
== Test the bootloader, 1.2.1 ==
== Test the bootloader, 1.2.1 ==


Begin by testing your NU32. Plug the mini USB cable into the board and your computer. Plug the 6V wall power into the board. Turn on the NU32 power switch, and a red LED should turn on. Press and hold the reset button, press and hold the user button, release the reset button, and release the user button. LED1 should blink. If it does not, the bootloader firmware has not been installed on your board. Also check to see what the FTDI driver has named the NU32 ports. The NU32 board will create 2 virtual serial ports on your computer. In Windows, the ports will be named something like COM10 and COM11, or some two consecutive numbers. On a Mac or in Linux, the ports will named DEV/TTY/##A and ##B. (You can ignore the CU versions). If you cannot verify your ports, re-install the FTDI drivers.
First, make sure your NU32 is working. Use the NU32 Utility to load [[Media:NU32test.hex | NU32test.hex]] to test your NU32 and the Utility.


Now use the NU32 Utility to load [[Media:NU32test.hex | NU32test.hex]] on your board. This will test the communication link between your computer and the NU32. Open NU32_Utility:
To use the Utility, first plug in the mini USB cable to your NU32 and computer. Then power your NU32 with the wall power and turn on the board so that the red power LED is on. Now open NU32Utility.


[[Image:NU32_utility.png|thumb|300 px|left]]<br clear=all>
Image of utility when first opened


The left hand side of the Utility is used for loading code onto the NU32. Select the larger of the two ports (so COM11 instead of COM10, or ##B instead of ##A) to allow communication between your computer and the bootlodaer on the NU32. Click "Select HEX" and navigate to NU32test.hex. The NU32 must be in bootloading mode to accept code - this is when LED1 is blinking. Put the NU32 in this mode by pressing and holding reset, pressing and holding user, releasing rest, then releasing user. Or, depending on the code already on the NU32, clicking "Request Boot".
The NU32 board will create 2 virtual serial ports on your computer. In Windows, the ports will be named something like COM10 and COM11, or some two consecutive numbers. On a Mac or in Linux, the ports will named DEV/TTY/##A and ##B. (You can ignore the CU versions).


The text box should report:
The left hand side of the Utility is used for loading code onto the NU32. Select the larger of the two ports (so COM11 instead of COM10, or ##B instead of ##A). Click Select HEX and navigate to your .hex file. The NU32 must be in bootloading mode to accept code - LED1 blinks in this mode. You can put the NU32 in this mode by pressing and holding Reset, pressing and holding User, releasing Rest, then releasing User. Or, depending on the code already on the NU32, clicking Request Boot.
"Trying to connect...
Connected to bootloader v4.0!"


Now click Program. When the message Programming Complete! appears, click Run, and the program will execute.
Now click Program. When the message "Programming Complete!" appears, click "Run", and the program will execute.


[[Image:NU32_utility_ulpoaderNU32test.png|thumb|300 px|left]]<br clear=all>
Image of complete program


Using NU32test.hex, if you press the User button, LEDs 1 and 2 will blink out of phase, and stop blinking when you don't push User.
Using NU32test.hex, if you press the user button, LEDs 1 and 2 will blink out of phase, and stop blinking when you don't push User.


== Test MPLAB X, 1.3.1 ==
== Test MPLAB X, 1.3.1 ==


Now we will create an MPLAB X project to test your installation of MPLAB X.
Now create an MPLAB X project to test your installation of MPLAB X. First, create a project. Second, download the sample code and add it to the project. Third, compile the code, and use the NU32 Utility to load the .hex file.

Open MPLAB X and go to "File -> New Project..."

[[Image:MPLABX_newProject.png|thumb|300 px|left]]<br clear=all>

Keep "Microchip Embedded" and "Standalone Project" highlighted and click "Next >"

[[Image:NU32_utility_ulpoaderNU32test.png|thumb|300 px|left]]<br clear=all>

Select "32-bit MCUs (PIC32)" from "Family:" and "PIC32MX795F512L" from "Device:" and click "Next >"

[[Image:NU32_utility_ulpoaderNU32test.png|thumb|300 px|left]]<br clear=all>

If you are using the bootloader to load code, it doesn't matter which tool you select, but if you are using the PICkit3 programmer, select "PICkit3", and click "Next >"


[[Image:NU32_utility_ulpoaderNU32test.png|thumb|300 px|left]]<br clear=all>
Download [[Media:SimplePIC.c | SimplePIC.c]] and [[Media:NU32bootloaded.ld | NU32bootloaded.ld]].


Create a project in MPLAB X with XC32. Open MPLAB X and click New Project.
Select the compiler you will use, "XC32 (v1.xx) ..." and click "Next >"


[[Image:NU32_utility_ulpoaderNU32test.png|thumb|300 px|left]]<br clear=all>
Image


Give your project a name, like "SimplePIC", and click "Finish"
Select ...


[[Image:NU32_utility_ulpoaderNU32test.png|thumb|300 px|left]]<br clear=all>
Image


MPLAB X will make a new folder called "SimplePIC.X" at the location where you saved your project. This folder is where all of your files should be located.
When the project has been created, a new folder will appear in C:/users/MPLABXprojects/. Put the SimplePIC.c and NU32bootloaded.ld files in this folder. In MPLAB X, right click on source and select add files from, and select the .c file. Do the same for the .ld file in the liker folder.


Download [[Media:SimplePIC.c | SimplePIC.c]] and [[Media:NU32bootloaded.ld | NU32bootloaded.ld]], and place them in the "SimplePIC.X" folder. In MPLAB X, in the file tree on the left, right-click on the "Source Files" folder under the "SimplePIC" project. Select "Add Existing Item..." and select "SimplePIC.c". Right-click on the "Linker Files" folder and select "Add Existing Item..." and select "NU32bootloaded.ld".
Image


[[Image:NU32_utility_ulpoaderNU32test.png|thumb|300 px|left]]<br clear=all>
Select Build, and the bottom of the screen should show build completed.


This code is already complete, so build it by clicking the Hammer icon, "Build Main Project". Note that if there are several projects in the project tree on the left, the one that is highlighted will be built, so be sure to right-click on the project you are making and select "Set as Main Project". Also note that you code will compile, but not run, if you forget to add "NU32bootloaded.ld" to your project, from the project folder. "NU32bootloaded.ld" needs to be copied into every project folder you make, and added to the "Linker Files" folder in MPLAB X. Use the Hammer and Broom icon, "Clean and Build Main Project", to rebuild your code if you add a new linker file, otherwise MPLAB X won't necessarily know that you added a new linker file.
Image


When your code has compile, you should get a message "Compile Successful". This process has created a .hex file "(project).X.production.hex " in your project folder at "(project.x)\dist\default\production". Use this .hex file and the NU32 Utility to load the code onto your NU32.
There is now a .hex file in /dist/build/.


Use the NU32 Utility to put the .hex file on the NU32. Now the LEDs blink all the time, and stop when you hold the User button.
Run the code and the LEDs blink all the time, and stop when you hold the user button.


== Projects with the standard NU32 functions, 1.4.1 ==
== Projects with the standard NU32 functions, 1.4.1 ==

Revision as of 17:40, 20 January 2013

This is a quick-start guide to programming the NU32, using the bootloader and the PICkit3.

Follow this guide to test your NU32 with the bootloader application, and test your installation of MPLAB X.

If you are looking for more details about programming the PIC32, take a look at NU32: Starting a New Project and Putting it on the NU32 and NU32: A Detailed Look at Programming the PIC32 on the NU32

Before you start

You should complete the instructions on NU32: Software to Install if you have not already. Specifically, you need to at least:

  • download and install the MPLAB X IDE and the MPLAB XC32 Compiler
  • download the NU32 Utility computer application
  • install drivers for the FTDI USB-to-Serial chip

You can download all of the code that is used on this page here:

  • NU32test.hex - Precompiled .hex "Hello World!" to test your NU32
  • SimplePIC.c - C code for a different version of "Hello World!" to test your installation of MPLAB X
  • NU32bootloaded.ld - Linker file for all code that will use the bootloader to load
  • talkingPIC.c - C code for a different version of "Hello World!" using serial communication
  • NU32.c - C code library for the NU32 functions
  • NU32.h - Header file for the NU32 functions

Test the bootloader, 1.2.1

Begin by testing your NU32. Plug the mini USB cable into the board and your computer. Plug the 6V wall power into the board. Turn on the NU32 power switch, and a red LED should turn on. Press and hold the reset button, press and hold the user button, release the reset button, and release the user button. LED1 should blink. If it does not, the bootloader firmware has not been installed on your board. Also check to see what the FTDI driver has named the NU32 ports. The NU32 board will create 2 virtual serial ports on your computer. In Windows, the ports will be named something like COM10 and COM11, or some two consecutive numbers. On a Mac or in Linux, the ports will named DEV/TTY/##A and ##B. (You can ignore the CU versions). If you cannot verify your ports, re-install the FTDI drivers.

Now use the NU32 Utility to load NU32test.hex on your board. This will test the communication link between your computer and the NU32. Open NU32_Utility:


The left hand side of the Utility is used for loading code onto the NU32. Select the larger of the two ports (so COM11 instead of COM10, or ##B instead of ##A) to allow communication between your computer and the bootlodaer on the NU32. Click "Select HEX" and navigate to NU32test.hex. The NU32 must be in bootloading mode to accept code - this is when LED1 is blinking. Put the NU32 in this mode by pressing and holding reset, pressing and holding user, releasing rest, then releasing user. Or, depending on the code already on the NU32, clicking "Request Boot".

The text box should report: "Trying to connect... Connected to bootloader v4.0!"

Now click Program. When the message "Programming Complete!" appears, click "Run", and the program will execute.

NU32 utility ulpoaderNU32test.png


Using NU32test.hex, if you press the user button, LEDs 1 and 2 will blink out of phase, and stop blinking when you don't push User.

Test MPLAB X, 1.3.1

Now create an MPLAB X project to test your installation of MPLAB X. First, create a project. Second, download the sample code and add it to the project. Third, compile the code, and use the NU32 Utility to load the .hex file.

Open MPLAB X and go to "File -> New Project..."

MPLABX newProject.png


Keep "Microchip Embedded" and "Standalone Project" highlighted and click "Next >"

NU32 utility ulpoaderNU32test.png


Select "32-bit MCUs (PIC32)" from "Family:" and "PIC32MX795F512L" from "Device:" and click "Next >"

NU32 utility ulpoaderNU32test.png


If you are using the bootloader to load code, it doesn't matter which tool you select, but if you are using the PICkit3 programmer, select "PICkit3", and click "Next >"

NU32 utility ulpoaderNU32test.png


Select the compiler you will use, "XC32 (v1.xx) ..." and click "Next >"

NU32 utility ulpoaderNU32test.png


Give your project a name, like "SimplePIC", and click "Finish"

NU32 utility ulpoaderNU32test.png


MPLAB X will make a new folder called "SimplePIC.X" at the location where you saved your project. This folder is where all of your files should be located.

Download SimplePIC.c and NU32bootloaded.ld, and place them in the "SimplePIC.X" folder. In MPLAB X, in the file tree on the left, right-click on the "Source Files" folder under the "SimplePIC" project. Select "Add Existing Item..." and select "SimplePIC.c". Right-click on the "Linker Files" folder and select "Add Existing Item..." and select "NU32bootloaded.ld".

NU32 utility ulpoaderNU32test.png


This code is already complete, so build it by clicking the Hammer icon, "Build Main Project". Note that if there are several projects in the project tree on the left, the one that is highlighted will be built, so be sure to right-click on the project you are making and select "Set as Main Project". Also note that you code will compile, but not run, if you forget to add "NU32bootloaded.ld" to your project, from the project folder. "NU32bootloaded.ld" needs to be copied into every project folder you make, and added to the "Linker Files" folder in MPLAB X. Use the Hammer and Broom icon, "Clean and Build Main Project", to rebuild your code if you add a new linker file, otherwise MPLAB X won't necessarily know that you added a new linker file.

When your code has compile, you should get a message "Compile Successful". This process has created a .hex file "(project).X.production.hex " in your project folder at "(project.x)\dist\default\production". Use this .hex file and the NU32 Utility to load the code onto your NU32.

Run the code and the LEDs blink all the time, and stop when you hold the user button.

Projects with the standard NU32 functions, 1.4.1

The NU32 board has dedicated several pins on the PIC32MX795F512L to special funtions - A4 and A5 are LEDs, C13 is the User button, D14 and D15 are for programming the NU32 over UART4, and F2 and F8 are for communicating with the computer with UART1. These pins should not be used for any other function, unless you are very careful.

These functions can be set up to their dedicated functions by including NU32.c and NU32.h in your project.

Use the NU32_BasicTemplate.zip to start all of your projects. Remember to include app.ld!

Test the PICkit3, 1.2.2

If you don't want to use the bootloader and the Utility, and have a PICkit3 programmer, you can program the NU32 directly from MPLAB X.

Build a project with NU32_HelloWorld_standalone_files.zip. Note that you do not need to include a linker file (.ld) in your project - MPLAB X will use the default linker (procdefs.ld). But you need to be sure to include some extra code in your main.c file, because the bootloader called some functions to make the PIC32MX795F512L run at 80MHz and enable some pins.

Plug the PICkit3 into the NU32, lining up the white triangles. Press the "Make and Program Device" button in MPLAB X (green downwards arrow) to program the NU32.

Stand-alone projects with the standard NU32 functions using the PICkit3, 1.4.2

Use NU32_BasicTemplateStandalone.zip to start all of your projects with NU32.c and NU32.h using the PICkit3.