NU32: Starting a New Project and Putting it on the NU32

From Mech
Jump to navigationJump to search

THIS PAGE REFERS TO A PRE-RELEASE VERSION OF THE NU32 PIC32 DEVELOPMENT BOARD. FOR INFORMATION, SAMPLE CODE, AND VIDEOS RELATED TO THE PRODUCTION VERSION (2016 AND LATER), AND TO THE CORRESPONDING BOOK "EMBEDDED COMPUTING AND MECHATRONICS WITH THE PIC32 MICROCONTROLLER," VISIT THE NU32 PAGE.

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 XC32 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.

Here are the files you will need to complete this page: NU32_BasicTemplate.zip.

Here is a less detailed version of this page: NU32: Quickstart

Create a New Project in MPLAB X v1.XX 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 NU32_BasicTemplate.zip and place it in the MPLABXProjects folder. Note that every project you make will need a copy of app.ld.

app.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 app.ld in the folder that contains your source code, MPLAB X will use the default linker, named procdefs.ld. 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 .ld file. So every time you make a new project, copy the app.ld file you put in the MPLABXProjects folder into the new folder that MPLAB X generates for each project.

Fist, make a 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 XC32(v1.xx) 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 app.ld into "Hello_World.X", as well as the other files, hello_world.c, NU32.c, and NU32.h.

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.
  • Right click on Linker Files and select Add Existing Item... Select app.ld.
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.USBSERIAL 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.

For example: My Windows computer already has a COM1. When I plug in my NU32 I also get COM19 and COM20, so I choose COM20 for bootloading and COM19 for general communication. On my MAC I already have a bunch of ports, like /DEV/TTY.BLUETOOTH-MODEM and CU.NOKIA6205-DUNONBRCMPHONE-2. When I plug in my NU32 I get 4 more, /DEV/TTY.USBSERIAL-000030FDA, /DEV/CU.USBSERIAL-000030FDA, /DEV/TTY.USBSERIAL-000030FDB, and /DEV/CU.USBSERIAL-000030FDB. Ignore the versions with CU, and use /DEV/TTY.USBSERIAL-000030FDB for bootloading and /DEV/TTY.USBSERIAL-000030FDA 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".

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 a 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!