打开M472 442的bsp;
NUC472_NUC442_BSP_CMSIS_V3.02.000\SampleCode\StdDriver\SYS_Control
里面有个例程SYS_Control
.
- int32_t main (void)
- {
- uint32_t u32data;
- /* Lock protected registers */
- if(SYS->REGLCTL == 1) // In end of main function, program issued CPU reset and write-protection will be disabled.
- SYS_LockReg();
- /* Init System, IP clock and multi-function I/O */
- SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.
- /* Init UART0 for printf */
- UART0_Init();
- printf("\n\nCPU @ %dHz\n", SystemCoreClock);
- /*
- This sample code will show some function about system manager controller and clock controller:
- 1. Read PDID
- 2. Get and clear reset source
- 3. Setting about BOD
- 4. Change system clock depended on different PLL settings
- 5. Output system clock from CKO pin, and the output frequency = system clock / 4
- */
- printf("+---------------------------------------+\n");
- printf("| System Driver Sample Code |\n");
- printf("+---------------------------------------+\n");
- if (M32(FLAG_ADDR) == SIGNATURE) {
- printf(" CPU Reset success!\n");
- M32(FLAG_ADDR) = 0;
- printf(" Press any key to continue ...\n");
- getchar();
- }
- /*---------------------------------------------------------------------------------------------------------*/
- /* Misc system function test */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Read Part Device ID */
- printf("Product ID 0x%x\n", SYS->PDID);
- /* Get reset source from last operation */
- u32data = SYS->RSTSTS;
- printf("Reset Source 0x%x\n", u32data);
- /* Clear reset source */
- SYS->RSTSTS = u32data;
- /* Unlock protected registers for Brown-Out Detector settings */
- SYS_UnlockReg();
- /* Check if the write-protected registers are unlocked before BOD setting and CPU Reset */
- if (SYS->REGLCTL != 0) {
- printf("Protected Address is Unlocked\n");
- }
- /* Enable Brown-Out Detector and Low Voltage Reset function, and set Brown-Out Detector voltage 2.7V */
- SYS->BODCTL =SYS_BODCTL_BODEN_Msk | SYS_BODCTL_BODVL_2_7V | SYS_BODCTL_LVREN_Msk;
- /* Enable Brown-Out Interrupt function */
- SYS->BODCTL &= ~SYS_BODCTL_BODRSTEN_Msk;
- NVIC_EnableIRQ(BOD_IRQn);
- /* Get system clock frequency and PLL clock frequency */
- printf(" Change system clock to %d Hz and PLL clock is %d Hz\n", SystemCoreClock, CLK_GetPLLClockFreq());
- /* Run PLL Test */
- SYS_PLL_Test();
- /* Write a signature work to SRAM to check if it is reset by software */
- M32(FLAG_ADDR) = SIGNATURE;
- printf("\n\n >>> Reset CPU <<<\n");
- /* Waiting for message send out */
- UART_WAIT_TX_EMPTY(UART0);
- /* Switch HCLK clock source to Internal 22MHz */
- CLK->CLKSEL0 = CLK_CLKSEL0_HCLKSEL_HIRC;
- /* Set PLL to Power down mode and HW will also clear PLLSTB bit in CLKSTATUS register */
- CLK->PLLCTL |= CLK_PLLCTL_PD_Msk;
- /* Reset CPU */
- SYS_ResetCPU();
- }
复制代码
|