clock_config.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. package_id: LPC54114J256BD64
  52. mcu_data: ksdk2_0
  53. processor_version: 1.1.0
  54. board: LPCXpresso54114
  55. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  56. #include "fsl_power.h"
  57. #include "fsl_clock.h"
  58. #include "clock_config.h"
  59. /*******************************************************************************
  60. * Definitions
  61. ******************************************************************************/
  62. /*******************************************************************************
  63. * Variables
  64. ******************************************************************************/
  65. /* System clock frequency. */
  66. extern uint32_t SystemCoreClock;
  67. /*******************************************************************************
  68. ********************* Configuration BOARD_BootClockFRO12M ***********************
  69. ******************************************************************************/
  70. /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
  71. !!Configuration
  72. name: BOARD_BootClockFRO12M
  73. outputs:
  74. - {id: System_clock.outFreq, value: 12 MHz}
  75. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  76. /*******************************************************************************
  77. * Variables for BOARD_BootClockFRO12M configuration
  78. ******************************************************************************/
  79. /*******************************************************************************
  80. * Code for BOARD_BootClockFRO12M configuration
  81. ******************************************************************************/
  82. void BOARD_BootClockFRO12M(void)
  83. {
  84. /*!< Set up the clock sources */
  85. /*!< Set up FRO */
  86. POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
  87. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
  88. being below the voltage for current speed */
  89. CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
  90. POWER_SetVoltageForFreq(12000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
  91. CLOCK_SetFLASHAccessCyclesForFreq(12000000U); /*!< Set FLASH wait states for core */
  92. /*!< Set up dividers */
  93. CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
  94. /*!< Set up clock selectors - Attach clocks to the peripheries */
  95. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO12M */
  96. /*!< Set SystemCoreClock variable. */
  97. SystemCoreClock = BOARD_BOOTCLOCKFRO12M_CORE_CLOCK;
  98. }
  99. /*******************************************************************************
  100. ********************** Configuration BOARD_BootClockFROHF48M ***********************
  101. ******************************************************************************/
  102. /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
  103. !!Configuration
  104. name: BOARD_BootClockFROHF48M
  105. outputs:
  106. - {id: System_clock.outFreq, value: 48 MHz}
  107. settings:
  108. - {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
  109. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  110. /*******************************************************************************
  111. * Variables for BOARD_BootClockFROHF48M configuration
  112. ******************************************************************************/
  113. /*******************************************************************************
  114. * Code for BOARD_BootClockFROHF48M configuration
  115. ******************************************************************************/
  116. void BOARD_BootClockFROHF48M(void)
  117. {
  118. /*!< Set up the clock sources */
  119. /*!< Set up FRO */
  120. POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
  121. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
  122. being below the voltage for current speed */
  123. POWER_SetVoltageForFreq(48000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
  124. CLOCK_SetFLASHAccessCyclesForFreq(48000000U); /*!< Set FLASH wait states for core */
  125. CLOCK_SetupFROClocking(48000000U); /*!< Set up high frequency FRO output to selected frequency */
  126. /*!< Set up dividers */
  127. CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
  128. /*!< Set up clock selectors - Attach clocks to the peripheries */
  129. CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
  130. /*!< Set SystemCoreClock variable. */
  131. SystemCoreClock = BOARD_BOOTCLOCKFROHF48M_CORE_CLOCK;
  132. }
  133. /*******************************************************************************
  134. ********************* Configuration BOARD_BootClockFROHF96M **********************
  135. ******************************************************************************/
  136. /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
  137. !!Configuration
  138. name: BOARD_BootClockFROHF96M
  139. outputs:
  140. - {id: System_clock.outFreq, value: 96 MHz}
  141. settings:
  142. - {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
  143. sources:
  144. - {id: SYSCON.fro_hf.outFreq, value: 96 MHz}
  145. * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
  146. /*******************************************************************************
  147. * Variables for BOARD_BootClockFROHF96M configuration
  148. ******************************************************************************/
  149. /*******************************************************************************
  150. * Code for BOARD_BootClockFROHF96M configuration
  151. ******************************************************************************/
  152. void BOARD_BootClockFROHF96M(void)
  153. {
  154. /*!< Set up the clock sources */
  155. /*!< Set up FRO */
  156. POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
  157. CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
  158. being below the voltage for current speed */
  159. POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
  160. CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
  161. CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
  162. /*!< Set up dividers */
  163. CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
  164. /*!< Set up clock selectors - Attach clocks to the peripheries */
  165. CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
  166. /*!< Set SystemCoreClock variable. */
  167. SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
  168. }