Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions bsp/gd32/arm/gd32407v-lckfb/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ menu "On-chip Peripheral Drivers"
default n
select RT_USING_SPI
if BSP_USING_SPI
config BSP_USING_SPI0
bool "Enable SPI0 BUS"
default n

config BSP_USING_SPI1
bool "Enable SPI1 BUS"
default n
Expand Down Expand Up @@ -357,6 +361,53 @@ endmenu

menu "Board extended module Drivers"

config BSP_USING_CH390
bool "Enable WCH CH390 SPI Ethernet module"
select BSP_USING_SPI
select BSP_USING_SPI0
select RT_USING_CH390
select RT_USING_PIN
default n

if BSP_USING_CH390
config BSP_CH390_SPI_BUS_NAME
string "CH390 SPI bus name on this board"
default "spi0"

config BSP_CH390_SPI_DEVICE_NAME
string "CH390 SPI device name on this board"
default "spi10"

config BSP_CH390_NETIF_NAME
string "CH390 network interface name"
default "e0"

config BSP_CH390_CS_PIN
int "CH390 CS pin number on this board"
default 4

config BSP_CH390_RST_PIN
int "CH390 reset pin number on this board"
default -1

config BSP_CH390_INT_PIN
int "CH390 interrupt pin number on this board"
default 3

config BSP_CH390_SPI_MAX_HZ
int "CH390 SPI maximum frequency"
default 5000000

config BSP_CH390_POLL_INTERVAL_MS
int "CH390 RX polling interval in milliseconds"
default 20

config BSP_CH390_USING_DHCP
bool "Use DHCP for CH390 netif"
select RT_LWIP_DHCP
default n
endif

endmenu

endmenu
8 changes: 7 additions & 1 deletion bsp/gd32/arm/gd32407v-lckfb/board/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import rtconfig
from building import *

cwd = GetCurrentDir()
objs = []

# add general drivers
src = Split('''
Expand All @@ -14,4 +15,9 @@ path = [cwd]
CPPDEFINES = ['GD32F407','LCKFB_SKYSTART_GD32F407V']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
objs += group

if os.path.isfile(os.path.join(cwd, 'ports', 'SConscript')):
objs += SConscript(os.path.join('ports', 'SConscript'))

Return('objs')
15 changes: 15 additions & 0 deletions bsp/gd32/arm/gd32407v-lckfb/board/ports/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Import('RTT_ROOT')
from building import *

cwd = GetCurrentDir()

src = []
path = [cwd, cwd + '/..', cwd + '/../../../libraries/gd32_drivers',
RTT_ROOT + '/components/drivers/spi']

if GetDepend('BSP_USING_CH390'):
src += ['ch390_port.c']

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path)

Return('group')
52 changes: 52 additions & 0 deletions bsp/gd32/arm/gd32407v-lckfb/board/ports/ch390_port.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-07-07 Liu Changjie add CH390 board port
*/

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <drv_spi.h>
#include <ch390.h>

#ifdef BSP_USING_CH390

#define DBG_TAG "drv.ch390.port"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

static const rt_uint8_t ch390_mac[6] = {0x02, 0x12, 0x34, 0x56, 0x78, 0x90};

static int rt_hw_ch390_port_init(void)
{
struct ch390_config config;
rt_err_t ret;

ret = rt_hw_spi_device_attach(BSP_CH390_SPI_BUS_NAME,
BSP_CH390_SPI_DEVICE_NAME,
BSP_CH390_CS_PIN);
if (ret != RT_EOK)
{
LOG_E("attach %s to %s failed: %d",
BSP_CH390_SPI_DEVICE_NAME, BSP_CH390_SPI_BUS_NAME, ret);
return ret;
}

config.spi_device_name = BSP_CH390_SPI_DEVICE_NAME;
config.netif_name = BSP_CH390_NETIF_NAME;
config.rst_pin = BSP_CH390_RST_PIN;
config.int_pin = BSP_CH390_INT_PIN;
config.mac = ch390_mac;
config.spi_max_hz = BSP_CH390_SPI_MAX_HZ;
config.poll_interval_ms = BSP_CH390_POLL_INTERVAL_MS;

return ch390_attach(&config);
}
INIT_DEVICE_EXPORT(rt_hw_ch390_port_init);

#endif /* BSP_USING_CH390 */
6 changes: 6 additions & 0 deletions components/drivers/spi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ menuconfig RT_USING_SPI
select RT_USING_LWIP
default n

config RT_USING_CH390
bool "Using WCH CH390 SPI Ethernet network interface"
select RT_USING_LWIP
select RT_USING_PIN
default n

config RT_USING_SPI_WIFI
bool "Using RW009/007 SPI Wi-Fi wireless interface"
select RT_USING_LWIP
Expand Down
3 changes: 3 additions & 0 deletions components/drivers/spi/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ if GetDepend('RT_USING_SPI_WIFI'):
if GetDepend('RT_USING_ENC28J60'):
src_device += ['enc28j60.c']

if GetDepend('RT_USING_CH390'):
src_device += ['ch390.c']

if GetDepend('RT_USING_SPI_MSD'):
src_device += ['dev_spi_msd.c']

Expand Down
Loading