Hello,
please find here a nice trick permitting to use the USB on the PIC32MX2xx without using the external quartz.
The idea is to use the internal oscillator (at 8Mhz) and enable the reference clock output (divided by 2 so 4 Mhz).
Connecting this output (the REFCLKO signal) to the CLKI input using a wire, this clock can be routed to the PLL enabling it.
For sure, you still need 2 pins of the PIC (the REFCLKO and the CLKI) but you can remove the crystal.
Just for information this idea is not mine ...
Please find here the needed code to implement :
In the configuration file (ex. HardwareProfile.h)
//#define USB_USE_CRYSTAL // 8Mhz, in this case
/** CONFIGURATION **************************************************/
#pragma config UPLLEN = ON // USB PLL Enabled
#pragma config FPBDIV = DIV_1 // Peripheral Clock divisor
#pragma config FWDTEN = OFF // Watchdog Timer
#pragma config WDTPS = PS1 // Watchdog Timer Postscale
#pragma config OSCIOFNC = OFF // CLKO Enable
#pragma config IESO = OFF // Internal/External Switch-over
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (KLO was off)
#pragma config CP = OFF // Code Protect
#pragma config BWP = OFF // Boot Flash Write Protect
#pragma config PWP = OFF // Program Flash Write Protect
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select
#pragma config JTAGEN = OFF // JTAG Enable (JTAG Port Disabled)
#pragma config PMDL1WAY = OFF // Peripheral Module Disable Configuration (Allow multiple reconfigurations)
#pragma config IOL1WAY = OFF // Peripheral Pin Select Configuration (Allow multiple reconfigurations)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by the USB Module)
#pragma config FVBUSONIO= OFF // USB VBUS ON Selection (Controlled by USB Module)
#if defined(USB_USE_CRYSTAL)
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
#pragma config FPLLODIV = DIV_2 // PLL Output Divider
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits (Primary Osc w/PLL (XT+,HS+,EC+PLL))
#pragma config POSCMOD = HS // Primary Oscillator Configuration (HS osc mode)
#else
// specific setting useful to remove the crystal for the usb
//
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
#pragma config UPLLIDIV = DIV_1 // USB PLL Input Divider
#pragma config FPLLIDIV = DIV_1 // PLL Input Divider
#pragma config FPLLODIV = DIV_2 // PLL Output Divider
#pragma config FCKSM = CSECMD // Clock Switching and Monitor Selection (Clock Switch Enable, FSCM Disabled)
#pragma config FNOSC = FRC // Oscillator Selection Bits (Fast RC Osc (FRC))
#pragma config POSCMOD = EC // Primary Oscillator Configuration (External clock mode)
#endif
and the code in main.c
#ifndef USB_USE_CRYSTAL
// this setting is useful to remove the crystal
// the usb can work without it connecting RPA4(pin12) to CLKI(pin9)
PPSUnLock; // Allow PIN Mapping
PPSOutput(3, RPA4, REFCLKO);
PPSLock;
int intStat, dmaSusp;
OSCREFConfig(OSC_REFOCON_FRC, OSC_REFOCON_ON | OSC_REFOCON_OE, 1); // activate the reference clock output
mSYSTEMUnlock(intStat, dmaSusp);
OSCCONbits.NOSC = 0b011; // set Primary Oscillator with PLL module (XTPLL, HSPLL or ECPLL)
OSCCONbits.OSWEN = 1; // initiate the oscillator switch
mSYSTEMLock(intStat, dmaSusp);
#endif
You need to connect the pin 12 to the pin 9 to route the clock signal.
Hope this can be useful for someone of you.