Using the MPLAB IDE with the chipKIT Pro MX7 Development Board - PIC32 Microcontrollers and the Digilent chipKIT: Introductory to Advanced Projects (2015)

PIC32 Microcontrollers and the Digilent chipKIT: Introductory to Advanced Projects (2015)

APPENDIX. Using the MPLAB IDE with the chipKIT Pro MX7 Development Board

MPLAB IDE® is Microchip’s popular integrated development environment. In this appendix, the steps for using the chipKIT Pro MX7 board with MPLAB IDE and Microchip’s C32 compiler are shown. The chipKIT MX3 development board cannot be used directly with the MPLAB IDE, and additional programming hardware (e.g., Microchip PICkit 3) is required. chipKIT Pro MX7 is however, a more advanced development board and can be used directly with the MPLAB IDE.

In this appendix, a simple program example is given that flashes LED 1 on the chipKIT Pro MX7 development board using the MPLAB IDE and the C32 compiler. Readers who wish to carry out their developments using the MPLAB IDE environment should find this appendix useful.

• PIC32MX795F512L microcontroller

• 10/100 Ethernet

• 2 × CAN network interfaces

• 4 × LEDs

• 3 × push-button switches

• 2 × USB connectors

• 2 × I2C bus interfaces

• MPLAB IDE and MPIDE support

• Program/debug circuit

• 6 × Pmod connectors

In this project, a program is developed using the MPLAB C32 compiler to flash LED 1 on the development board. This LED is connected to bit 12 of PORTG (RG12) and has the logical I/O port number 51. The program listing is shown in Figure A.2.

The steps to compile and load the program to the program memory of the chipKIT Pro MX7 development board are given as follows:

Step 1: Start the MPLAB IDE (see Figure A.3).

image

FIGURE A.3 MPLAB IDE Start-Up Window

Step 2: Click Project Project Wizard and click Next.

Select the device type as PIC32MX795F512L, and click Next.

Step 3: Select Microchip PIC32 C-compiler Toolsuite and click Next .

Step 4: Select the source file : LEDF.C and click Next.

Step 5: Add source file to the project by selecting it in the left pane and then clicking Add, and then click Next .

Step 6: Click Finish to exit the project wizard.

Step 7: You should see a list of project folders and the source files you have added to the project. Double click source file LEDF.C to display its contents (see Figure A.9).

image

FIGURE A.9 File LEDF.C

Step 8: Click Debugger Select Tool Licensed Debugger.

Connect the chipKIT MX7 development board to the PC using a USB-A to micro-B cable, connected to micro USB connector called DEBUG (connector J15), positioned on the left hand side of the board just below the Ethernet connector. Make sure that the jumper J3 is connected to position DBG.

When the licensed debugger is selected as the programming or debugging device, the MPLAB IDE will check the version number of the firmware running on the debugger and offer to update if it is out of date with the version of MPLAB being used.

Step 9: Check the Configuration Bits. Click Configure Configuration Bits from the top drop down menu of the IDE. Unclick the box “Configuration Bits set in code” so that the values given here take effect. Change the following Configuration Bits by clicking on the Bit to be changed (see Figure A.10):

image

FIGURE A.10 Configuration Bits

PLL Input Divider:

12

PLL Multiplier:

24

System PLL Output Clock Divider:

256

Oscillator Selection Bits:

Primary osc w/PLL (XT+,HS+,EC+PLL)

Primary Oscillator Configuration:

XT osc mode

Peripheral Clock Divisor:

Pb_Clk is Sys_Clk/1

Watchdog Timer Enable:

WDT Disabled

Step 10: The chipKIT Pro MX7 is designed to use the PGC1/PGD1 pair of pins for programming. Because of this, it is necessary to select the use of PGC1/PGD1 for the debugging interface. The following statement must be included at the beginning of the program to configure the microcontroller for use with the on-board licensed debugger circuit:

#pragma config ICESEL = ICS_PGx1

The MPLAB IDE may report an error indicating that the device is not configured for debugging until a program containing this statement has been programmed into the board.

The MCLR pin on the PIC32 microcontroller is used by the hardware programming/debugging interface to reset the processor. This same pin is used by the USB serial converter to reset the processor when using the MPIDE. It is possible that the reset function from the USB serial interface can interfere with correct operation of the Microchip programming and debugging tools. If this happens, jumper JP11 can be used to disconnect the USB serial converter reset circuit. Remove the shorting block from JP11 to disable the reset circuit. If the shorting block has been removed, it is necessary to reinstall it on JP11 in order to use the chipKIT Pro MX7 board with the MPIDE again.

Step 11: Click Build All from the top drop down menu to compile the program; you should have no errors (See Figure A.2).

Step 12: Use the Debugger Run command to program all memories on the device and start to run the program on the target microcontroller in debug mode.

The LED should now start flashing.

Reloading the BootLoader

Using the Microchip development tools to program the chipKIT Pro MX7 will erase the BootLoader loaded at the factory. To use the board with the chipKIT MPIDE again, it is necessary to program the BootLoader back onto the board. The programming file for the BootLoader programmed into the board by Digilent at the factory is available for download from the product page for the chipKIT Pro MX7 on the Digilent Inc. web site (in addition, the BootLoader source code is available in the chipKIT project repository at web site: www.github.com/chipKIT32/pic32-Arduino-BootLoader).

To reprogram the BootLoader using MPLAB, perform the following steps:

• Use the Configure Select Device menu to select the PIC32MX795F512L.

• Use the Debugger Select Tool Licensed Debugger.

• Use the File Import dialog box to navigate to and select the BootLoader programming downloaded from the Digilent web site. The file name will be something like: chipKIT_BootLoader_MX7cK.hex.

• Use the Programmer Program command to program all memories on the device.