board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. *
  5. * The license and distribution terms for this file may be
  6. * found in the file LICENSE in this distribution or at
  7. * http://www.rt-thread.org/license/LICENSE
  8. *
  9. * Change Logs:
  10. * Date Author Notes
  11. * 2017-12-12 Bluebear233 first implementation
  12. */
  13. #include <rtconfig.h>
  14. #include <rtthread.h>
  15. #include <board.h>
  16. #include <usart.h>
  17. #include <NUC472_442.h>
  18. #ifdef __CC_ARM
  19. extern int Image$$RW_IRAM1$$ZI$$Limit;
  20. #elif __ICCARM__
  21. #pragma section="HEAP"
  22. #else
  23. extern int __bss_end;
  24. #endif
  25. /**
  26. * This function will initial Clock tree.
  27. */
  28. void clock_init(void)
  29. {
  30. /*---------------------------------------------------------------------------------------------------------*/
  31. /* Init System Clock */
  32. /*---------------------------------------------------------------------------------------------------------*/
  33. /* Unlock protected registers */
  34. SYS_UnlockReg();
  35. /* Enable External XTAL (4~24 MHz) */
  36. CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
  37. /* Waiting for 12MHz clock ready */
  38. CLK_WaitClockReady( CLK_STATUS_HXTSTB_Msk);
  39. /* Switch HCLK clock source to HXT */
  40. CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HXT,CLK_CLKDIV0_HCLK(1));
  41. /* Set PLL to power down mode and PLL_STB bit in CLKSTATUS register will be cleared by hardware.*/
  42. CLK->PLLCTL |= CLK_PLLCTL_PD_Msk;
  43. /* Set PLL frequency */
  44. CLK->PLLCTL = CLK_PLLCTL_84MHz_HXT;
  45. /* Waiting for clock ready */
  46. CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk);
  47. /* Switch HCLK clock source to PLL */
  48. CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_PLL,CLK_CLKDIV0_HCLK(1));
  49. /* Update System Core Clock */
  50. /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
  51. SystemCoreClockUpdate();
  52. /* Lock protected registers */
  53. SYS_LockReg();
  54. }
  55. /**
  56. * This function will initial NUC472 board.
  57. */
  58. void rt_hw_board_init(void)
  59. {
  60. clock_init();
  61. #ifdef RT_USING_HEAP
  62. #ifdef __CC_ARM
  63. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)SRAM_END);
  64. #elif __ICCARM__
  65. rt_system_heap_init(__segment_end("HEAP"), (void*)SRAM_END);
  66. #else
  67. /* init memory system */
  68. rt_system_heap_init((void*)&__bss_end, (void*)SRAM_END);
  69. #endif
  70. #endif /* RT_USING_HEAP */
  71. rt_hw_usart_init();
  72. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  73. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  74. }
  75. /**
  76. * This is the timer interrupt service routine.
  77. *
  78. */
  79. void SysTick_Handler(void)
  80. {
  81. /* enter interrupt */
  82. rt_interrupt_enter();
  83. rt_tick_increase();
  84. /* leave interrupt */
  85. rt_interrupt_leave();
  86. }