board.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-10-23 drifting1024 first implementation
  9. */
  10. #include <stdint.h>
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include <board.h>
  14. #ifdef RT_USING_SERIAL_V2
  15. #include "drv_usart_v2.h"
  16. #else
  17. #include "drv_usart.h"
  18. #endif
  19. /**
  20. * @brief This function is executed in case of error occurrence.
  21. * @param None
  22. * @retval None
  23. */
  24. void Error_Handler(void)
  25. {
  26. /* USER CODE BEGIN Error_Handler */
  27. /* User can add his own implementation to report the HAL error return state */
  28. while (1)
  29. {
  30. }
  31. /* USER CODE END Error_Handler */
  32. }
  33. /** System Clock Configuration
  34. */
  35. void SystemClock_Config(void)
  36. {
  37. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  38. NVIC_SetPriority(SysTick_IRQn, 0);
  39. }
  40. /**
  41. * This is the timer interrupt service routine.
  42. *
  43. */
  44. void SysTick_Handler(void)
  45. {
  46. /* enter interrupt */
  47. rt_interrupt_enter();
  48. rt_tick_increase();
  49. /* leave interrupt */
  50. rt_interrupt_leave();
  51. }
  52. /**
  53. * This function will initial GD32 board.
  54. */
  55. void rt_hw_board_init()
  56. {
  57. /* NVIC Configuration */
  58. #define NVIC_VTOR_MASK 0x3FFFFF80
  59. #ifdef VECT_TAB_RAM
  60. /* Set the Vector Table base location at 0x10000000 */
  61. SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK);
  62. #else /* VECT_TAB_FLASH */
  63. /* Set the Vector Table base location at 0x08000000 */
  64. SCB->VTOR = (0x08000000 & NVIC_VTOR_MASK);
  65. #endif
  66. SystemClock_Config();
  67. #ifdef RT_USING_SERIAL
  68. rt_hw_usart_init();
  69. #endif
  70. #ifdef BSP_USING_SDRAM
  71. rt_system_heap_init((void *)EXT_SDRAM_BEGIN, (void *)EXT_SDRAM_END);
  72. #else
  73. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  74. #endif
  75. #ifdef RT_USING_CONSOLE
  76. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  77. #endif
  78. #ifdef RT_USING_COMPONENTS_INIT
  79. rt_components_board_init();
  80. #endif
  81. }
  82. /*@}*/