clock_config.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * How to set up clock using clock driver functions:
  36. *
  37. * 1. Setup clock sources.
  38. *
  39. * 2. Setup voltage for the fastest of the clock outputs
  40. *
  41. * 3. Set up wait states of the flash.
  42. *
  43. * 4. Set up all dividers.
  44. *
  45. * 5. Set up all selectors to provide selected clocks.
  46. */
  47. /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
  48. !!ClocksProfile
  49. product: Clocks v1.0
  50. processor: LPC54114J256
  51. mcu_data: ksdk2_0
  52. processor_version: 1.1.0
  53. board: LPCXpresso54114
  54. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  55. #include "fsl_power.h"
  56. #include "fsl_clock.h"
  57. #include "clock_config.h"
  58. /*******************************************************************************
  59. * Definitions
  60. ******************************************************************************/
  61. /*******************************************************************************
  62. * Variables
  63. ******************************************************************************/
  64. /* System clock frequency. */
  65. extern uint32_t SystemCoreClock;
  66. /*******************************************************************************
  67. ************************ BOARD_InitBootClocks function ************************
  68. ******************************************************************************/
  69. void BOARD_InitBootClocks(void)
  70. {
  71. BOARD_BootClockFROHF48M();
  72. }
  73. /*******************************************************************************
  74. ********************* Configuration BOARD_BootClockFRO12M ***********************
  75. ******************************************************************************/
  76. /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
  77. !!Configuration
  78. name: BOARD_BootClockFRO12M
  79. outputs:
  80. - {id: System_clock.outFreq, value: 12 MHz}
  81. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  82. /*******************************************************************************
  83. * Variables for BOARD_BootClockFRO12M configuration
  84. ******************************************************************************/
  85. /*******************************************************************************
  86. * Code for BOARD_BootClockFRO12M configuration
  87. ******************************************************************************/
  88. void BOARD_BootClockFRO12M(void)
  89. {
  90. /*!< Set up the clock sources */
  91. /*!< Set up FRO */
  92. POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
  93. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
  94. being below the voltage for current speed */
  95. CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
  96. POWER_SetVoltageForFreq(12000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
  97. CLOCK_SetFLASHAccessCyclesForFreq(12000000U); /*!< Set FLASH wait states for core */
  98. /*!< Set up dividers */
  99. CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
  100. /*!< Set up clock selectors - Attach clocks to the peripheries */
  101. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO12M */
  102. /*!< Set SystemCoreClock variable. */
  103. SystemCoreClock = BOARD_BOOTCLOCKFRO12M_CORE_CLOCK;
  104. }
  105. /*******************************************************************************
  106. ********************** Configuration BOARD_BootClockFROHF48M ***********************
  107. ******************************************************************************/
  108. /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
  109. !!Configuration
  110. name: BOARD_BootClockFROHF48M
  111. outputs:
  112. - {id: System_clock.outFreq, value: 48 MHz}
  113. settings:
  114. - {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
  115. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  116. /*******************************************************************************
  117. * Variables for BOARD_BootClockFROHF48M configuration
  118. ******************************************************************************/
  119. /*******************************************************************************
  120. * Code for BOARD_BootClockFROHF48M configuration
  121. ******************************************************************************/
  122. void BOARD_BootClockFROHF48M(void)
  123. {
  124. /*!< Set up the clock sources */
  125. /*!< Set up FRO */
  126. POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
  127. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
  128. being below the voltage for current speed */
  129. POWER_SetVoltageForFreq(48000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
  130. CLOCK_SetFLASHAccessCyclesForFreq(48000000U); /*!< Set FLASH wait states for core */
  131. CLOCK_SetupFROClocking(48000000U); /*!< Set up high frequency FRO output to selected frequency */
  132. /*!< Set up dividers */
  133. CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
  134. /*!< Set up clock selectors - Attach clocks to the peripheries */
  135. CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
  136. /*!< Set SystemCoreClock variable. */
  137. SystemCoreClock = BOARD_BOOTCLOCKFROHF48M_CORE_CLOCK;
  138. }
  139. /*******************************************************************************
  140. ********************* Configuration BOARD_BootClockFROHF96M **********************
  141. ******************************************************************************/
  142. /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
  143. !!Configuration
  144. name: BOARD_BootClockFROHF96M
  145. outputs:
  146. - {id: System_clock.outFreq, value: 96 MHz}
  147. settings:
  148. - {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
  149. sources:
  150. - {id: SYSCON.fro_hf.outFreq, value: 96 MHz}
  151. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  152. /*******************************************************************************
  153. * Variables for BOARD_BootClockFROHF96M configuration
  154. ******************************************************************************/
  155. /*******************************************************************************
  156. * Code for BOARD_BootClockFROHF96M configuration
  157. ******************************************************************************/
  158. void BOARD_BootClockFROHF96M(void)
  159. {
  160. /*!< Set up the clock sources */
  161. /*!< Set up FRO */
  162. POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
  163. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
  164. being below the voltage for current speed */
  165. POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
  166. CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
  167. CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
  168. /*!< Set up dividers */
  169. CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
  170. /*!< Set up clock selectors - Attach clocks to the peripheries */
  171. CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
  172. /*!< Set SystemCoreClock variable. */
  173. SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
  174. }