clock_config.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /***********************************************************************************************************************
  2. * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
  3. * will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
  4. **********************************************************************************************************************/
  5. /*
  6. * How to setup clock using clock driver functions:
  7. *
  8. * 1. CLOCK_SetSimSafeDivs, to make sure core clock, bus clock, flexbus clock
  9. * and flash clock are in allowed range during clock mode switch.
  10. *
  11. * 2. Call CLOCK_Osc0Init to setup OSC clock, if it is used in target mode.
  12. *
  13. * 3. Set MCG configuration, MCG includes three parts: FLL clock, PLL clock and
  14. * internal reference clock(MCGIRCLK). Follow the steps to setup:
  15. *
  16. * 1). Call CLOCK_BootToXxxMode to set MCG to target mode.
  17. *
  18. * 2). If target mode is FBI/BLPI/PBI mode, the MCGIRCLK has been configured
  19. * correctly. For other modes, need to call CLOCK_SetInternalRefClkConfig
  20. * explicitly to setup MCGIRCLK.
  21. *
  22. * 3). Don't need to configure FLL explicitly, because if target mode is FLL
  23. * mode, then FLL has been configured by the function CLOCK_BootToXxxMode,
  24. * if the target mode is not FLL mode, the FLL is disabled.
  25. *
  26. * 4). If target mode is PEE/PBE/PEI/PBI mode, then the related PLL has been
  27. * setup by CLOCK_BootToXxxMode. In FBE/FBI/FEE/FBE mode, the PLL could
  28. * be enabled independently, call CLOCK_EnablePll0 explicitly in this case.
  29. *
  30. * 4. Call CLOCK_SetSimConfig to set the clock configuration in SIM.
  31. */
  32. /* clang-format off */
  33. /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
  34. !!GlobalInfo
  35. product: Clocks v4.1
  36. processor: MK82FN256xxx15
  37. package_id: MK82FN256VLQ15
  38. mcu_data: ksdk2_0
  39. processor_version: 4.0.1
  40. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
  41. /* clang-format on */
  42. #include "clock_config.h"
  43. /*******************************************************************************
  44. * Definitions
  45. ******************************************************************************/
  46. #define MCG_IRCLK_DISABLE 0U /*!< MCGIRCLK disabled */
  47. #define MCG_PLL_DISABLE 0U /*!< MCGPLLCLK disabled */
  48. #define OSC_CAP0P 0U /*!< Oscillator 0pF capacitor load */
  49. #define SIM_LPUART_CLK_SEL_OSCERCLK_CLK 2U /*!< LPUART clock select: OSCERCLK clock */
  50. #define SIM_OSC32KSEL_OSC32KCLK_CLK 0U /*!< OSC32KSEL select: OSC32KCLK clock */
  51. #define SIM_PLLFLLSEL_MCGFLLCLK_CLK 0U /*!< PLLFLL select: MCGFLLCLK clock */
  52. #define SIM_TRACE_CLK_DIV_1 0U /*!< Trace clock divider divisor: divided by 1 */
  53. #define SIM_TRACE_CLK_FRAC_1 0U /*!< Trace clock divider fraction: multiplied by 1 */
  54. #define SIM_TRACE_CLK_SEL_CORE_SYSTEM_CLK 1U /*!< Trace clock select: Core/system clock */
  55. /*******************************************************************************
  56. * Variables
  57. ******************************************************************************/
  58. /* System clock frequency. */
  59. extern uint32_t SystemCoreClock;
  60. /*******************************************************************************
  61. * Code
  62. ******************************************************************************/
  63. /*FUNCTION**********************************************************************
  64. *
  65. * Function Name : CLOCK_CONFIG_FllStableDelay
  66. * Description : This function is used to delay for FLL stable.
  67. *
  68. *END**************************************************************************/
  69. static void CLOCK_CONFIG_FllStableDelay(void)
  70. {
  71. uint32_t i = 30000U;
  72. while (i--)
  73. {
  74. __NOP();
  75. }
  76. }
  77. /*******************************************************************************
  78. ************************ BOARD_InitBootClocks function ************************
  79. ******************************************************************************/
  80. void BOARD_InitBootClocks(void)
  81. {
  82. BOARD_BootClockRUN();
  83. }
  84. /*******************************************************************************
  85. ********************** Configuration BOARD_BootClockRUN ***********************
  86. ******************************************************************************/
  87. /* clang-format off */
  88. /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
  89. !!Configuration
  90. name: BOARD_BootClockRUN
  91. called_from_default_init: true
  92. outputs:
  93. - {id: Bus_clock.outFreq, value: 7.37 MHz}
  94. - {id: Core_clock.outFreq, value: 7.37 MHz}
  95. - {id: Flash_clock.outFreq, value: 7.37 MHz}
  96. - {id: FlexBus_clock.outFreq, value: 7.37 MHz}
  97. - {id: LPO_clock.outFreq, value: 1 kHz}
  98. - {id: LPUARTCLK.outFreq, value: 7.37 MHz}
  99. - {id: MCGFFCLK.outFreq, value: 57.578125/2 kHz}
  100. - {id: MCGFLLCLK.outFreq, value: 21.07359375 MHz}
  101. - {id: OSCERCLK.outFreq, value: 7.37 MHz}
  102. - {id: OSCERCLK_UNDIV.outFreq, value: 7.37 MHz}
  103. - {id: PLLFLLCLK.outFreq, value: 21.07359375 MHz}
  104. - {id: System_clock.outFreq, value: 7.37 MHz}
  105. - {id: TRACECLKIN.outFreq, value: 7.37 MHz}
  106. settings:
  107. - {id: MCGMode, value: FBE}
  108. - {id: LPUARTClkConfig, value: 'yes'}
  109. - {id: MCG.CLKS.sel, value: MCG.OSCSEL}
  110. - {id: MCG.FLL_mul.scale, value: '732'}
  111. - {id: MCG.FRDIV.scale, value: '256'}
  112. - {id: MCG.IREFS.sel, value: MCG.FRDIV}
  113. - {id: MCG_C2_RANGE0_CFG, value: High}
  114. - {id: MCG_C2_RANGE0_FRDIV_CFG, value: High}
  115. - {id: OSC_CR_ERCLKEN_CFG, value: Enabled}
  116. - {id: OSC_CR_ERCLKEN_UNDIV_CFG, value: Enabled}
  117. - {id: OSC_CR_EREFSTEN_CFG, value: Enabled}
  118. - {id: OSC_CR_EREFSTEN_UNDIV_CFG, value: Enabled}
  119. - {id: SIM.LPUARTSRCSEL.sel, value: OSC.OSCERCLK}
  120. - {id: SIM.OUTDIV3.scale, value: '1', locked: true}
  121. - {id: SIM.OUTDIV4.scale, value: '1', locked: true}
  122. - {id: TraceClkConfig, value: 'yes'}
  123. sources:
  124. - {id: OSC.OSC.outFreq, value: 7.37 MHz, enabled: true}
  125. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
  126. /* clang-format on */
  127. /*******************************************************************************
  128. * Variables for BOARD_BootClockRUN configuration
  129. ******************************************************************************/
  130. const mcg_config_t mcgConfig_BOARD_BootClockRUN =
  131. {
  132. .mcgMode = kMCG_ModeFBE, /* FBE - FLL Bypassed External */
  133. .irclkEnableMode = MCG_IRCLK_DISABLE, /* MCGIRCLK disabled */
  134. .ircs = kMCG_IrcSlow, /* Slow internal reference clock selected */
  135. .fcrdiv = 0x1U, /* Fast IRC divider: divided by 2 */
  136. .frdiv = 0x3U, /* FLL reference clock divider: divided by 256 */
  137. .drs = kMCG_DrsLow, /* Low frequency range */
  138. .dmx32 = kMCG_Dmx32Fine, /* DCO is fine-tuned for maximum frequency with 32.768 kHz reference */
  139. .oscsel = kMCG_OscselOsc, /* Selects System Oscillator (OSCCLK) */
  140. .pll0Config =
  141. {
  142. .enableMode = MCG_PLL_DISABLE, /* MCGPLLCLK disabled */
  143. .prdiv = 0x0U, /* PLL Reference divider: divided by 1 */
  144. .vdiv = 0x0U, /* VCO divider: multiplied by 16 */
  145. },
  146. };
  147. const sim_clock_config_t simConfig_BOARD_BootClockRUN =
  148. {
  149. .pllFllSel = SIM_PLLFLLSEL_MCGFLLCLK_CLK, /* PLLFLL select: MCGFLLCLK clock */
  150. .pllFllDiv = 0, /* PLLFLLSEL clock divider divisor: divided by 1 */
  151. .pllFllFrac = 0, /* PLLFLLSEL clock divider fraction: multiplied by 1 */
  152. .er32kSrc = SIM_OSC32KSEL_OSC32KCLK_CLK, /* OSC32KSEL select: OSC32KCLK clock */
  153. .clkdiv1 = 0x0U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV2: /1, OUTDIV3: /1, OUTDIV4: /1 */
  154. };
  155. const osc_config_t oscConfig_BOARD_BootClockRUN =
  156. {
  157. .freq = 7370000U, /* Oscillator frequency: 7370000Hz */
  158. .capLoad = (OSC_CAP0P), /* Oscillator capacity load: 0pF */
  159. .workMode = kOSC_ModeExt, /* Use external clock */
  160. .oscerConfig =
  161. {
  162. .enableMode = kOSC_ErClkEnable | kOSC_ErClkEnableInStop,/* Enable external reference clock, enable external reference clock in STOP mode */
  163. .erclkDiv = 0, /* Divider for OSCERCLK: divided by 1 */
  164. }
  165. };
  166. /*******************************************************************************
  167. * Code for BOARD_BootClockRUN configuration
  168. ******************************************************************************/
  169. void BOARD_BootClockRUN(void)
  170. {
  171. /* Set the system clock dividers in SIM to safe value. */
  172. CLOCK_SetSimSafeDivs();
  173. /* Initializes OSC0 according to board configuration. */
  174. CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
  175. CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
  176. /* Set MCG to FBE mode. */
  177. CLOCK_SetExternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.oscsel);
  178. CLOCK_SetFbeMode(mcgConfig_BOARD_BootClockRUN.frdiv,
  179. mcgConfig_BOARD_BootClockRUN.dmx32,
  180. mcgConfig_BOARD_BootClockRUN.drs,
  181. CLOCK_CONFIG_FllStableDelay);
  182. /* Set the clock configuration in SIM module. */
  183. CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
  184. /* Set SystemCoreClock variable. */
  185. SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
  186. /* Set LPUART clock source. */
  187. CLOCK_SetLpuartClock(SIM_LPUART_CLK_SEL_OSCERCLK_CLK);
  188. /* Set debug trace clock source. */
  189. CLOCK_SetTraceClock(SIM_TRACE_CLK_SEL_CORE_SYSTEM_CLK, SIM_TRACE_CLK_DIV_1, SIM_TRACE_CLK_FRAC_1);
  190. }