diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/.ci/attachconfig/ci.attachconfig.yml b/bsp/gd32/risc-v/gd32vw553h-eval/.ci/attachconfig/ci.attachconfig.yml index 24dc1545860..4fc253e2ac2 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/.ci/attachconfig/ci.attachconfig.yml +++ b/bsp/gd32/risc-v/gd32vw553h-eval/.ci/attachconfig/ci.attachconfig.yml @@ -6,4 +6,20 @@ scons.args: &scons component.pwm: kconfig: - CONFIG_BSP_USING_PWM=y - - CONFIG_BSP_USING_PWM0=y \ No newline at end of file + - CONFIG_BSP_USING_PWM0=y + +# ------ devices ------ +devices.i2c: + kconfig: + - CONFIG_BSP_USING_HW_I2C=y + - CONFIG_BSP_USING_HW_I2C0=y + - CONFIG_BSP_HW_I2C0_PIN_PA2_PA3=y + - CONFIG_BSP_HW_I2C0_CLK=100 + - CONFIG_BSP_USING_HW_I2C1=y + - CONFIG_BSP_HW_I2C1_PIN_PB12_PB13=y + - CONFIG_BSP_HW_I2C1_CLK=100 + +devices.spi: + kconfig: + - CONFIG_BSP_USING_SPI=y + - CONFIG_BSP_USING_SPI0=y \ No newline at end of file diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig index 433c3057126..10901072711 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig @@ -79,8 +79,85 @@ menu "On-chip Peripheral Drivers" bool "Enable PWM16" default n endif + + menuconfig BSP_USING_HW_I2C + bool "Enable Hardware I2C" + default n + select RT_USING_I2C + if BSP_USING_HW_I2C + config BSP_USING_HW_I2C0 + bool "Enable Hardware I2C0" + default n + + # config i2c0 pins + choice + prompt "Select I2C0 pins" + depends on BSP_USING_HW_I2C0 + config BSP_HW_I2C0_PIN_PA2_PA3 + bool "SCL=PA2, SDA=PA3" + config BSP_HW_I2C0_PIN_PA15_PC8 + bool "SCL=PA15, SDA=PC8" + config BSP_HW_I2C0_PIN_PB0_PB1 + bool "SCL=PB0, SDA=PB1" + config BSP_HW_I2C0_PIN_PB15_PA8 + bool "SCL=PB15, SDA=PA8" + endchoice + + # config i2c0 clock + config BSP_HW_I2C0_CLK + int "I2C0 clock frequency(KHz)" + default 100 + depends on BSP_USING_HW_I2C0 + range 10 1000 + + config BSP_USING_HW_I2C1 + bool "Enable Hardware I2C1" + default n + + # config i2c1 pins + choice + prompt "Select I2C1 pins" + depends on BSP_USING_HW_I2C1 + config BSP_HW_I2C1_PIN_PA6_PA7 + bool "SCL=PA6, SDA=PA7" + config BSP_HW_I2C1_PIN_PA13_PA14 + bool "SCL=PA13, SDA=PA14" + config BSP_HW_I2C1_PIN_PA15_PC8 + bool "SCL=PA15, SDA=PC8" + config BSP_HW_I2C1_PIN_PB12_PB13 + bool "SCL=PB12, SDA=PB13" + config BSP_HW_I2C1_PIN_PB15_PA8 + bool "SCL=PB15, SDA=PA8" + endchoice + + # config i2c1 clock + config BSP_HW_I2C1_CLK + int "I2C1 clock frequency(KHz)" + default 100 + depends on BSP_USING_HW_I2C1 + range 10 1000 + endif + menuconfig BSP_USING_SPI + bool "Enable SPI BUS" + default n + select RT_USING_SPI + if BSP_USING_SPI + config BSP_USING_SPI0 + bool "Enable SPI0 BUS" + default n + + config BSP_SPI0_TX_USING_DMA + bool "Enable SPI0 TX DMA" + depends on BSP_USING_SPI0 + default n + config BSP_SPI0_RX_USING_DMA + bool "Enable SPI0 RX DMA" + depends on BSP_USING_SPI0 + select BSP_SPI0_TX_USING_DMA + default n + endif source "$(BSP_DIR)/../libraries/gd32_drivers/Kconfig" @@ -88,7 +165,29 @@ endmenu menu "Board extended module Drivers" -endmenu + menuconfig BSP_USING_AT24C02 + bool "Enable AT24C02 I2C0( SCL[PA2 : 2] SDA[PA3 : 3] )" + default n + select BSP_USING_HW_I2C + select BSP_USING_HW_I2C0 + select PKG_USING_AT24CXX + select PKG_AT24CXX_EE_TYPE_AT24C02 + + if BSP_USING_AT24C02 + + config BSP_USING_AT24C02_UTEST + bool "Enable the utest of AT24C02" + default n + select RT_USING_UTEST + select RT_USING_ULOG + select ULOG_USING_ISR_LOG + + config BSP_USING_AT24C02_INIT + bool "Init the model and check it" + default y + + endif endmenu +endmenu diff --git a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_spi.c b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_spi.c index 416ed780450..647f6919d16 100644 --- a/bsp/gd32/risc-v/libraries/gd32_drivers/drv_spi.c +++ b/bsp/gd32/risc-v/libraries/gd32_drivers/drv_spi.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2022-06-04 BruceOu first implementation + * 2026-01-24 Unknown Add GD32VW553h */ #include "drv_spi.h" @@ -29,6 +30,19 @@ static struct rt_spi_bus spi_bus2; static const struct gd32_spi spi_bus_obj[] = { #ifdef BSP_USING_SPI0 +#if defined (SOC_SERIES_GD32VW55x) + { + SPI, + "spi0", + RCU_SPI, + RCU_GPIOA, + &spi_bus0, + GPIOA, + GPIO_PIN_9, + GPIO_PIN_10, + GPIO_PIN_11, + } +#else { SPI0, "spi0", @@ -40,6 +54,7 @@ static const struct gd32_spi spi_bus_obj[] = { GPIO_PIN_6, GPIO_PIN_7, } +#endif #endif /* BSP_USING_SPI0 */ #ifdef BSP_USING_SPI1 @@ -92,16 +107,22 @@ static void gd32_spi_init(struct gd32_spi *gd32_spi) rcu_periph_clock_enable(gd32_spi->spi_clk); rcu_periph_clock_enable(gd32_spi->gpio_clk); +#if defined (SOC_SERIES_GD32VW55x) + /* configure SPI GPIO: SCK, MISO, MOSI */ + gpio_af_set(gd32_spi->spi_port, GPIO_AF_0, gd32_spi->sck_pin | gd32_spi->miso_pin | gd32_spi->mosi_pin); + + 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); + 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); +#else /* Init SPI SCK MOSI */ gpio_init(gd32_spi->spi_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, gd32_spi->sck_pin | gd32_spi->mosi_pin); - /* Init SPI MISO */ gpio_init(gd32_spi->spi_port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, gd32_spi->miso_pin); - +#endif } static rt_err_t spi_configure(struct rt_spi_device* device, - struct rt_spi_configuration* configuration) + struct rt_spi_configuration* configuration) { struct rt_spi_bus * spi_bus = (struct rt_spi_bus *)device->bus; 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, LOG_D("CK_APB2 freq: %d\n", rcu_clock_freq_get(CK_APB2)); LOG_D("max freq: %d\n", max_hz); +#if defined (SOC_SERIES_GD32VW55x) + spi_src = CK_APB2; +#else if (spi_periph == SPI1 || spi_periph == SPI2) { spi_src = CK_APB1; @@ -148,6 +172,9 @@ static rt_err_t spi_configure(struct rt_spi_device* device, { spi_src = CK_APB2; } +#endif + + spi_apb_clock = rcu_clock_freq_get(spi_src); if(max_hz >= spi_apb_clock/2) @@ -215,12 +242,19 @@ static rt_err_t spi_configure(struct rt_spi_device* device, spi_init_struct.device_mode = SPI_MASTER; spi_init_struct.nss = SPI_NSS_SOFT; +#if defined (SOC_SERIES_GD32VW55x) + spi_crc_off(); + /* init SPI */ + spi_init(&spi_init_struct); + /* Enable SPI_MASTER */ + spi_enable(); +#else spi_crc_off(spi_periph); - /* init SPI */ spi_init(spi_periph, &spi_init_struct); /* Enable SPI_MASTER */ spi_enable(spi_periph); +#endif return RT_EOK; }; @@ -261,16 +295,27 @@ static rt_uint32_t spixfer(struct rt_spi_device* device, struct rt_spi_message* data = *send_ptr++; } - // Todo: replace register read/write by gd32f4 lib - //Wait until the transmit buffer is empty +#if defined (SOC_SERIES_GD32VW55x) + /* Wait until the transmit buffer is empty */ + while(RESET == spi_flag_get(SPI_FLAG_TBE)); + /* Send the byte */ + spi_data_transmit(data); + + /* Wait until a data is received */ + while(RESET == spi_flag_get(SPI_FLAG_RBNE)); + /* Get the received data */ + data = spi_data_receive(); +#else + /* Wait until the transmit buffer is empty */ while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_TBE)); - // Send the byte + /* Send the byte */ spi_i2s_data_transmit(spi_periph, data); - //Wait until a data is received + /* Wait until a data is received */ while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_RBNE)); - // Get the received data + /* Get the received data */ data = spi_i2s_data_receive(spi_periph); +#endif if(recv_ptr != RT_NULL) { @@ -294,15 +339,27 @@ static rt_uint32_t spixfer(struct rt_spi_device* device, struct rt_spi_message* data = *send_ptr++; } - //Wait until the transmit buffer is empty +#if defined (SOC_SERIES_GD32VW55x) + /* Wait until the transmit buffer is empty */ + while(RESET == spi_flag_get(SPI_FLAG_TBE)); + /* Send the byte */ + spi_data_transmit(data); + + /* Wait until a data is received */ + while(RESET == spi_flag_get(SPI_FLAG_RBNE)); + /* Get the received data */ + data = spi_data_receive(); +#else + /* Wait until the transmit buffer is empty */ while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_TBE)); - // Send the byte + /* Send the byte */ spi_i2s_data_transmit(spi_periph, data); - //Wait until a data is received + /* Wait until a data is received */ while(RESET == spi_i2s_flag_get(spi_periph, SPI_FLAG_RBNE)); - // Get the received data + /* Get the received data */ data = spi_i2s_data_receive(spi_periph); +#endif if(recv_ptr != RT_NULL) {