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  * 2021-12-18     BruceOu      first implementation
9  * 2024-03-19     Evlers       add serial supports
10   */
11 #include <stdint.h>
12 #include <rthw.h>
13 #include <rtthread.h>
14 #include <board.h>
15 
16 #ifdef RT_USING_SERIAL_V2
17 #include "drv_usart_v2.h"
18 #else
19 #include "drv_usart.h"
20 #endif
21 
22 
23 /**
24   * @brief  This function is executed in case of error occurrence.
25   * @param  None
26   * @retval None
27   */
Error_Handler(void)28 void Error_Handler(void)
29 {
30     /* USER CODE BEGIN Error_Handler */
31     /* User can add his own implementation to report the HAL error return state */
32     while (1)
33     {
34     }
35     /* USER CODE END Error_Handler */
36 }
37 
38 /** System Clock Configuration
39 */
SystemClock_Config(void)40 void SystemClock_Config(void)
41 {
42     SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
43     NVIC_SetPriority(SysTick_IRQn, 0);
44 }
45 
46 /**
47  * This is the timer interrupt service routine.
48  *
49  */
SysTick_Handler(void)50 void SysTick_Handler(void)
51 {
52     /* enter interrupt */
53     rt_interrupt_enter();
54 
55     rt_tick_increase();
56 
57     /* leave interrupt */
58     rt_interrupt_leave();
59 }
60 
61 /**
62  * This function will initial GD32 board.
63  */
rt_hw_board_init()64 void rt_hw_board_init()
65 {
66     /* NVIC Configuration */
67 #define NVIC_VTOR_MASK              0x3FFFFF80
68 #ifdef  VECT_TAB_RAM
69     /* Set the Vector Table base location at 0x10000000 */
70     SCB->VTOR  = (0x10000000 & NVIC_VTOR_MASK);
71 #else  /* VECT_TAB_FLASH  */
72     /* Set the Vector Table base location at 0x08000000 */
73     SCB->VTOR  = (0x08000000 & NVIC_VTOR_MASK);
74 #endif
75 
76     SystemClock_Config();
77 
78 #ifdef RT_USING_SERIAL
79     rt_hw_usart_init();
80 #endif
81 
82 #ifdef BSP_USING_SDRAM
83     rt_system_heap_init((void *)EXT_SDRAM_BEGIN, (void *)EXT_SDRAM_END);
84 #else
85     rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
86 #endif
87 
88 #ifdef RT_USING_CONSOLE
89     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
90 #endif
91 
92 #ifdef RT_USING_COMPONENTS_INIT
93     rt_components_board_init();
94 #endif
95 }
96 
97 /*@}*/
98