Difference between revisions of "NU32: Starting a New Project and Putting it on the NU32"

From Mech
Jump to navigationJump to search
Line 52: Line 52:
= Using the NU32 Utility Computer Application =
= Using the NU32 Utility Computer Application =


Now that you have compiled your code, you can use the NU32 Utility and the bootloader already on the NU32 to put it on your NU32 board.
Now that you have compiled your code, you can put it on your NU32 board using the NU32 Utility and the bootloader program already on the NU32.


Plug your NU32 into a power supply and turn on the board. Plug the USB cable into the board and your computer. If this is the first time you have plugged the board into your computer, drivers will be installed assigning your board two communication (COM) port numbers. Note what the port numbers are.
Plug your NU32 into your power supply (6V wall wart from the kit, or a supply >6V) and turn on the board. Plug the USB cable into the board and your computer. If this is the first time you have plugged the board into your computer, drivers will be installed assigning your board two communication port numbers (COM in Windows, TTY on MAC). Note what the port numbers or names are. The larger number is used for bootloading communication, and the smaller number is used for general communication.


Now open NU32_Utility.exe.
Now open NU32_Utility.exe. The left hand side of the window is used for bootloading, and the right hand side for general communication.


[[Image:nu32_utility_open.jpg|thumb|300 px|left|Initial NU32_Utility.exe window]]
Note that the text in the 'Status' box are red and your COM port is listed in 'Serial Ports'. If multiple ports are listed and you don't know which is your NU32v2 board, you can check 'Ports (COM & LPT)' in 'Device Manager'. Right click on each Port. The NU32v2 uses a chip made by FTDI, so your NU32v2 COM port will say "Manufacturer: FTDI". Usually your NU32v2 has the largest COM port number.
<br clear=all>


Select the larger of the two communication ports under "Select a bootloader port".
[[Image:nu32v2_serial_bootloader_open.png|thumb|300 px|left|Initial NU32v2_serial_bootloader.exe window]]

[[Image:nu32_utility_bootloaderopen.png|thumb|300 px|left|NU32_Utility.exe with a bootloader port selected]]
<br clear=all>
<br clear=all>


Push "Select_Hex" and navigate to your .hex file.
Click "Select .hex File", navigate to your project and select your hex file (projectname.hex). The path to your file will be listed in the first line in 'Status' in green.


[[Image:nu32v2_serial_bootloader_hex.png|thumb|300 px|left|.hex file selected, noted in green in 'Status']]
[[Image:nu32_utility_selecthex.jpg|thumb|300 px|left|NU32_Utility.exe with a .hex file selected]]
<br clear=all>
<br clear=all>


There are two options to get the NU32 board into bootloader mode. The first is to press and hold the RESET button on the board, press and hold the USER button, let go of the RESET button, then let go of the USER button. In bootloader mode L1, just above the RESET button, will blink. To connect NU32_Utility.exe to the NU32, press CONNECT.
Next click on the button corresponding to your COM port. The COM port you selected will be listed in the second line in 'Status' in green.

The second way to get the NU32 board into bootloader mode is to press REQUEST_BOOT. This will command the NU32 to perform a reset in software, and to enter bootloader mode. L1 will blink, and NU32_Utility.exe will automatically connect to the NU32. This method will only work if you use the standard NU32 header files when you write your code. If you do not use these files you will have to physically press the buttons on the NU32 board to get it into bootloader mode.

Once NU32_Utility.exe has connected to the NU32, you will see a message that the NU32 is connected.

[[Image:nu32_utility_connected.jpg|thumb|300 px|left|NU32_Utility.exe connected to the NU32 in bootloader mode]]
<br clear=all>

Now you can press PROGRAM to transfer the .hex file to the NU32 and have the PIC program itself.

[[Image:nu32_utility_programmed.jpg|thumb|300 px|left|NU32_Utility.exe completed programming the NU32]]
<br clear=all>

Now press RUN to have the NU32 leave bootloader mode and run the code you just programmed.

On the right side of the window, select the smaller of the communication port numbers under "Select debug port". The text area that appears bellow will display anything that the computer receives from the NU32.


[[Image:nu32v2_serial_bootloader_com.png|thumb|300 px|left|COM port selected, noted in green in 'Status']]
[[Image:nu32_utility_debug.jpg|thumb|300 px|left|NU32_Utility.exe receiving data from "Hello_World"]]
<br clear=all>
<br clear=all>


From here, you can send data to the NU32 by typing followed by an enter, you can save or clear the data received, or if the data is coming in in a special format, plot it by pressing the Plot button.
Next put your NU32v2 board into bootloader mode by pressing and holding the reset button on the NU32v2, pressing and holding the button in the top left breadboard between pin G6 and GND, releasing reset, then releasing G6. The 'Message' box will show "Bootloader v1.1" and the third line in 'Status' will state that your NU32v2 has connected in green.


[[Image:nu32v2_serial_bootloader_connect.png|thumb|300 px|left|NU32v2 ready to be programmed]]
[[Image:nu32_utility_plot.jpg|thumb|300 px|left|NU32_Utility.exe plotting data from the NU32]]
<br clear=all>
<br clear=all>


Enjoy!
Next click the "Program" button. Doing this will clear the memory of your NU32v2, write your code to the board, reset the board and close NU32v2_serial_bootloader.exe. Your code is now running on the NU32v2.

Revision as of 16:05, 28 December 2011

Note: Code downloaded from Microchip is constantly evolving, and it is possible that the information below will be outdated for future code releases. This information is accurate for code downloaded from Microchip's website in December 2011. Also, sample code developed by us and others are generally modified from working code for different purposes, and therefore you may find unnecessary legacy code, programming inefficiency, or even incorrect code in some samples.

You should complete the instructions in NU32: Software to Install if you have not already. For this page specifically, you need to

  • download and install the MPLAB X IDE (Integrated Development Environment) that you use for programming, compiling, debugging, and simulating your PIC code. The MPLAB C32 Compiler is included in the installation instructions
  • download the NU32 Utility computer application
  • install drivers for the FTDI USB-to-Serial chip on the NU32 board

The remainder of this page describes how to create a new Project in MPLAB X, compile a general "Hello World" program to blink the LEDs on the NU32, and use the NU32 Utility computer application to put the program on the NU32.

If you have already completed this and are just looking for the files, here they are: procdefs.ld, standard NU32 header files, hello world source code.

Create a New Project in MPLAB X v1.00 for the NU32

For organizational reasons, it is recommended to use the MPLABXProjects folder created during the MPLAB X IDE installation to store your projects.

Download and unzip the procdefs.ld file from this .zip file and place procdefs.ld in the MPLABXProjects folder. You will need to put procdefs.ld into each project folder as you make new projects for your code to work on the NU32.

Procdefs.ld is a linker file. If you have installed a bootloader (such as with the NU32), the linker file tells the compiler to rearrange the memory of your program so that it doesn't overwrite the bootloader code that is already on your PIC32. If you do not put procdefs.ld in the folder that contains your source code, MPLAB X will use the default procdefs.ld (unfortunately we cannot change the name to make this more clear.) Fortunately the bootloader will not overwrite itself, but your code will not work and will not give you an error telling you that you used the wrong prodefs.ld file. So every time you make a new project, copy the procdefs.ld file you put in the MPLABXProjects folder into the new folder that MPLAB X generates for each project.

Lets make new project, compile some pre-written code, and use the NU32 Utility to put it on your NU32.

  • Open MPLAB X
  • Choose File -> New Project... to create a new project.
  • Select Microchip Embedded and Standalone Project and click Next >.
Mplabx newproject 1.jpg


  • Select 32-bit MCUs (PIC32) and the PIC32MX795F512L (the last one in the list) and click Next >.
Mplabx newproject 2.jpg


  • Select the ICD 3 Hardware Tool (we will not be using the ICD 3, but select it anyway) and click Next >.
Mplabx newproject 3.jpg


  • Select C32(v2.02) from the Compiler Toolchains and click Next >.
Mplabx newproject 4.jpg


  • Enter a project Name ("Hello_World") and click Finish.
Mplabx newproject 5.jpg


Now go back to the MPLABXProjects folder, and you should see a new folder called "Hello_World.X". Copy procdefs.ld into "Hellow_World.X", as well as the standard NU32 header files from this .zip file and the hello world source code from this .zip file.

In MPLAB X, you can close the Start Page tab. Add the code to the project:

  • Right click on Header Files in the Projects tab on the left and select Add Existing Item... Select NU32.h.
  • Right click on Source Files and select Add Existing Item... Select NU32.c and hello_world.c.
Mplabx hello 1.jpg


This code is ready to be used, so compile it by pressing the Build Project button (the hammer).

Mplabx hello 2.jpg


The Output window at the bottom of the screen should say BUILD SUCCESSFUL.

MPLAB X creates a .hex file when you compile the code. It is hidden away in your project folder, in dist -> default -> production, and given a name (projectfoldername).production.hex, or in this case, Hello_World.X.production.hex.

Next we will use the NU32_Utility program to put the .hex file on your NU32 board.

Using the NU32 Utility Computer Application

Now that you have compiled your code, you can put it on your NU32 board using the NU32 Utility and the bootloader program already on the NU32.

Plug your NU32 into your power supply (6V wall wart from the kit, or a supply >6V) and turn on the board. Plug the USB cable into the board and your computer. If this is the first time you have plugged the board into your computer, drivers will be installed assigning your board two communication port numbers (COM in Windows, TTY on MAC). Note what the port numbers or names are. The larger number is used for bootloading communication, and the smaller number is used for general communication.

Now open NU32_Utility.exe. The left hand side of the window is used for bootloading, and the right hand side for general communication.

Initial NU32_Utility.exe window


Select the larger of the two communication ports under "Select a bootloader port".

File:Nu32 utility bootloaderopen.png
NU32_Utility.exe with a bootloader port selected


Push "Select_Hex" and navigate to your .hex file.

NU32_Utility.exe with a .hex file selected


There are two options to get the NU32 board into bootloader mode. The first is to press and hold the RESET button on the board, press and hold the USER button, let go of the RESET button, then let go of the USER button. In bootloader mode L1, just above the RESET button, will blink. To connect NU32_Utility.exe to the NU32, press CONNECT.

The second way to get the NU32 board into bootloader mode is to press REQUEST_BOOT. This will command the NU32 to perform a reset in software, and to enter bootloader mode. L1 will blink, and NU32_Utility.exe will automatically connect to the NU32. This method will only work if you use the standard NU32 header files when you write your code. If you do not use these files you will have to physically press the buttons on the NU32 board to get it into bootloader mode.

Once NU32_Utility.exe has connected to the NU32, you will see a message that the NU32 is connected.

NU32_Utility.exe connected to the NU32 in bootloader mode


Now you can press PROGRAM to transfer the .hex file to the NU32 and have the PIC program itself.

NU32_Utility.exe completed programming the NU32


Now press RUN to have the NU32 leave bootloader mode and run the code you just programmed.

On the right side of the window, select the smaller of the communication port numbers under "Select debug port". The text area that appears bellow will display anything that the computer receives from the NU32.

NU32_Utility.exe receiving data from "Hello_World"


From here, you can send data to the NU32 by typing followed by an enter, you can save or clear the data received, or if the data is coming in in a special format, plot it by pressing the Plot button.

NU32_Utility.exe plotting data from the NU32


Enjoy!