1 /*
2  * Copyright (c) 2006-2025, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  */
7 
8 #include <rthw.h>
9 #include <rtthread.h>
10 #include "board.h"
11 #include "gd32e23x.h"
12 
13 #ifdef RT_USING_SERIAL
14 #if defined(RT_USING_SERIAL_V2)
15 #include "drv_usart_v2.h"
16 #else
17 #include "drv_usart.h"
18 #endif
19 #endif
20 
21 /**
22  * @brief  This function is executed in case of error occurrence.
23  * @param  None
24  * @retval None
25  */
Error_Handler(void)26 void Error_Handler(void)
27 {
28     rt_kprintf("\nError_Handler triggered! System halted.\n");
29     while (1)
30     {
31     }
32 }
33 
34 /**
35  * @brief  This is the timer interrupt service routine.
36  *
37  */
SysTick_Handler(void)38 void SysTick_Handler(void)
39 {
40     /* enter interrupt */
41     rt_interrupt_enter();
42 
43     rt_tick_increase();
44 
45     /* leave interrupt */
46     rt_interrupt_leave();
47 }
48 
49 /**
50  * @brief This function will initial GD32 board.
51  * @note  This function is called from the RT-Thread startup code.
52  */
rt_hw_board_init(void)53 void rt_hw_board_init(void)
54 {
55 #ifdef VECT_TAB_RAM
56     SCB->VTOR = 0x20000000;
57 #else  /* VECT_TAB_FLASH is the default */
58     SCB->VTOR = 0x08000000;
59 #endif
60 
61     SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
62     NVIC_SetPriority(SysTick_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
63 
64 #ifdef RT_USING_HEAP
65     rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
66 #endif
67 
68 #ifdef RT_USING_SERIAL
69     rt_hw_usart_init();
70 #endif
71 
72 #ifdef RT_USING_CONSOLE
73     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
74 #endif
75 
76 #ifdef RT_USING_COMPONENTS_INIT
77     rt_components_board_init();
78 #endif
79 }
80 
81