board.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. */
  10. #include <stdint.h>
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include <gd32f4xx.h>
  14. #include <board.h>
  15. #include <drv_usart.h>
  16. /**
  17. * @brief This function is executed in case of error occurrence.
  18. * @param None
  19. * @retval None
  20. */
  21. void Error_Handler(void)
  22. {
  23. /* USER CODE BEGIN Error_Handler */
  24. /* User can add his own implementation to report the HAL error return state */
  25. while (1)
  26. {
  27. }
  28. /* USER CODE END Error_Handler */
  29. }
  30. /** System Clock Configuration
  31. */
  32. void SystemClock_Config(void)
  33. {
  34. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  35. NVIC_SetPriority(SysTick_IRQn, 0);
  36. }
  37. /**
  38. * This is the timer interrupt service routine.
  39. *
  40. */
  41. void SysTick_Handler(void)
  42. {
  43. /* enter interrupt */
  44. rt_interrupt_enter();
  45. rt_tick_increase();
  46. /* leave interrupt */
  47. rt_interrupt_leave();
  48. }
  49. /**
  50. * This function will initial GD32 board.
  51. */
  52. void rt_hw_board_init()
  53. {
  54. /* NVIC Configuration */
  55. #define NVIC_VTOR_MASK 0x3FFFFF80
  56. #ifdef VECT_TAB_RAM
  57. /* Set the Vector Table base location at 0x10000000 */
  58. SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK);
  59. #else /* VECT_TAB_FLASH */
  60. /* Set the Vector Table base location at 0x08000000 */
  61. SCB->VTOR = (0x08000000 & NVIC_VTOR_MASK);
  62. #endif
  63. SystemClock_Config();
  64. #ifdef RT_USING_COMPONENTS_INIT
  65. rt_components_board_init();
  66. #endif
  67. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  68. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  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. }
  76. /*@}*/