📄 startup.c
字号:
#include "startup.h"
void startup(void)
{
unsigned int m;
unsigned int n;
unsigned int clk_div;
unsigned int clk_div_usb;
m = 11; /* PLL Multiplier = 20, MSEL bits = 12 - 1 = 11 */
n = 0; /* PLL Divider = 1, NSEL bits = 1 - 1 = 0 */
clk_div = 3; /* Configure the ARM Core clock div to 6. CCLKSEL = 6 - 1 */
clk_div_usb = 6; /* Configure the USB clock divider to 6, USBSEL = 6 - 1 */
if ((PLLSTAT & 0x02000000) > 0)
{ /* If the PLL is already running */
PLLCON &= ~0x00000002; /* Disconnect the PLL */
PLLFEED = 0xAA; /* PLL register update sequence, 0xAA, 0x55 */
PLLFEED = 0x55;
}
PLLCON &= ~0x00000001; /* Disable the PLL */
PLLFEED = 0xAA; /* PLL register update sequence, 0xAA, 0x55 */
PLLFEED = 0x55;
SCS &= ~0x00000010; /* OSCRANGE = 0, Main OSC is between 1 and 20 Mhz */
SCS |= 0x00000020; /* OSCEN = 1, Enable the main oscillator */
while ((SCS & 0x00000040) == 0) { /* Wait until OSCSTAT is set (Main OSC ready to be used) */
;
}
CLKSRCSEL = 0x00000001; /* Select main OSC, 12MHz, as the PLL clock source */
PLLCFG = (m << 0) | (n << 16); /* Configure the PLL multiplier and divider */
PLLFEED = 0xAA; /* PLL register update sequence, 0xAA, 0x55 */
PLLFEED = 0x55;
PLLCON |= 0x00000001; /* Enable the PLL */
PLLFEED = 0xAA; /* PLL register update sequence, 0xAA, 0x55 */
PLLFEED = 0x55;
CCLKCFG = clk_div; /* Configure the ARM Core Processor clock divider */
USBCLKCFG = clk_div_usb; /* Configure the USB clock divider */
while ((PLLSTAT & 0x04000000) == 0) { /* Wait for PLOCK to become set */
;
}
PCLKSEL0 = 0xAAAAAAAA; /* Set peripheral clocks to be half of main clock */
PCLKSEL1 = 0x22AAA8AA;
PLLCON |= 0x00000002; /* Connect the PLL. The PLL is now the active clock source */
PLLFEED = 0xAA; /* PLL register update sequence, 0xAA, 0x55 */
PLLFEED = 0x55;
while ((PLLSTAT & 0x02000000) == 0) { /* Wait PLLC, the PLL connect status bit to become set */
;
}
/* MAM Initialize */
MAMCR = 0;
MAMTIM = 3;
MAMCR = 2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -