Skip to content

Commit c0c6a10

Browse files
committed
[fix] 适配uart设备并格式化部分文件
1 parent 2263b62 commit c0c6a10

File tree

8 files changed

+108
-76
lines changed

8 files changed

+108
-76
lines changed

bsp/gd32/risc-v/gd32vw553h-eval/.config

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
139139
# CONFIG_RT_USING_TINY_FFS is not set
140140
# end of kservice options
141141

142-
CONFIG_RT_USING_DEBUG=y
143-
CONFIG_RT_DEBUGING_ASSERT=y
144-
CONFIG_RT_DEBUGING_COLOR=y
145-
CONFIG_RT_DEBUGING_CONTEXT=y
146-
# CONFIG_RT_DEBUGING_AUTO_INIT is not set
142+
# CONFIG_RT_USING_DEBUG is not set
147143
# CONFIG_RT_USING_CI_ACTION is not set
148144

149145
#
@@ -181,7 +177,7 @@ CONFIG_RT_USING_DEVICE=y
181177
# CONFIG_RT_USING_THREADSAFE_PRINTF is not set
182178
CONFIG_RT_USING_CONSOLE=y
183179
CONFIG_RT_CONSOLEBUF_SIZE=128
184-
CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
180+
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
185181
CONFIG_RT_VER_NUM=0x50201
186182
# CONFIG_RT_USING_STDC_ATOMIC is not set
187183
CONFIG_RT_BACKTRACE_LEVEL_MAX_NR=32
@@ -197,7 +193,22 @@ CONFIG_RT_USING_USER_MAIN=y
197193
CONFIG_RT_MAIN_THREAD_STACK_SIZE=4096
198194
CONFIG_RT_MAIN_THREAD_PRIORITY=10
199195
# CONFIG_RT_USING_LEGACY is not set
200-
# CONFIG_RT_USING_MSH is not set
196+
CONFIG_RT_USING_MSH=y
197+
CONFIG_RT_USING_FINSH=y
198+
CONFIG_FINSH_USING_MSH=y
199+
CONFIG_FINSH_THREAD_NAME="tshell"
200+
CONFIG_FINSH_THREAD_PRIORITY=20
201+
CONFIG_FINSH_THREAD_STACK_SIZE=4096
202+
CONFIG_FINSH_USING_HISTORY=y
203+
CONFIG_FINSH_HISTORY_LINES=5
204+
CONFIG_FINSH_USING_SYMTAB=y
205+
CONFIG_FINSH_CMD_SIZE=80
206+
CONFIG_MSH_USING_BUILT_IN_COMMANDS=y
207+
CONFIG_FINSH_USING_DESCRIPTION=y
208+
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
209+
# CONFIG_FINSH_USING_AUTH is not set
210+
CONFIG_FINSH_ARG_MAX=10
211+
CONFIG_FINSH_USING_OPTION_COMPLETION=y
201212

202213
#
203214
# DFS: device virtual file system
@@ -215,7 +226,12 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10
215226
CONFIG_RT_USING_DEVICE_IPC=y
216227
CONFIG_RT_UNAMED_PIPE_NUMBER=64
217228
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
218-
# CONFIG_RT_USING_SERIAL is not set
229+
CONFIG_RT_USING_SERIAL=y
230+
CONFIG_RT_USING_SERIAL_V1=y
231+
# CONFIG_RT_USING_SERIAL_V2 is not set
232+
CONFIG_RT_SERIAL_USING_DMA=y
233+
CONFIG_RT_SERIAL_RB_BUFSZ=64
234+
# CONFIG_RT_USING_SERIAL_BYPASS is not set
219235
# CONFIG_RT_USING_CAN is not set
220236
# CONFIG_RT_USING_CPUTIME is not set
221237
# CONFIG_RT_USING_I2C is not set
@@ -1375,7 +1391,13 @@ CONFIG_SOC_SERIES_GD32VW=y
13751391
# On-chip Peripheral Drivers
13761392
#
13771393
CONFIG_BSP_USING_GPIO=y
1378-
# CONFIG_BSP_USING_UART is not set
1394+
CONFIG_BSP_USING_UART=y
1395+
CONFIG_BSP_USING_UART0=y
1396+
# CONFIG_BSP_UART0_RX_USING_DMA is not set
1397+
# CONFIG_BSP_USING_UART1 is not set
1398+
# CONFIG_BSP_USING_UART2 is not set
1399+
# CONFIG_BSP_USING_UART3 is not set
1400+
# CONFIG_BSP_USING_UART4 is not set
13791401
# CONFIG_BSP_USING_SPI is not set
13801402
# CONFIG_BSP_USING_I2C1 is not set
13811403
# CONFIG_BSP_USING_ADC is not set

bsp/gd32/risc-v/gd32vw553h-eval/Utilities/gd32vw553h_eval.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88
/*
99
Copyright (c) 2024, GigaDevice Semiconductor Inc.
1010
11-
Redistribution and use in source and binary forms, with or without modification,
11+
Redistribution and use in source and binary forms, with or without modification,
1212
are permitted provided that the following conditions are met:
1313
14-
1. Redistributions of source code must retain the above copyright notice, this
14+
1. Redistributions of source code must retain the above copyright notice, this
1515
list of conditions and the following disclaimer.
16-
2. Redistributions in binary form must reproduce the above copyright notice,
17-
this list of conditions and the following disclaimer in the documentation
16+
2. Redistributions in binary form must reproduce the above copyright notice,
17+
this list of conditions and the following disclaimer in the documentation
1818
and/or other materials provided with the distribution.
19-
3. Neither the name of the copyright holder nor the names of its contributors
20-
may be used to endorse or promote products derived from this software without
19+
3. Neither the name of the copyright holder nor the names of its contributors
20+
may be used to endorse or promote products derived from this software without
2121
specific prior written permission.
2222
23-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26-
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27-
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31-
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
3232
OF SUCH DAMAGE.
3333
*/
3434

@@ -43,7 +43,7 @@ static rcu_periph_enum COM_CLK[COMn] = {EVAL_COM0_CLK};
4343
static uint32_t COM_TX_PIN[COMn] = {EVAL_COM0_TX_PIN};
4444
static uint32_t COM_RX_PIN[COMn] = {EVAL_COM0_RX_PIN};
4545

46-
static rcu_periph_enum GPIO_CLK[LED_MAX] = {LED1_GPIO_CLK, LED2_GPIO_CLK,
46+
static rcu_periph_enum GPIO_CLK[LED_MAX] = {LED1_GPIO_CLK, LED2_GPIO_CLK,
4747
LED3_GPIO_CLK};
4848

4949
static uint32_t KEY_PORT[KEY_MAX] = {TAMPER_WAKEUP_KEY_GPIO_PORT};
@@ -67,7 +67,7 @@ void gd_eval_led_init (led_typedef_enum lednum)
6767
{
6868
/* enable the led clock */
6969
rcu_periph_clock_enable(GPIO_CLK[lednum]);
70-
/* configure led GPIO port */
70+
/* configure led GPIO port */
7171
gpio_mode_set(GPIO_PORT[lednum], GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,GPIO_PIN[lednum]);
7272
gpio_output_options_set(GPIO_PORT[lednum], GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ,GPIO_PIN[lednum]);
7373

bsp/gd32/risc-v/gd32vw553h-eval/Utilities/gd32vw553h_eval.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88
/*
99
Copyright (c) 2024, GigaDevice Semiconductor Inc.
1010
11-
Redistribution and use in source and binary forms, with or without modification,
11+
Redistribution and use in source and binary forms, with or without modification,
1212
are permitted provided that the following conditions are met:
1313
14-
1. Redistributions of source code must retain the above copyright notice, this
14+
1. Redistributions of source code must retain the above copyright notice, this
1515
list of conditions and the following disclaimer.
16-
2. Redistributions in binary form must reproduce the above copyright notice,
17-
this list of conditions and the following disclaimer in the documentation
16+
2. Redistributions in binary form must reproduce the above copyright notice,
17+
this list of conditions and the following disclaimer in the documentation
1818
and/or other materials provided with the distribution.
19-
3. Neither the name of the copyright holder nor the names of its contributors
20-
may be used to endorse or promote products derived from this software without
19+
3. Neither the name of the copyright holder nor the names of its contributors
20+
may be used to endorse or promote products derived from this software without
2121
specific prior written permission.
2222
23-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26-
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27-
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31-
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
3232
OF SUCH DAMAGE.
3333
*/
3434

@@ -40,23 +40,23 @@ OF SUCH DAMAGE.
4040
#endif
4141

4242
#include "gd32vw55x.h"
43-
43+
4444
/* exported types */
45-
typedef enum
45+
typedef enum
4646
{
4747
LED1 = 0U,
4848
LED2 = 1,
4949
LED3 = 2,
5050
LED_MAX
5151
}led_typedef_enum;
5252

53-
typedef enum
53+
typedef enum
5454
{
5555
KEY_TAMPER_WAKEUP = 0,
5656
KEY_MAX
5757
}key_typedef_enum;
5858

59-
typedef enum
59+
typedef enum
6060
{
6161
KEY_MODE_GPIO = 0,
6262
KEY_MODE_EXTI = 1
@@ -66,11 +66,11 @@ typedef enum
6666
#define LED1_PIN GPIO_PIN_4
6767
#define LED1_GPIO_PORT GPIOA
6868
#define LED1_GPIO_CLK RCU_GPIOA
69-
69+
7070
#define LED2_PIN GPIO_PIN_5
7171
#define LED2_GPIO_PORT GPIOA
7272
#define LED2_GPIO_CLK RCU_GPIOA
73-
73+
7474
#define LED3_PIN GPIO_PIN_6
7575
#define LED3_GPIO_PORT GPIOA
7676
#define LED3_GPIO_CLK RCU_GPIOA

bsp/gd32/risc-v/gd32vw553h-eval/applications/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2022-06-04 BruceOu first implementation
9+
* 2025-07-10 WangShun fix for GD32VW553H_EVAL
910
*/
1011

1112
#include <stdio.h>
1213
#include <rtthread.h>
1314
#include <rtdevice.h>
1415
#include <board.h>
1516

16-
/* defined the LED1 pin: PA4 */
17+
/* LED1 ~ LED3 pin: PA4 PA5 PA6 */
1718
#define LED1_PIN GET_PIN(A, 4)
1819

1920
int main(void)

bsp/gd32/risc-v/gd32vw553h-eval/board/board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*

bsp/gd32/risc-v/gd32vw553h-eval/board/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*

bsp/gd32/risc-v/gd32vw553h-eval/rtconfig.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@
8080
/* kservice options */
8181

8282
/* end of kservice options */
83-
#define RT_USING_DEBUG
84-
#define RT_DEBUGING_ASSERT
85-
#define RT_DEBUGING_COLOR
86-
#define RT_DEBUGING_CONTEXT
8783

8884
/* Inter-Thread communication */
8985

@@ -104,7 +100,7 @@
104100
#define RT_USING_DEVICE
105101
#define RT_USING_CONSOLE
106102
#define RT_CONSOLEBUF_SIZE 128
107-
#define RT_CONSOLE_DEVICE_NAME "uart1"
103+
#define RT_CONSOLE_DEVICE_NAME "uart0"
108104
#define RT_VER_NUM 0x50201
109105
#define RT_BACKTRACE_LEVEL_MAX_NR 32
110106
/* end of RT-Thread Kernel */
@@ -116,6 +112,20 @@
116112
#define RT_USING_USER_MAIN
117113
#define RT_MAIN_THREAD_STACK_SIZE 4096
118114
#define RT_MAIN_THREAD_PRIORITY 10
115+
#define RT_USING_MSH
116+
#define RT_USING_FINSH
117+
#define FINSH_USING_MSH
118+
#define FINSH_THREAD_NAME "tshell"
119+
#define FINSH_THREAD_PRIORITY 20
120+
#define FINSH_THREAD_STACK_SIZE 4096
121+
#define FINSH_USING_HISTORY
122+
#define FINSH_HISTORY_LINES 5
123+
#define FINSH_USING_SYMTAB
124+
#define FINSH_CMD_SIZE 80
125+
#define MSH_USING_BUILT_IN_COMMANDS
126+
#define FINSH_USING_DESCRIPTION
127+
#define FINSH_ARG_MAX 10
128+
#define FINSH_USING_OPTION_COMPLETION
119129

120130
/* DFS: device virtual file system */
121131

@@ -125,6 +135,10 @@
125135

126136
#define RT_USING_DEVICE_IPC
127137
#define RT_UNAMED_PIPE_NUMBER 64
138+
#define RT_USING_SERIAL
139+
#define RT_USING_SERIAL_V1
140+
#define RT_SERIAL_USING_DMA
141+
#define RT_SERIAL_RB_BUFSZ 64
128142
#define RT_USING_PIN
129143
/* end of Device Drivers */
130144

@@ -386,6 +400,8 @@
386400
/* On-chip Peripheral Drivers */
387401

388402
#define BSP_USING_GPIO
403+
#define BSP_USING_UART
404+
#define BSP_USING_UART0
389405
/* end of On-chip Peripheral Drivers */
390406

391407
/* Board extended module Drivers */

bsp/gd32/risc-v/libraries/gd32_drivers/drv_usart.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2021-08-20 BruceOu first implementation
9+
* 2025-07-11 Wangshun adapt to GD32VV553H
910
*/
1011

1112
#include "drv_usart.h"
@@ -157,9 +158,9 @@ static const struct gd32_uart uart_obj[] = {
157158
{
158159
USART0, // uart peripheral index
159160
USART0_IRQn, // uart iqrn
160-
RCU_USART0, RCU_GPIOA, RCU_GPIOA, // periph clock, tx gpio clock, rt gpio clock
161-
GPIOA, GPIO_PIN_9, // tx port, tx pin
162-
GPIOA, GPIO_PIN_10, // rx port, rx pin
161+
RCU_USART0, RCU_GPIOB, RCU_GPIOA, // periph clock, tx gpio clock, rt gpio clock
162+
GPIOB, GPIO_PIN_15, // tx port, tx pin
163+
GPIOA, GPIO_PIN_8, // rx port, rx pin
163164
&serial0,
164165
"uart0",
165166
},
@@ -231,18 +232,18 @@ void gd32_uart_gpio_init(struct gd32_uart *uart)
231232
rcu_periph_clock_enable(uart->rx_gpio_clk);
232233
rcu_periph_clock_enable(uart->per_clk);
233234

234-
/* connect port to USARTx_Tx */
235+
/* connect port */
235236
#if defined SOC_SERIES_GD32VF103V
236237
gpio_init(uart->tx_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, uart->tx_pin);
237-
#else
238-
gpio_init(uart->tx_port, GPIO_MODE_AF, GPIO_OSPEED_MAX, uart->tx_pin);
239-
#endif
240-
241-
/* connect port to USARTx_Rx */
242-
#if defined SOC_SERIES_GD32VF103V
243238
gpio_init(uart->rx_port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, uart->rx_pin);
244239
#else
245-
gpio_init(uart->rx_port, GPIO_MODE_ANALOG, GPIO_OSPEED_MAX, uart->rx_pin);
240+
gpio_af_set(uart->tx_port, GPIO_AF_8, uart->tx_pin);
241+
gpio_mode_set(uart->tx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->tx_pin);
242+
gpio_output_options_set(uart->tx_port, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, uart->tx_pin);
243+
244+
gpio_af_set(uart->rx_port, GPIO_AF_2, uart->rx_pin);
245+
gpio_mode_set(uart->rx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->rx_pin);
246+
gpio_output_options_set(uart->rx_port, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, uart->rx_pin);
246247
#endif
247248
}
248249

@@ -327,11 +328,6 @@ static rt_err_t gd32_uart_control(struct rt_serial_device *serial, int cmd, void
327328

328329
break;
329330
case RT_DEVICE_CTRL_SET_INT:
330-
// #if defined SOC_SERIES_GD32VF103V
331-
// eclic_set_nlbits(ECLIC_GROUP_LEVEL3_PRIO1);
332-
// #else
333-
// eclic_set_nlbits(ECLIC_PRIGROUP_LEVEL3_PRIO1);
334-
// #endif
335331
/* enable rx irq */
336332
eclic_irq_enable(uart->irqn, 1, 0);
337333
/* enable interrupt */
@@ -454,7 +450,4 @@ int rt_hw_usart_init(void)
454450

455451
return result;
456452
}
457-
458-
//INIT_BOARD_EXPORT(rt_hw_usart_init);
459-
460453
#endif

0 commit comments

Comments
 (0)