1 /*
2  * Copyright 2018 NXP.
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 /*
9  * How to set up clock using clock driver functions:
10  *
11  * 1. Setup clock sources.
12  *
13  * 2. Setup voltage for the fastest of the clock outputs
14  *
15  * 3. Set up wait states of the flash.
16  *
17  * 4. Set up all dividers.
18  *
19  * 5. Set up all selectors to provide selected clocks.
20  */
21 
22 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
23 !!GlobalInfo
24 product: Clocks v5.0
25 processor: LPC51U68
26 mcu_data: ksdk2_0
27 processor_version: 0.0.4
28  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
29 
30 #include "fsl_power.h"
31 #include "fsl_clock.h"
32 #include "clock_config.h"
33 
34 /*******************************************************************************
35  * Definitions
36  ******************************************************************************/
37 
38 /*******************************************************************************
39  * Variables
40  ******************************************************************************/
41 /* System clock frequency. */
42 extern uint32_t SystemCoreClock;
43 
44 /*******************************************************************************
45  ************************ BOARD_InitBootClocks function ************************
46  ******************************************************************************/
BOARD_InitBootClocks(void)47 void BOARD_InitBootClocks(void)
48 {
49     BOARD_BootClockRUN();
50 }
51 
52 /*******************************************************************************
53  ********************** Configuration BOARD_BootClockRUN ***********************
54  ******************************************************************************/
55 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
56 !!Configuration
57 name: BOARD_BootClockRUN
58 called_from_default_init: true
59 outputs:
60 - {id: SYSTICK_clock.outFreq, value: 12 MHz}
61 - {id: System_clock.outFreq, value: 12 MHz}
62  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
63 
64 /*******************************************************************************
65  * Variables for BOARD_BootClockRUN configuration
66  ******************************************************************************/
67 /*******************************************************************************
68  * Code for BOARD_BootClockRUN configuration
69  ******************************************************************************/
BOARD_BootClockRUN(void)70 void BOARD_BootClockRUN(void)
71 {
72     /*!< Set up the clock sources */
73     /*!< Set up FRO */
74     POWER_DisablePD(kPDRUNCFG_PD_FRO_EN);                   /*!< Ensure FRO is on  */
75     CLOCK_SetupFROClocking(12000000U);                    /*!< Set up FRO to the 12 MHz, just for sure */
76     CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);                  /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
77                                                                 being below the voltage for current speed */
78     POWER_SetVoltageForFreq(12000000U);             /*!< Set voltage for the one of the fastest clock outputs: System clock output */
79     CLOCK_SetFLASHAccessCyclesForFreq(12000000U);   /*!< Set FLASH wait states for core */
80 
81     /*!< Set up dividers */
82     CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false);                  /*!< Set AHBCLKDIV divider to value 1 */
83     CLOCK_SetClkDiv(kCLOCK_DivSystickClk, 0U, true);                  /*!< Reset SYSTICKCLKDIV divider counter and halt it */
84     CLOCK_SetClkDiv(kCLOCK_DivSystickClk, 1U, false);                  /*!< Set SYSTICKCLKDIV divider to value 1 */
85 
86     /*!< Set up clock selectors - Attach clocks to the peripheries */
87     CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);                  /*!< Switch MAIN_CLK to FRO12M */
88     /*!< Set SystemCoreClock variable. */
89     SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
90 }
91 
92