board.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * 2010-02-04 Magicoe ported to LPC17xx
  10. * 2010-05-02 Aozima update CMSIS to 130
  11. * 2017-08-02 XiaoYang porting to LPC54608 bsp
  12. */
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include "board.h"
  16. #include "clock_config.h"
  17. #include "drv_uart.h"
  18. #include "drv_sdram.h"
  19. /**
  20. * This is the timer interrupt service routine.
  21. *
  22. */
  23. void SysTick_Handler(void)
  24. {
  25. /* enter interrupt */
  26. rt_interrupt_enter();
  27. rt_tick_increase();
  28. /* leave interrupt */
  29. rt_interrupt_leave();
  30. }
  31. /**
  32. * This function will initial LPC54xx board.
  33. */
  34. void rt_hw_board_init()
  35. {
  36. /* Hardware Initialization */
  37. CLOCK_EnableClock(kCLOCK_InputMux);
  38. CLOCK_EnableClock(kCLOCK_Iocon);
  39. /* NVIC Configuration */
  40. #define NVIC_VTOR_MASK 0x3FFFFF80
  41. #ifdef VECT_TAB_RAM
  42. /* Set the Vector Table base location at 0x10000000 */
  43. SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK);
  44. #else /* VECT_TAB_FLASH */
  45. /* Set the Vector Table base location at 0x00000000 */
  46. SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK);
  47. #endif
  48. BOARD_BootClockFROHF48M();
  49. /* init systick 1 systick = 1/(100M / 100) 100 systicks = 1s*/
  50. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  51. /* set pend exception priority */
  52. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  53. /* Heap initialization */
  54. #ifdef RT_USING_HEAP
  55. #ifdef BSP_DRV_SDRAM
  56. rt_kprintf(" heap: [0x%08x - 0x%08x]\n", LPC_EXT_SDRAM_BEGIN, LPC_EXT_SDRAM_END);
  57. rt_system_heap_init((void *)LPC_EXT_SDRAM_BEGIN, (void *)LPC_EXT_SDRAM_END);
  58. sram_init();
  59. #else
  60. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  61. #endif
  62. #endif
  63. /*init uart device*/
  64. rt_hw_uart_init();
  65. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  66. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  67. #endif
  68. #ifdef BSP_DRV_SDRAM
  69. lpc_sdram_hw_init();
  70. #endif
  71. #ifdef RT_USING_COMPONENTS_INIT
  72. /* initialization board with RT-Thread Components */
  73. rt_components_board_init();
  74. #endif
  75. }
  76. #ifdef PKG_USING_GUIENGINE
  77. #include <rtgui/driver.h>
  78. #include "drv_lcd.h"
  79. /* initialize for gui driver */
  80. int rtgui_lcd_init(void)
  81. {
  82. rt_device_t device;
  83. rt_hw_lcd_init();
  84. device = rt_device_find("lcd");
  85. /* set graphic device */
  86. rtgui_graphic_set_device(device);
  87. return 0;
  88. }
  89. INIT_DEVICE_EXPORT(rtgui_lcd_init);
  90. #endif
  91. void MemManage_Handler(void)
  92. {
  93. extern void HardFault_Handler(void);
  94. rt_kprintf("Memory Fault!\n");
  95. HardFault_Handler();
  96. }