Skip to content

Commit 4eec035

Browse files
committed
Add VW553H spi support
1 parent ec5f5e6 commit 4eec035

2 files changed

Lines changed: 102 additions & 24 deletions

File tree

‎bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig‎

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ menu "On-chip Peripheral Drivers"
2222
select RT_USING_PIN
2323
default n
2424

25+
menuconfig BSP_USING_SPI
26+
bool "Enable SPI BUS"
27+
default n
28+
select RT_USING_SPI
29+
if BSP_USING_SPI
30+
config BSP_USING_SPI0
31+
bool "Enable SPI0 BUS"
32+
default n
33+
34+
config BSP_SPI0_TX_USING_DMA
35+
bool "Enable SPI0 TX DMA"
36+
depends on BSP_USING_SPI0
37+
default n
38+
39+
config BSP_SPI0_RX_USING_DMA
40+
bool "Enable SPI0 RX DMA"
41+
depends on BSP_USING_SPI0
42+
select BSP_SPI0_TX_USING_DMA
43+
default n
44+
endif
45+
2546
menuconfig BSP_USING_UART
2647
bool "Enable UART"
2748
default n
@@ -56,33 +77,29 @@ menu "On-chip Peripheral Drivers"
5677
depends on BSP_USING_UART2
5778
select RT_SERIAL_USING_DMA
5879
default n
59-
endif
6080

61-
menuconfig BSP_USING_PWM
62-
bool "Enable PWM"
63-
default n
64-
select RT_USING_PWM
65-
if BSP_USING_PWM
66-
config BSP_USING_PWM0
67-
bool "Enable PWM0"
68-
default y
69-
config BSP_USING_PWM1
70-
bool "Enable PWM1"
81+
config BSP_USING_UART3
82+
bool "Enable UART3"
7183
default n
72-
config BSP_USING_PWM2
73-
bool "Enable PWM2"
84+
85+
config BSP_UART3_RX_USING_DMA
86+
bool "Enable UART3 RX DMA"
87+
depends on BSP_USING_UART3
88+
select RT_SERIAL_USING_DMA
7489
default n
75-
config BSP_USING_PWM15
76-
bool "Enable PWM15"
90+
91+
config BSP_USING_UART4
92+
bool "Enable UART4"
7793
default n
78-
config BSP_USING_PWM16
79-
bool "Enable PWM16"
94+
95+
config BSP_UART4_RX_USING_DMA
96+
bool "Enable UART4 RX DMA"
97+
depends on BSP_USING_UART4
98+
select RT_SERIAL_USING_DMA
8099
default n
81100
endif
82101

83-
84-
85-
source "$(BSP_DIR)/../libraries/gd32_drivers/Kconfig"
102+
source "$(BSP_DIR)/libraries/gd32_drivers/Kconfig"
86103

87104
endmenu
88105

‎bsp/gd32/risc-v/libraries/gd32_drivers/drv_spi.c‎

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2022-06-04 BruceOu first implementation
9+
* 2026-01-24 Unknown Add GD32VW553h
910
*/
1011
#include "drv_spi.h"
1112

@@ -29,6 +30,19 @@ static struct rt_spi_bus spi_bus2;
2930
static const struct gd32_spi spi_bus_obj[] = {
3031

3132
#ifdef BSP_USING_SPI0
33+
#if defined (SOC_SERIES_GD32VW55x)
34+
{
35+
SPI,
36+
"spi0",
37+
RCU_SPI,
38+
RCU_GPIOA,
39+
&spi_bus0,
40+
GPIOA,
41+
GPIO_PIN_9,
42+
GPIO_PIN_10,
43+
GPIO_PIN_11,
44+
}
45+
#else
3246
{
3347
SPI0,
3448
"spi0",
@@ -40,6 +54,7 @@ static const struct gd32_spi spi_bus_obj[] = {
4054
GPIO_PIN_6,
4155
GPIO_PIN_7,
4256
}
57+
#endif
4358
#endif /* BSP_USING_SPI0 */
4459

4560
#ifdef BSP_USING_SPI1
@@ -92,16 +107,22 @@ static void gd32_spi_init(struct gd32_spi *gd32_spi)
92107
rcu_periph_clock_enable(gd32_spi->spi_clk);
93108
rcu_periph_clock_enable(gd32_spi->gpio_clk);
94109

110+
#if defined (SOC_SERIES_GD32VW55x)
111+
/* configure SPI GPIO: SCK, MISO, MOSI */
112+
gpio_af_set(gd32_spi->spi_port, GPIO_AF_0, gd32_spi->sck_pin | gd32_spi->miso_pin | gd32_spi->mosi_pin);
113+
114+
gpio_mode_set(gd32_spi->spi_port, GPIO_MODE_AF, GPIO_PUPD_NONE, gd32_spi->sck_pin | gd32_spi->miso_pin | gd32_spi->mosi_pin);
115+
gpio_output_options_set(gd32_spi->spi_port, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, gd32_spi->sck_pin | gd32_spi->miso_pin | gd32_spi->mosi_pin);
116+
#else
95117
/* Init SPI SCK MOSI */
96118
gpio_init(gd32_spi->spi_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, gd32_spi->sck_pin | gd32_spi->mosi_pin);
97-
98119
/* Init SPI MISO */
99120
gpio_init(gd32_spi->spi_port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, gd32_spi->miso_pin);
100-
121+
#endif
101122
}
102123

103124
static rt_err_t spi_configure(struct rt_spi_device* device,
104-
struct rt_spi_configuration* configuration)
125+
struct rt_spi_configuration* configuration)
105126
{
106127
struct rt_spi_bus * spi_bus = (struct rt_spi_bus *)device->bus;
107128
struct gd32_spi *spi_device = (struct gd32_spi *)spi_bus->parent.user_data;
@@ -140,6 +161,9 @@ static rt_err_t spi_configure(struct rt_spi_device* device,
140161
LOG_D("CK_APB2 freq: %d\n", rcu_clock_freq_get(CK_APB2));
141162
LOG_D("max freq: %d\n", max_hz);
142163

164+
#if defined (SOC_SERIES_GD32VW55x)
165+
spi_src = CK_APB2;
166+
#else
143167
if (spi_periph == SPI1 || spi_periph == SPI2)
144168
{
145169
spi_src = CK_APB1;
@@ -148,6 +172,9 @@ static rt_err_t spi_configure(struct rt_spi_device* device,
148172
{
149173
spi_src = CK_APB2;
150174
}
175+
#endif
176+
177+
151178
spi_apb_clock = rcu_clock_freq_get(spi_src);
152179

153180
if(max_hz >= spi_apb_clock/2)
@@ -215,12 +242,19 @@ static rt_err_t spi_configure(struct rt_spi_device* device,
215242
spi_init_struct.device_mode = SPI_MASTER;
216243
spi_init_struct.nss = SPI_NSS_SOFT;
217244

245+
#if defined (SOC_SERIES_GD32VW55x)
246+
spi_crc_off();
247+
/* init SPI */
248+
spi_init(&spi_init_struct);
249+
/* Enable SPI_MASTER */
250+
spi_enable();
251+
#else
218252
spi_crc_off(spi_periph);
219-
220253
/* init SPI */
221254
spi_init(spi_periph, &spi_init_struct);
222255
/* Enable SPI_MASTER */
223256
spi_enable(spi_periph);
257+
#endif
224258

225259
return RT_EOK;
226260
};
@@ -261,6 +295,18 @@ static rt_uint32_t spixfer(struct rt_spi_device* device, struct rt_spi_message*
261295
data = *send_ptr++;
262296
}
263297

298+
#if defined (SOC_SERIES_GD32VW55x)
299+
// Todo: replace register read/write by gd32f4 lib
300+
//Wait until the transmit buffer is empty
301+
while(RESET == spi_flag_get(SPI_FLAG_TBE));
302+
// Send the byte
303+
spi_data_transmit(data);
304+
305+
//Wait until a data is received
306+
while(RESET == spi_flag_get(SPI_FLAG_RBNE));
307+
// Get the received data
308+
data = spi_data_receive();
309+
#else
264310
// Todo: replace register read/write by gd32f4 lib
265311
//Wait until the transmit buffer is empty
266312
while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_TBE));
@@ -271,6 +317,7 @@ static rt_uint32_t spixfer(struct rt_spi_device* device, struct rt_spi_message*
271317
while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_RBNE));
272318
// Get the received data
273319
data = spi_i2s_data_receive(spi_periph);
320+
#endif
274321

275322
if(recv_ptr != RT_NULL)
276323
{
@@ -294,6 +341,19 @@ static rt_uint32_t spixfer(struct rt_spi_device* device, struct rt_spi_message*
294341
data = *send_ptr++;
295342
}
296343

344+
#if defined (SOC_SERIES_GD32VW55x)
345+
// Todo: replace register read/write by gd32f4 lib
346+
//Wait until the transmit buffer is empty
347+
while(RESET == spi_flag_get(SPI_FLAG_TBE));
348+
// Send the byte
349+
spi_data_transmit(data);
350+
351+
//Wait until a data is received
352+
while(RESET == spi_flag_get(SPI_FLAG_RBNE));
353+
// Get the received data
354+
data = spi_data_receive();
355+
#else
356+
// Todo: replace register read/write by gd32f4 lib
297357
//Wait until the transmit buffer is empty
298358
while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_TBE));
299359
// Send the byte
@@ -303,6 +363,7 @@ static rt_uint32_t spixfer(struct rt_spi_device* device, struct rt_spi_message*
303363
while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_RBNE));
304364
// Get the received data
305365
data = spi_i2s_data_receive(spi_periph);
366+
#endif
306367

307368
if(recv_ptr != RT_NULL)
308369
{

0 commit comments

Comments
 (0)