Chris Styles
/
sub_SystemInit
An example program showing how to run the LPC11U24 without a crystal
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut myled(LED1); 00004 00005 extern int stdio_retargeting_module; 00006 00007 /** 00008 * Initialize the system 00009 * 00010 * @param none 00011 * @return none 00012 * 00013 * @brief Setup the microcontroller system. 00014 * Initialize the System. 00015 */ 00016 extern "C" void $Sub$$SystemInit (void) 00017 { 00018 00019 // select the PLL input 00020 LPC_SYSCON->SYSPLLCLKSEL = 0x0; // Select PLL Input source 0=IRC, 1=OSC 00021 LPC_SYSCON->SYSPLLCLKUEN = 0x01; /* Update Clock Source */ 00022 LPC_SYSCON->SYSPLLCLKUEN = 0x00; /* Toggle Update Register */ 00023 LPC_SYSCON->SYSPLLCLKUEN = 0x01; 00024 while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); /* Wait Until Updated */ 00025 00026 // Power up the system PLL 00027 LPC_SYSCON->SYSPLLCTRL = 0x00000023; 00028 LPC_SYSCON->PDRUNCFG &= ~(1 << 7); /* Power-up SYSPLL */ 00029 while (!(LPC_SYSCON->SYSPLLSTAT & 0x01)); /* Wait Until PLL Locked */ 00030 00031 // Select the main clock source 00032 LPC_SYSCON->MAINCLKSEL = 0x3; // Select main Clock source, 0=IRC, 1=PLLin, 2=WDO, 3=PLLout 00033 LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */ 00034 LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */ 00035 LPC_SYSCON->MAINCLKUEN = 0x01; 00036 while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */ 00037 00038 LPC_SYSCON->SYSAHBCLKDIV = 0x00000001; 00039 00040 LPC_SYSCON->PDRUNCFG &= ~(1 << 10); /* Power-up USB PHY */ 00041 LPC_SYSCON->PDRUNCFG &= ~(1 << 8); /* Power-up USB PLL */ 00042 LPC_SYSCON->USBPLLCLKSEL = 0x0; // 0=IRC, 1=System clock, only good for low speed 00043 LPC_SYSCON->USBPLLCLKUEN = 0x01; /* Update Clock Source */ 00044 LPC_SYSCON->USBPLLCLKUEN = 0x00; /* Toggle Update Register */ 00045 LPC_SYSCON->USBPLLCLKUEN = 0x01; 00046 00047 while (!(LPC_SYSCON->USBPLLCLKUEN & 0x01)); /* Wait Until Updated */ 00048 LPC_SYSCON->USBPLLCTRL = 0x00000023; 00049 00050 while (!(LPC_SYSCON->USBPLLSTAT & 0x01)); /* Wait Until PLL Locked */ 00051 LPC_SYSCON->USBCLKSEL = 0x00; /* Select USB PLL */ 00052 00053 LPC_SYSCON->USBCLKSEL = 0x00000000; /* Select USB Clock */ 00054 LPC_SYSCON->USBCLKDIV = 0x00000001; /* Set USB clock divider */ 00055 00056 /* System clock to the IOCON needs to be enabled or 00057 most of the I/O related peripherals won't work. */ 00058 LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); 00059 stdio_retargeting_module = 1; 00060 00061 } 00062 00063 00064 int main() 00065 { 00066 while(1) { 00067 myled = 1; 00068 wait(0.25); 00069 myled = 0; 00070 wait(0.25); 00071 } 00072 }
Generated on Fri Jul 15 2022 00:32:31 by 1.7.2