board.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-10-23 yuzrain the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "drv_uart.h"
  14. #include "drv_gpio.h"
  15. #include "md_gpio.h"
  16. /**
  17. * @addtogroup es32f0
  18. */
  19. /*@{*/
  20. /*******************************************************************************
  21. * Function Name : NVIC_Configuration
  22. * Description : Configures Vector Table base location.
  23. * Input : None
  24. * Output : None
  25. * Return : None
  26. *******************************************************************************/
  27. void NVIC_Configuration(void)
  28. {
  29. }
  30. /*******************************************************************************
  31. * Function Name : SystemClock_Configuration
  32. * Description : Configures the System Clock.
  33. * Input : None
  34. * Output : None
  35. * Return : None
  36. *******************************************************************************/
  37. void SystemClock_Config(void)
  38. {
  39. /*-------------------------Clock Config-------------------------/
  40. * Config system clock to 48MHz of which the clock source
  41. * is PLL0.
  42. */
  43. //
  44. // Open PLL0/HRC then wait it ready.
  45. //
  46. SET_BIT(RCU->CON, RCU_CON_PLL0ON_MSK);
  47. SET_BIT(RCU->CON, RCU_CON_HRCON_MSK);
  48. /* Wait HRC clock steady. */
  49. while (!READ_BIT(RCU->CON, RCU_CON_HRCRDY_MSK));
  50. //
  51. // Change system clock source,PLL0,48MHz.
  52. //
  53. /* Chose PLL0 as system clock. */
  54. MODIFY_REG(RCU->CFG, RCU_CFG_SW_MSK, (0x4 << RCU_CFG_SW_POSS));
  55. /* Config mul of PLL0. */
  56. MODIFY_REG(RCU->CFG, RCU_CFG_PLLMUL_MSK, (11 << RCU_CFG_PLLMUL_POSS));
  57. //
  58. // Start to change system clock and wait it ready.
  59. //
  60. /* Config flash read wait time. */
  61. MODIFY_REG(FC->CON, FC_CON_WAIT_MSK, (0X2 << FC_CON_WAIT_POSS));
  62. /* Start to change. */
  63. SET_BIT(RCU->CFG, RCU_CFG_CKCFG_MSK);
  64. /* Wait system clock ready. */
  65. while (!READ_BIT(RCU->CON, RCU_CON_SWRDY_MSK));
  66. //
  67. // Remember the system clock.
  68. //
  69. SystemCoreClock = 48000000;
  70. }
  71. /*******************************************************************************
  72. * Function Name : SysTick_Configuration
  73. * Description : Configures the SysTick for OS tick.
  74. * Input : None
  75. * Output : None
  76. * Return : None
  77. *******************************************************************************/
  78. void SysTick_Configuration(void)
  79. {
  80. /* ticks = sysclk / RT_TICK_PER_SECOND */
  81. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  82. }
  83. /**
  84. * This is the timer interrupt service routine.
  85. *
  86. */
  87. void SysTick_Handler(void)
  88. {
  89. /* enter interrupt */
  90. rt_interrupt_enter();
  91. rt_tick_increase();
  92. /* leave interrupt */
  93. rt_interrupt_leave();
  94. }
  95. /*@}*/
  96. /**
  97. * This function will initial ES32F0 board.
  98. */
  99. void rt_hw_board_init(void)
  100. {
  101. /* NVIC Configuration */
  102. NVIC_Configuration();
  103. /*System Clock Configuration */
  104. SystemClock_Config();
  105. /* Configure the SysTick */
  106. SysTick_Configuration();
  107. #ifdef RT_USING_HEAP
  108. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  109. #endif
  110. #ifdef RT_USING_COMPONENTS_INIT
  111. rt_components_board_init();
  112. #endif
  113. #ifdef RT_USING_CONSOLE
  114. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  115. #endif
  116. }