board.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * 2009-01-05 Bernard first implementation
  9. * 2014-07-18 ArdaFu Port to TM4C129X
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include "board.h"
  14. #include "driverlib/interrupt.h"
  15. #include "driverlib/sysctl.h"
  16. #include "driverlib/systick.h"
  17. #include "driverlib/fpu.h"
  18. #include "driverlib/rom_map.h"
  19. #define SYS_CLOCK_DEFAULT 120000000
  20. uint32_t SystemCoreClock;
  21. #define FAULT_NMI 2 // NMI fault
  22. #define FAULT_HARD 3 // Hard fault
  23. #define FAULT_MPU 4 // MPU fault
  24. #define FAULT_BUS 5 // Bus fault
  25. #define FAULT_USAGE 6 // Usage fault
  26. #define FAULT_SVCALL 11 // SVCall
  27. #define FAULT_DEBUG 12 // Debug monitor
  28. #define FAULT_PENDSV 14 // PendSV
  29. #define FAULT_SYSTICK 15 // System Tick
  30. /**
  31. * This is the timer interrupt service routine.
  32. *
  33. */
  34. void SysTick_Handler(void)
  35. {
  36. /* enter interrupt */
  37. rt_interrupt_enter();
  38. rt_tick_increase();
  39. /* leave interrupt */
  40. rt_interrupt_leave();
  41. }
  42. extern void PendSV_Handler(void);
  43. extern void HardFault_Handler(void);
  44. /**
  45. * This function will initial TM4C129X board.
  46. */
  47. void rt_hw_board_init()
  48. {
  49. //init low level drivers. e.g. cpu uart etc.
  50. rt_components_board_init();
  51. //init HEAP.
  52. #ifdef RT_USING_HEAP
  53. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  54. #endif
  55. //redirect RTT stdio to CONSOLE device
  56. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  57. }
  58. int rt_hw_cpu_init(void)
  59. {
  60. MAP_IntMasterDisable();
  61. IntRegister(FAULT_HARD, HardFault_Handler);
  62. IntRegister(FAULT_PENDSV, PendSV_Handler);
  63. IntRegister(FAULT_SYSTICK, SysTick_Handler);
  64. // Enable lazy stacking for interrupt handlers. This allows floating-point
  65. // instructions to be used within interrupt handlers, but at the expense of
  66. // extra stack usage.
  67. MAP_FPULazyStackingEnable();
  68. // Set the clocking to run directly from the external crystal/oscillator.
  69. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
  70. // crystal on your board.
  71. SystemCoreClock = MAP_SysCtlClockFreqSet(
  72. (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
  73. SYS_CLOCK_DEFAULT);
  74. MAP_SysTickDisable();
  75. MAP_SysTickPeriodSet(SystemCoreClock/ RT_TICK_PER_SECOND - 1);
  76. MAP_SysTickIntEnable();
  77. MAP_SysTickEnable();
  78. return 0;
  79. }
  80. // rt_hw_cpu_init should be run before any other INIT_BOARD_EXPORT
  81. // We use INIT_EXPORT here and set the sequence index to "0.xxxx"
  82. INIT_EXPORT(rt_hw_cpu_init, "0.post");