sysinit_8xx.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * @brief LPC8xx Chip specific SystemInit
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2013
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #define _CHIP_COMMON_
  32. #include "board_lpc.h"
  33. /*****************************************************************************
  34. * Private types/enumerations/variables
  35. ****************************************************************************/
  36. /*****************************************************************************
  37. * Public types/enumerations/variables
  38. ****************************************************************************/
  39. /*****************************************************************************
  40. * Private functions
  41. ****************************************************************************/
  42. #define CONFIG_MAIN_FREQ 60000000
  43. #define CONFIG_SYS_FREQ MAX_CLOCK_FREQ
  44. /*****************************************************************************
  45. * Public functions
  46. ****************************************************************************/
  47. /* Setup system clocking */
  48. void Chip_SetupXtalClocking(void)
  49. {
  50. /* EXT oscillator < 15MHz */
  51. Chip_Clock_SetPLLBypass(false, false);
  52. /* Turn on the SYSOSC by clearing the power down bit */
  53. Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSOSC_PD);
  54. /* Select the PLL input to the external oscillator */
  55. Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_SYSOSC);
  56. /* Setup FLASH access to 2 clocks (up to 30MHz) */
  57. Chip_FMC_SetFLASHAccess(FLASHTIM_30MHZ_CPU);
  58. /* Power down PLL to change the PLL divider ratio */
  59. Chip_SYSCTL_PowerDown(SYSCTL_SLPWAKE_SYSPLL_PD);
  60. /* Configure the PLL M and P dividers */
  61. /* Setup PLL for main oscillator rate ((FCLKIN = 12MHz) * 5)/2 = 30MHz */
  62. Chip_Clock_SetupSystemPLL(4, 1);
  63. /* Turn on the PLL by clearing the power down bit */
  64. Chip_SYSCTL_PowerUp(SYSCTL_SLPWAKE_SYSPLL_PD);
  65. /* Enable the clock to the Switch Matrix */
  66. Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
  67. /* Wait for PLL to lock */
  68. while (!Chip_Clock_IsSystemPLLLocked()) {}
  69. Chip_Clock_SetSysClockDiv(2);
  70. /* Set main clock source to the system PLL. This will drive 24MHz
  71. for the main clock and 24MHz for the system clock */
  72. Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT);
  73. }
  74. /* Set up and initialize hardware prior to call to main */
  75. void Chip_SetupIrcClocking(void)
  76. {
  77. Chip_IRC_SetFreq(CONFIG_MAIN_FREQ, CONFIG_SYS_FREQ);
  78. }
  79. /* Set up and initialize hardware prior to call to main */
  80. /* 在main()函数之前调用此函数做基本的初始化工作 */
  81. void SystemInit(void)
  82. {
  83. Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
  84. #ifdef USE_IRC_AS_ROOT_CLOCK
  85. /* Use 12MHz IRC as clock source */
  86. Chip_SetupIrcClocking();
  87. #else
  88. /* Use Xtal or external clock_in as clock source*/
  89. Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
  90. Chip_SWM_EnableFixedPin(SWM_FIXED_XTALIN);
  91. Chip_SWM_EnableFixedPin(SWM_FIXED_XTALOUT);
  92. // Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
  93. Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO8, PIN_MODE_INACTIVE);
  94. Chip_IOCON_PinSetMode(LPC_IOCON, IOCON_PIO9, PIN_MODE_INACTIVE);
  95. Chip_SetupXtalClocking();
  96. #endif
  97. }