This is a sample code showing a minimal configuration of a PIC32MX795F512L to get on RA1 a high level (logical 1) of a duration of one cycle at 80MIPS. The aim is to validate a simple design by verifying :
- The MPU is well powered,
- Its main oscillator is working and the PLL is well configured.
To do that, two files have to be added to a blank project in MPLABX using C32 or XC32 compilers :
- main.c
#include "HardwareProfile.h"
void CPUInit(void) {
SYSTEMConfigPerformance(SYS_FREQ);
DDPCONbits.JTAGEN = 0; // Disable JTAG
DDPCONbits.TROEN = 0; // Disable trace
PORTSetPinsDigitalOut(IOPORT_A,BIT_1);
}
int main(void) {
CPUInit();
while(1) {
mPORTASetBits(BIT_1);
mPORTAClearBits(BIT_1);
}
return 0;
}
void CPUInit(void) {
SYSTEMConfigPerformance(SYS_FREQ);
DDPCONbits.JTAGEN = 0; // Disable JTAG
DDPCONbits.TROEN = 0; // Disable trace
PORTSetPinsDigitalOut(IOPORT_A,BIT_1);
}
int main(void) {
CPUInit();
while(1) {
mPORTASetBits(BIT_1);
mPORTAClearBits(BIT_1);
}
return 0;
}
- HardwareProfile.h
#include <p32xxxx.h>
#include <plib.h>
//////////////////////////////////////////////////////////////////////////////////////////
// Configuration processeur //
// //
// Informations disponibles dans le fichier d'aide : //
// - hlpPIC32MXConfigSet.chm //
// - http://ww1.microchip.com/downloads/en/DeviceDoc/61156G.pdf //
// page 165 Section 28.1 - Configuration bits //
//////////////////////////////////////////////////////////////////////////////////////////
#pragma config FSRSSEL = PRIORITY_0 // Toutes les interruptions utilisent le shadow register
#pragma config FMIIEN = OFF // Interface Ethernet en mode RMII pour DP83848
#pragma config FETHIO = OFF // Configuration alternative des signaux du module Ethernet
#pragma config FCANIO = ON, FUSBIDIO = OFF, FVBUSONIO = OFF //Autres modules inutilises
#pragma config WDTPS = PS1, FWDTEN = OFF
#pragma config ICESEL = ICS_PGx1, DEBUG = OFF
#pragma config PWP = OFF, BWP = OFF, CP = OFF
////////// Configuration de l'oscillateur pour un quartz de 8MHz externe /////////////////
#pragma config FNOSC = PRIPLL // Choix de l'oscillateur primaire avec utilisation de la PLL
#pragma config POSCMOD = XT // Quartz < 10Mhz donc XT
#pragma config OSCIOFNC = ON
#pragma config FPLLIDIV = DIV_2, FPLLMUL = MUL_20, FPLLODIV = DIV_1 // 80Mips
#pragma config UPLLEN = ON, UPLLIDIV = DIV_2 // PLL USB
#pragma config FSOSCEN = OFF, IESO = OFF, FCKSM = CSDCMD // Autres parametres de l'oscillateur
#pragma config FPBDIV = DIV_1 // Horloge peripherique
//////////////////////////////////////////////////////////////////////////////////////////
// Definitions generiques //
// //
//////////////////////////////////////////////////////////////////////////////////////////
#define SYS_FREQ 80000000UL
#define GetPeripheralClock() (SYS_FREQ/(1 << OSCCONbits.PBDIV))
#define GetInstructionClock() (SYS_FREQ)
#include <plib.h>
//////////////////////////////////////////////////////////////////////////////////////////
// Configuration processeur //
// //
// Informations disponibles dans le fichier d'aide : //
// - hlpPIC32MXConfigSet.chm //
// - http://ww1.microchip.com/downloads/en/DeviceDoc/61156G.pdf //
// page 165 Section 28.1 - Configuration bits //
//////////////////////////////////////////////////////////////////////////////////////////
#pragma config FSRSSEL = PRIORITY_0 // Toutes les interruptions utilisent le shadow register
#pragma config FMIIEN = OFF // Interface Ethernet en mode RMII pour DP83848
#pragma config FETHIO = OFF // Configuration alternative des signaux du module Ethernet
#pragma config FCANIO = ON, FUSBIDIO = OFF, FVBUSONIO = OFF //Autres modules inutilises
#pragma config WDTPS = PS1, FWDTEN = OFF
#pragma config ICESEL = ICS_PGx1, DEBUG = OFF
#pragma config PWP = OFF, BWP = OFF, CP = OFF
////////// Configuration de l'oscillateur pour un quartz de 8MHz externe /////////////////
#pragma config FNOSC = PRIPLL // Choix de l'oscillateur primaire avec utilisation de la PLL
#pragma config POSCMOD = XT // Quartz < 10Mhz donc XT
#pragma config OSCIOFNC = ON
#pragma config FPLLIDIV = DIV_2, FPLLMUL = MUL_20, FPLLODIV = DIV_1 // 80Mips
#pragma config UPLLEN = ON, UPLLIDIV = DIV_2 // PLL USB
#pragma config FSOSCEN = OFF, IESO = OFF, FCKSM = CSDCMD // Autres parametres de l'oscillateur
#pragma config FPBDIV = DIV_1 // Horloge peripherique
//////////////////////////////////////////////////////////////////////////////////////////
// Definitions generiques //
// //
//////////////////////////////////////////////////////////////////////////////////////////
#define SYS_FREQ 80000000UL
#define GetPeripheralClock() (SYS_FREQ/(1 << OSCCONbits.PBDIV))
#define GetInstructionClock() (SYS_FREQ)