board.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2006-2023, 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. DMA_Init(DMA0);
  46. DMA_Init(DMA1);
  47. /* NVIC Configuration */
  48. #define NVIC_VTOR_MASK 0x3FFFFF80
  49. #ifdef VECT_TAB_RAM
  50. /* Set the Vector Table base location at 0x10000000 */
  51. SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK);
  52. #else /* VECT_TAB_FLASH */
  53. #ifdef PKG_USING_TFM
  54. /* Set the Vector Table base location at 0x00020000 when RTT with TF-M*/
  55. SCB->VTOR = (0x00020000 & NVIC_VTOR_MASK);
  56. #else
  57. /* Set the Vector Table base location at 0x00000000 */
  58. SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK);
  59. #endif
  60. #endif
  61. #ifndef PKG_USING_TFM
  62. /* This init has finished in secure side of TF-M */
  63. BOARD_BootClockPLL150M();
  64. #endif
  65. //BOARD_BootClockFROHF96M();
  66. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  67. /* set pend exception priority */
  68. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  69. /*init uart device*/
  70. rt_hw_uart_init();
  71. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  72. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  73. #endif
  74. #ifdef RT_USING_COMPONENTS_INIT
  75. /* initialization board with RT-Thread Components */
  76. rt_components_board_init();
  77. #endif
  78. #ifdef RT_USING_HEAP
  79. rt_kprintf("sram heap, begin: 0x%p, end: 0x%p\n", HEAP_BEGIN, HEAP_END);
  80. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  81. #endif
  82. }
  83. /**
  84. * This function will called when memory fault.
  85. */
  86. void MemManage_Handler(void)
  87. {
  88. extern void HardFault_Handler(void);
  89. rt_kprintf("Memory Fault!\n");
  90. HardFault_Handler();
  91. }
  92. void rt_hw_us_delay(rt_uint32_t us)
  93. {
  94. rt_uint32_t ticks;
  95. rt_uint32_t told, tnow, tcnt = 0;
  96. rt_uint32_t reload = SysTick->LOAD;
  97. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  98. told = SysTick->VAL;
  99. while (1)
  100. {
  101. tnow = SysTick->VAL;
  102. if (tnow != told)
  103. {
  104. if (tnow < told)
  105. {
  106. tcnt += told - tnow;
  107. }
  108. else
  109. {
  110. tcnt += reload - tnow + told;
  111. }
  112. told = tnow;
  113. if (tcnt >= ticks)
  114. {
  115. break;
  116. }
  117. }
  118. }
  119. }