board.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-07-24 Tanek the first version
  9. * 2018-11-12 Ernest Chen modify copyright
  10. * 2020-06-27 AHTYDHD modify to adapt in TM4C123
  11. */
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include "inc/hw_sysctl.h"
  15. #include "inc/hw_memmap.h"
  16. #include "driverlib/fpu.h"
  17. #include "driverlib/sysctl.h"
  18. #include "driverlib/systick.h"
  19. #include "board.h"
  20. uint32_t SystemCoreClock;
  21. /* this function set the system clock */
  22. void SystemCoreClockUpdate(void)
  23. {
  24. FPULazyStackingEnable();
  25. /* Set the clocking to run directly from the crystal. 50MHz*/
  26. SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
  27. SYSCTL_OSC_MAIN);
  28. SystemCoreClock = SysCtlClockGet();
  29. }
  30. /* this funtion set the Systick and enable systick int */
  31. void SysTickConfig()
  32. {
  33. SysTickDisable();
  34. SysTickPeriodSet(SystemCoreClock / RT_TICK_PER_SECOND);
  35. SysTickIntEnable();
  36. SysTickEnable();
  37. }
  38. /**
  39. * This function will initial your board.
  40. */
  41. void rt_hw_board_init()
  42. {
  43. /* System Clock Update */
  44. SystemCoreClockUpdate();
  45. /* System Tick Configuration */
  46. SysTickConfig();
  47. #ifdef RT_USING_SERIAL
  48. rt_hw_usart_init();
  49. #endif
  50. #ifdef RT_USING_PIN
  51. rt_hw_pin_init();
  52. #endif
  53. #ifdef RT_USING_PWM
  54. rt_hw_pwm_init();
  55. #endif
  56. #ifdef RT_USING_I2C
  57. rt_hw_i2c_init();
  58. #endif
  59. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  60. #ifdef RT_USING_COMPONENTS_INIT
  61. rt_components_board_init();
  62. #endif
  63. /* set the console device */
  64. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  65. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  66. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  67. #endif
  68. }
  69. void SysTick_Handler(void)
  70. {
  71. /* enter interrupt */
  72. rt_interrupt_enter();
  73. rt_tick_increase();
  74. /* leave interrupt */
  75. rt_interrupt_leave();
  76. }