void Chip_SystemInit(void) { /* IRC should be powered up */ // Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_IRC_PD); LPC_SYSCTL->PDRUNCFG &= ~(1 << 1); // Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_IRCOUT_PD); LPC_SYSCTL->PDRUNCFG &= ~(1 << 0); /* Set system PLL input to IRC */ // Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_IRC); LPC_SYSCTL->SYSPLLCLKSEL = 0; LPC_SYSCTL->SYSPLLCLKUEN = 0; LPC_SYSCTL->SYSPLLCLKUEN = 1; /* Power down PLL to change the PLL divider ratio */ // Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_SYSPLL_PD); LPC_SYSCTL->PDRUNCFG |= (1 << 7); /* Setup PLL for main oscillator rate (FCLKIN = 12MHz) * 4 = 48MHz */ // Chip_Clock_SetupSystemPLL(3, 1); LPC_SYSCTL->SYSPLLCTRL = 0x23; /* Powerup system PLL */ // Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSPLL_PD); LPC_SYSCTL->PDRUNCFG &= ~(1 << 7); /* Wait for PLL to lock (never locks) */ // while (!Chip_Clock_IsSystemPLLLocked()) {} while ((LPC_SYSCTL->SYSPLLSTAT & 1) == 0); ... } |
/* PDRUNCFG register mask */ #if defined(CHIP_LPC11AXX) #define PDRUNCFGUSEMASK 0x00000D08 #define PDRUNCFGMASKTMP 0x0001E0F7 #elif defined(CHIP_LPC11UXX) #define PDRUNCFGUSEMASK 0x0000E800 #define PDRUNCFGMASKTMP 0x000005FF #elif defined(CHIP_LPC1125) #define PDRUNCFGUSEMASK 0x0000ED00 #define PDRUNCFGMASKTMP 0x000000FF #else #define PDRUNCFGUSEMASK 0x0000ED00 #define PDRUNCFGMASKTMP 0x000000FF #endif void setup_clock(void) { uint32_t temp; //set main clock to IRC LPC_SYSCTL->MAINCLKSEL = 0; LPC_SYSCTL->MAINCLKUEN = 0; LPC_SYSCTL->MAINCLKUEN = 1; //PLL source: IRC LPC_SYSCTL->SYSPLLCLKSEL = 0;//IRC LPC_SYSCTL->SYSPLLCLKUEN = 0; LPC_SYSCTL->SYSPLLCLKUEN = 1; //power down PLL to change the PLL divider temp = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP; temp |= ((1<<7) & PDRUNCFGMASKTMP); LPC_SYSCTL->PDRUNCFG = (temp | PDRUNCFGUSEMASK); //set PLL LPC_SYSCTL->SYSPLLCTRL = (3 & 0x1F) | ((1 & 0x3) << 5); //power up PLL again temp = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP; temp &= ~((1<<7) & PDRUNCFGMASKTMP); LPC_SYSCTL->PDRUNCFG = (temp | PDRUNCFGUSEMASK); //wait until PLL is locked while ((LPC_SYSCTL->SYSPLLSTAT & 1) == 0); //set clock div LPC_SYSCTL->SYSAHBCLKDIV = 1; //Chip_FMC_SetFLASHAccess(FLASHTIM_50MHZ_CPU); temp = LPC_FMC->FLASHTIM & (~(0x3)); LPC_FMC->FLASHTIM = temp | 2; //set main clock to PLL out LPC_SYSCTL->MAINCLKSEL = 3; LPC_SYSCTL->MAINCLKUEN = 0; LPC_SYSCTL->MAINCLKUEN = 1; } |