Getting Started with PIC32 User’s Guide © 2008 Microchip Technology Inc.
Note the following details of the code protection feature on Microchip devices: • Microchip products meet the specification contained in their particular Microchip Data Sheet. • Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions. • There are dishonest and possibly illegal methods used to breach the code protection feature.
GETTING STARTED WITH PIC32 Table of Contents Preface ........................................................................................................................... 1 Chapter 1. PIC32 Features 1.1 Introduction ..................................................................................................... 7 1.2 Highlights ........................................................................................................ 7 Chapter 2. PIC32 Product Family 2.1 Introduction ..............
Getting Started with PIC32 NOTES: DS61146B-page iv © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32 Preface NOTICE TO CUSTOMERS All documentation becomes dated, and this manual is no exception. Microchip tools and documentation are constantly evolving to meet customer needs, so some actual dialogs and/or tool descriptions may differ from those in this document. Please refer to our web site (www.microchip.com) to obtain the latest documentation available. Documents are identified with a “DS” number. This number is located on the bottom of each page, in front of the page number.
Getting Started with PIC32 DOCUMENT LAYOUT This document is divided into 6 sections. Sections 1 through 4 provide an overview of PIC32 products. Section 5 provides an overview of PIC32 development tools. Section 6 describes the procedure to setup a development environment and debug a sample application. The manual layout is as follows: • • • • • Chapter 1. PIC32 Features Chapter 2. PIC32 Product Family Chapter 3. PIC32 Architecture Chapter 4. PIC32 Tools Chapter 5.
Preface CONVENTIONS USED IN THIS GUIDE This manual uses the following documentation conventions: DOCUMENTATION CONVENTIONS Description Arial font: Italic characters Initial caps Quotes Underlined, italic text with right angle bracket Bold characters N‘Rnnnn Text in angle brackets < > Courier New font: Plain Courier New Represents Referenced books Emphasized text A window A dialog A menu selection A field name in a window or dialog A menu path MPLAB® IDE User’s Guide ...is the only compiler...
Getting Started with PIC32 RECOMMENDED READING This user's guide describes how to use PIC32. Other useful documents are listed below. The following Microchip documents are available and recommended as supplemental reference resources. Readme for the PIC32MX For the latest information on using PIC32 microcontrollers, read the file (an ASCII text file) at the root level of the CD included in the PIC32 Starter Kit.
Preface DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICE Microchip’s customer notification service helps keep customers current on Microchip products. Subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. To register, access the Microchip web site at www.microchip.com, click on Customer Change Notification and follow the registration instructions.
Getting Started with PIC32 NOTES: DS61146B-page 6 © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32 Chapter 1. PIC32 Features 1.1 INTRODUCTION The PIC32 is a 32-bit family of general purpose microcontrollers from Microchip Technology. It offers 80+ DMIPS performance with a wide variety of on-chip peripherals. It employs industry leading M4K MIPS32 core from MIPS Technologies, Inc. All members in the PIC32 family use programming interface similar to other Microchip PIC® microcontrollers.
Getting Started with PIC32 Ease of Use: • PIC® microcontroller “look and feel” peripherals • Standard MPLAB® tool-suite – MPLAB IDE, MPLAB C32 C Compiler, MPLAB REAL ICE™, and MPLAB ICD 2. • Software Peripheral Libraries compatible with those for Microchip 16-bit microcontrollers • Microchip developed middleware modules such as TCP/IP and 16-bit file system DS61146B-page 8 © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32 Chapter 2. PIC32 Product Family 2.1 INTRODUCTION The PIC32 family includes scalable devices ranging from 32KB to 512KB of Flash memory. Also a rich set of peripherals – Five timers, 16 channels of 10-bit A/D Converters and communication interfaces: SPI, I2C™ and UART. Please consult the “PIC32MX Family Data Sheet” (DS61143) for a complete list of family variants, core and peripheral characteristics.
Getting Started with PIC32 NOTES: DS61146B-page 10 © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32 Chapter 3. PIC32 Architecture 3.1 INTRODUCTION The PIC32 family of MCUs combines the MIPS M4K core together with powerful peripherals and embedded Flash and RAM memory to address a wide range of applications.
Getting Started with PIC32 Processor core: • • • • • • MIPS M4K with 5-stage pipeline MIPS32-compatible Release 2 Instruction Set MIPS16e™ Code Compression to improve code density by up to 40% GPR shadow registers to minimize latency for interrupt handlers Bit field manipulation instructions High-performance Multiply/Divide Unit: - Maximum issue rate of one 32x16 multiply per clock - Maximum issue rate of one 32x32 multiply every other clock • Static implementation: minimum operating frequency 0 MHz • 2.
PIC32 Architecture Communication channels: • • • • USB 2.0 compliant (FS.
Getting Started with PIC32 GPIO: • • • • 5V tolerant inputs Individual output pin open-drain enable/disable Individual input pin weak pull-up enable/disable Monitor selective inputs and generate interrupt on mismatch condition Note: DS61146B-page 14 Input pin weak pull-up and interrupt on mismatch features are available only on select I/O pins. © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32 Chapter 4. PIC32 Tools 4.1 INTRODUCTION The PIC32 microcontrollers are supported by the MPLAB Integrated Development Environment and its full range of hardware and software tools. 4.2 HIGHLIGHTS Items discussed in this chapter are: • • • • • • 4.
Getting Started with PIC32 4.4 MPLAB C32 C COMPILER The MPLAB C32 C Compiler package allows you to build your applications and contains the following key software components (see Figure 4-1). • PIC32-gcc Compiler: complete ANSI C compiler with powerful integration capabilities and efficient code optimization. The compiler provides symbol information that is used by the MPLAB IDE debugger. • PIC32-gpp Macro Processor: used automatically by the compiler to transform the program before compilation.
PIC32 Tools 4.5 PERIPHERAL LIBRARIES PIC32 MCUs integrate a large number of on-chip high-performance peripherals. To accelerate the usage of these peripherals, the MPLAB C32 compiler for PIC32 includes software peripheral libraries compatible with the 16-bit Microchip MCUs. The peripheral libraries are distributed in source and object format along with a detailed API description document.
Getting Started with PIC32 TABLE 4-1: PERIPHERAL LIBRARY Peripheral ADC adc10.h Description Library for the Analog-to-Digital converters support Memory Org bmx.h Library for configuring the Bus Matrix internal buses, priorities and memory layout Analog Comparators cmp.h Library for the Comparator modules support Comparator Voltage Reference cvref.h Library for the Comparators Voltage reference support DMA Controller dma.
PIC32 Tools 4.6 SOFTWARE SOLUTIONS At the time of writing this document, Microchip had not released any drivers. Microchip does intend to develop drivers for key communication peripherals. 4.6.1 Middleware The following list provides the Microchip middleware components available at the time of writing this document: • 16-bit file system on SD Memory to support Microsoft MS-DOS file system.
Getting Started with PIC32 4.7 DEMONSTRATION, DEVELOPMENT AND EVALUATION BOARDS A wide variety of demonstration, development and evaluation boards for PIC32 MCUs allow quick application development on fully functional systems. Most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. These boards support a variety of features, including LEDs, switches, RS-232 interfaces, LCD displays, etc.
GETTING STARTED WITH PIC32 Chapter 5. Step-by-Step Procedures to Setup, Build, and Run a Demo Project 5.1 INTRODUCTION In this step-by-step procedure, the basic concepts of the MPLAB Project Manager, Editor and Debugger will be presented. You will create a simple project and understand the debug capabilities of MPLAB IDE. No previous MPLAB IDE knowledge is assumed. For complete features set and comprehensive technical details of MPLAB IDE and its components, please visit our web site (www.microchip.
Getting Started with PIC32 5.3.3 Running MPLAB IDE To start MPLAB IDE, double click on the icon installed on the desktop after installation or select Start>Programs>Microchip>MPLAB IDE vx.xx>MPLAB IDE. A screen will display the MPLAB IDE logo followed by the MPLAB IDE desktop. FIGURE 5-1: 5.4 MPLAB IDE START SCREEN STEP-BY-STEP GUIDE OVERVIEW To create code that is executable by the PIC32 MCU, source files need to be part of a project.
Step-by-Step Procedures to Setup, Build, and Run a Demo Project Some very simple code will be added to the template file to print a “Hello World…” string to a serial console connected to the evaluation board. We will use the UART Peripheral Library provided by Microchip. - Build Project The project will be built – causing the source files to be compiled and linked into machine code that can run on the selected PIC32 MCU. - Test Code Finally, the code will be tested by running it on the evaluation board.
Getting Started with PIC32 5.6 CREATING THE PROJECT The next step is to create a project using the Project Wizard. A project is the way the files are organized to be compiled, assembled and linked. We will use a single “C” file for this project and a linker script. Choose Project>Project Wizard. From the Welcome dialog, click on Next> to advance. The Step One dialog allows you to select the device, which we’ve already done. Make sure that it displays the proper PIC32 variant.
Step-by-Step Procedures to Setup, Build, and Run a Demo Project 5.7 SETTING UP LANGUAGE TOOLS Step Two of the Project Wizard sets up the language tools that are used with this project. Make sure the “Show all installed toolsuites” checkbox is checked. Select Microchip PIC32 C Compiler Toolsuite in the Active Toolsuite list box. Then “MPLAB PIC32 Assembler (PIC32-as.exe)”, “MPLAB PIC32 C Compiler (PIC32-gcc.exe)”, “MPLAB PIC32 Object Linker (PIC32-ld.exe)”, and “MPLAB PIC32 Archiver (PIC32-ar.
Getting Started with PIC32 5.8 NAMING THE PROJECT Step Three of the wizard allows you to name the project and put it into a folder. This sample project will be called MyTestProject. Using the Browse button, place the project in a folder named Projects32. Click Next>. FIGURE 5-5: DS61146B-page 26 MPLAB IDE NAMING THE PROJECT © 2008 Microchip Technology Inc.
Step-by-Step Procedures to Setup, Build, and Run a Demo Project 5.9 ADDING FILES TO THE PROJECT Step Four of the Project Wizard allows file selection for the project. This is where we can add existing files to our project. In the current example we don’t have a previously created file but we’ll create one once we’re done with the new project setting.
Getting Started with PIC32 Be sure to save the workspace in the Projects32 directory and name this workspace using the same name as for the project: MyTestProject. Click Save. The project space is now completely created and it should look like that: FIGURE 5-8: MPLAB IDE PROJECT SAVE Now we’ll create our C source file. If the MPLAB IDE Editor window is not open, click File->New from the top menu or the New File menu shortcut on the standard toolbar. The Editor window will show up.
Step-by-Step Procedures to Setup, Build, and Run a Demo Project FIGURE 5-9: MPLAB IDE MAIN.C FILE To add the newly created main.c file to our project just right click on the Source Files folder in the MPLAB IDE MyTestProject.mcp window and select Add File. Browse and select main.c file from the Projects32 directory. Note: If the Project window is not open, select View->Project from the top IDE menu. The linker script that’s needed for this project is selected automatically by the MPLAB IDE.
Getting Started with PIC32 Right click on MyTestProject.mcp window and select Save. The test project should be saved. The MyTestProject.mcp should look like: FIGURE 5-10: MPLAB IDE PROJECT SAVED TIP: Files can be added and projects saved by using the right mouse button in the project window. In case of error, files can be manually deleted by selecting them and using the right mouse click menu. DS61146B-page 30 © 2008 Microchip Technology Inc.
Step-by-Step Procedures to Setup, Build, and Run a Demo Project 5.10 ATTACHING THE DEBUGGER In order to test the code using the PIC32 Starter Kit, please refer to the PIC32MX Starter Kit User’s Guide (DS61144 ) for a sample project and a step-by-step getting started info.
Getting Started with PIC32 5.11 BUILDING THE PROJECT From the Project menu, we can compile and link the current files. To build the project, select either: - Project>Build All - Right click on the project name in the project window and select Build All - Click the Build All icon on the Project toolbar. Hover the mouse over icons to see pop-up text of what they represent. The Output window shows the result of the build process. There should be no errors on any step. FIGURE 5-12: 5.
Step-by-Step Procedures to Setup, Build, and Run a Demo Project FIGURE 5-13: HYPER TERMINAL CONNECTION SCREEN Click OK and, on the next screen, select the following communication settings: • • • • • Bits Per Second: 57600 Data Bits: 8 Parity: None Stop Bits: 1 Flow Control: None Click OK and the Hyper Terminal session should be connected to the serial port on the development board. Now return to the MPLAB IDE and double click on the line: return nc; in the MPLAB IDE Editor window, the main.
Getting Started with PIC32 FIGURE 5-14: MPLAB IDE BREAKPOINT REACHED 4 6 3 5 8 1 1. 2. 3. 4. 5. 6. 7. 8.
Step-by-Step Procedures to Setup, Build, and Run a Demo Project Also, if you look at the Explorer 16 board, you should see the LED D9 lit on. This shows that the PIC32 Explorer16 demo board and the MPLAB IDE operate correctly. We just made our first “Hello World” program for PIC32. There are many other things that you can do in the MPLAB IDE to debug your program.
Getting Started with PIC32 NOTES: DS61146B-page 36 © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32 Chapter 6. Technical Support Resources 6.1 INTRODUCTION For information about the Technical Support provided please visit Support.microchip.com. © 2008 Microchip Technology Inc.
Getting Started with PIC32 NOTES: DS61146B-page 38 © 2008 Microchip Technology Inc.
GETTING STARTED WITH PIC32 Index A Attaching the Debugger Connecting MPLAB REAL ICE ........................ 31 C Customer Notification Service ................................... 5 Customer Support ..................................................... 5 D Documentation Conventions ....................................................... 3 Layout ................................................................ 2 I Internet Address ........................................................
WORLDWIDE SALES AND SERVICE AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE Corporate Office 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://support.microchip.com Web Address: www.microchip.