board.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2009-01-05 Bernard first implementation
  10. * 2010-02-04 Magicoe ported to LPC17xx
  11. * 2010-05-02 Aozima update CMSIS to 130
  12. * 2017-08-02 XiaoYang porting to LPC54608 bsp
  13. * 2019-08-05 Magicoe porting to LPC55S69-EVK bsp
  14. * 2020-01-01 Karl Add PKG_USING_TFM support
  15. */
  16. #include <rthw.h>
  17. #include <rtthread.h>
  18. #include "board.h"
  19. #include "clock_config.h"
  20. #include "drv_uart.h"
  21. /**
  22. * This is the timer interrupt service routine.
  23. *
  24. */
  25. void SysTick_Handler(void)
  26. {
  27. /* enter interrupt */
  28. rt_interrupt_enter();
  29. rt_tick_increase();
  30. /* leave interrupt */
  31. rt_interrupt_leave();
  32. }
  33. /**
  34. * This function will initial LPC55Sxx board.
  35. */
  36. void rt_hw_board_init()
  37. {
  38. /* Hardware Initialization */
  39. BOARD_InitPins();
  40. CLOCK_EnableClock(kCLOCK_InputMux);
  41. CLOCK_EnableClock(kCLOCK_Gpio0);
  42. CLOCK_EnableClock(kCLOCK_Gpio1);
  43. GPIO_PortInit(GPIO, 0);
  44. GPIO_PortInit(GPIO, 1);
  45. /* NVIC Configuration */
  46. #define NVIC_VTOR_MASK 0x3FFFFF80
  47. #ifdef VECT_TAB_RAM
  48. /* Set the Vector Table base location at 0x10000000 */
  49. SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK);
  50. #else /* VECT_TAB_FLASH */
  51. #ifdef PKG_USING_TFM
  52. /* Set the Vector Table base location at 0x00020000 when RTT with TF-M*/
  53. SCB->VTOR = (0x00020000 & NVIC_VTOR_MASK);
  54. #else
  55. /* Set the Vector Table base location at 0x00000000 */
  56. SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK);
  57. #endif
  58. #endif
  59. #ifndef PKG_USING_TFM
  60. /* This init has finished in secure side of TF-M */
  61. BOARD_BootClockPLL150M();
  62. #endif
  63. //BOARD_BootClockFROHF96M();
  64. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  65. /* set pend exception priority */
  66. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  67. /*init uart device*/
  68. rt_hw_uart_init();
  69. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  70. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  71. #endif
  72. #ifdef RT_USING_COMPONENTS_INIT
  73. /* initialization board with RT-Thread Components */
  74. rt_components_board_init();
  75. #endif
  76. #ifdef RT_USING_HEAP
  77. rt_kprintf("sram heap, begin: 0x%p, end: 0x%p\n", HEAP_BEGIN, HEAP_END);
  78. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  79. #endif
  80. }
  81. /**
  82. * This function will called when memory fault.
  83. */
  84. void MemManage_Handler(void)
  85. {
  86. extern void HardFault_Handler(void);
  87. rt_kprintf("Memory Fault!\n");
  88. HardFault_Handler();
  89. }
  90. void rt_hw_us_delay(rt_uint32_t us)
  91. {
  92. rt_uint32_t ticks;
  93. rt_uint32_t told, tnow, tcnt = 0;
  94. rt_uint32_t reload = SysTick->LOAD;
  95. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  96. told = SysTick->VAL;
  97. while (1)
  98. {
  99. tnow = SysTick->VAL;
  100. if (tnow != told)
  101. {
  102. if (tnow < told)
  103. {
  104. tcnt += told - tnow;
  105. }
  106. else
  107. {
  108. tcnt += reload - tnow + told;
  109. }
  110. told = tnow;
  111. if (tcnt >= ticks)
  112. {
  113. break;
  114. }
  115. }
  116. }
  117. }