[bsp][gd32]:gd32vw553h-eval add wifi support#11175

This commit is contained in:
CYFS
2026-03-04 18:07:10 +08:00
committed by GitHub
parent 196477d753
commit 737ae54878
26 changed files with 857 additions and 112 deletions

View File

@@ -19,6 +19,15 @@ devices.i2c:
- CONFIG_BSP_HW_I2C1_PIN_PB12_PB13=y
- CONFIG_BSP_HW_I2C1_CLK=100
devices.wlan:
kconfig:
- CONFIG_BSP_USING_WLAN=y
- CONFIG_RT_NAME_MAX=24
- CONFIG_RT_WLAN_PROT_ENABLE=n
- CONFIG_RT_USING_LWIP212=y
# ------ peripheral CI ------
peripheral.at24c02:
kconfig:

View File

@@ -170,7 +170,51 @@ msh >
完成上述配置后即可点击调试选项进行调试调试时boot管脚均置为低电平即可调试时同样会进行固件下载。
## 4 注意事项
## 4.WIFI使用
使用ENVmenuconfig修改和使能下面的配置
* 修改 RT_NAME_MAX为24
![image-20260205145545039](figures/image-20260205145545039.png)
* 使能 BSP_USING_WLAN
![image-20260205145642371](figures/image-20260205145642371.png)
* 修改LWIP的版本为V2.1.2
![image-20260205145806668](figures/image-20260205145806668.png)
* 关闭 RT_WLAN_PROT_ENABLE
![image-20260205145856756](figures/image-20260205145856756.png)
进行编译 scons -jx ,下载。
![image-20260205150826393](figures/image-20260205150826393.png)
可以使用help查看wifi指令下面演示连接wifi以及ping
![image-20260205151251937](figures/image-20260205151251937.png)
### 使用NETDEV
* 使能 RT_USING_NETDEV
![image-20260205151356304](figures/image-20260205151356304.png)
重新编译,下载。
* wifi 连接以及ping
![image-20260205151712234](figures/image-20260205151712234.png)
* ifconfig
![image-20260205151644687](figures/image-20260205151644687.png)
## 5 注意事项
- Cortex-Debug插件优先选用v1.4.4版本高版本可能会出现与GDB版本不匹配的问题。

View File

@@ -13,6 +13,34 @@ config SOC_GD32VW553H
menu "Onboard Peripheral Drivers"
menuconfig BSP_USING_WLAN
bool "Enable WiFi (GD32VW553H Internal)"
select RT_USING_WIFI
select PKG_USING_GD32VW55X_WIFI
select RT_USING_MEMHEAP
select RT_USING_SYSTEM_WORKQUEUE
default n
if BSP_USING_WLAN
config BSP_WLAN_SSID_MAX_LENGTH
int "WiFi SSID max length"
range 1 32
default 32
config BSP_WLAN_PASSWORD_MAX_LENGTH
int "WiFi password max length"
range 8 64
default 64
config BSP_WLAN_SCAN_CACHE_NUM
int "WiFi scan result cache number"
range 4 32
default 16
# Include GD32VW55x WIFI package configuration
osource "$(BSP_DIR)/packages/gd32vw55x-wifi/Kconfig"
endif
endmenu
menu "On-chip Peripheral Drivers"

View File

@@ -12,12 +12,18 @@ board.c
trap_gcc.S
''')
# add WiFi driver
if GetDepend(['BSP_USING_WLAN']):
src += ['drv_wlan.c']
src += ['wifi.c']
path = [cwd]
# add startup txt path
startup_path_prefix = os.getcwd() + '/../'
if rtconfig.PLATFORM in ['gcc']:
# Use standard peripheral library startup files for compatibility
src += [startup_path_prefix + '/packages/gd32-riscv-series-latest/GD32VW55x/RISCV/env_Eclipse/start.S']
src += [startup_path_prefix + '/packages/gd32-riscv-series-latest/GD32VW55x/RISCV/env_Eclipse/entry.S']

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2025-12-25 RT-Thread first version
*/
#ifndef __DRV_WIFI_H__
#define __DRV_WIFI_H__
#ifdef RT_USING_WIFI
int rt_hw_wlan_init(void);
#endif /* RT_USING_WIFI */
#endif /* __DRV_WIFI_H__ */

View File

@@ -2,18 +2,20 @@
#include "riscv_encoding.h"
.macro SAVE_CSR_CONTEXT
csrrwi x0, CSR_PUSHMCAUSE, 11
csrrwi x0, CSR_PUSHMEPC, 12
csrrwi x0, CSR_PUSHMSUBM, 13
addi sp, sp, -16
csrrwi x0, CSR_PUSHMCAUSE, 1
csrrwi x0, CSR_PUSHMEPC, 2
csrrwi x0, CSR_PUSHMSUBM, 3
.endm
.macro RESTORE_CSR_CONTEXT
LOAD x5, 13*REGBYTES(sp)
LOAD x5, 3*REGBYTES(sp)
csrw CSR_MSUBM, x5
LOAD x5, 12*REGBYTES(sp)
LOAD x5, 2*REGBYTES(sp)
csrw CSR_MEPC, x5
LOAD x5, 11*REGBYTES(sp)
LOAD x5, 1*REGBYTES(sp)
csrw CSR_MCAUSE, x5
addi sp, sp, 16
.endm
.macro DISABLE_MIE

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-02-25 CYFS first version
*/
#include <stdio.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "gd32vw55x_platform.h"
#include "wrapper_os.h"
#include "wifi_management.h"
#include "wifi_init.h"
#include "user_setting.h"
#include "util.h"
#ifdef RT_USING_WIFI
#define START_TASK_STACK_SIZE 512
#define START_TASK_PRIO 4
static void application_init(void)
{
util_init();
user_setting_init();
if (wifi_init())
{
rt_kprintf("wifi init failed\r\n");
} else {
/* rt_kprintf("wifi init success\r\n"); */
}
}
static rt_sem_t init_done_sem = RT_NULL;
static void start_task(void *param)
{
(void)param;
application_init();
/* rt_kprintf("Start task completed, exiting.\n"); */
/* Note: In RT-Thread, task should exit by returning, not by calling sys_task_delete(NULL).
* When the task function returns, RT-Thread will automatically clean up the task.
*/
rt_sem_release(init_done_sem);
}
#endif /* RT_USING_WIFI */
int wifi_app_init(void)
{
#ifdef RT_USING_WIFI
/* Create semaphore for synchronization */
init_done_sem = rt_sem_create("init_done", 0, RT_IPC_FLAG_PRIO);
if (init_done_sem == RT_NULL)
{
rt_kprintf("Failed to create semaphore\n");
return -RT_ERROR;
}
if (sys_task_create_dynamic((const uint8_t *)"start_task",
START_TASK_STACK_SIZE, OS_TASK_PRIORITY(START_TASK_PRIO), start_task, NULL) == NULL)
{
rt_kprintf("Create start task failed\r\n");
return -RT_ERROR;
}
/* rt_kprintf("Waiting for initialization to complete...\n"); */
/* Wait for initialization task to complete */
rt_sem_take(init_done_sem, RT_WAITING_FOREVER);
/* rt_kprintf("Initialization completed, continuing...\n"); */
/* Clean up semaphore */
rt_sem_delete(init_done_sem);
init_done_sem = RT_NULL;
/* set wifi work mode */
rt_wlan_set_mode(RT_WLAN_DEVICE_STA_NAME, RT_WLAN_STATION);
rt_wlan_set_mode(RT_WLAN_DEVICE_AP_NAME, RT_WLAN_AP);
#ifdef RT_USING_NETDEV
rt_thread_mdelay(1000);
extern int wifi_netdev_register(void);
wifi_netdev_register();
#endif /* RT_USING_NETDEV */
#endif /* RT_USING_WIFI */
return RT_EOK;
}
INIT_APP_EXPORT(wifi_app_init);

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@@ -43,14 +43,26 @@ if PLATFORM == 'gcc':
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -march=rv32imafdc -mcmodel=medany -msmall-data-limit=8 -mdiv -mabi=ilp32d -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections '
# 使用单精度硬件浮点ABI以匹配预编译的WiFi库 (libwifi.a, libwpas.a, librf.a)
# 预编译库架构: rv32imafcbp (包含单精度浮点 'f' 扩展)
# 原配置: -march=rv32imafdc -mabi=ilp32d (硬件双精度浮点)
# 修改为: -march=rv32imafc -mabi=ilp32f (硬件单精度浮点)
# 注意: GCC 8.2.0 不支持 -mpriv-spec 选项,链接时使用 --no-warn-mismatch 忽略特权规范版本差异
DEVICE = ' -march=rv32imafc -mcmodel=medany -msmall-data-limit=8 -mabi=ilp32f -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections '
# C Compilation Parameters
CFLAGS = DEVICE + ' -std=gnu11 -DUSE_STDPERIPH_DRIVE -save-temps=obj'
# Assembly Compilation Parameters
AFLAGS = DEVICE + '-c'+ ' -x assembler-with-cpp'
# Linking Parameters
LFLAGS = DEVICE + ' -nostartfiles -Xlinker --gc-sections --specs=nano.specs --specs=nosys.specs ' + ' -T ' + LINK_FILE + ' -Wl,-Map=' + MAP_FILE
# 添加 --no-warn-mismatch 以忽略预编译库与当前工具链的特权规范版本差异
# 添加 WiFi ROM 符号表
wifi_pkg_path = os.path.join(os.path.dirname(__file__), 'packages', 'gd32vw55x-wifi-latest')
rom_symbol = os.path.join(wifi_pkg_path, 'rom_export', 'symbol', 'rom_symbol_m.gcc')
rom_symbol_flag = ''
if os.path.exists(rom_symbol):
rom_symbol_flag = ' -Wl,--just-symbols=' + rom_symbol
LFLAGS = DEVICE + ' -nostartfiles -Xlinker --gc-sections -Xlinker --no-warn-mismatch --specs=nano.specs --specs=nosys.specs ' + rom_symbol_flag + ' -T ' + LINK_FILE + ' -Wl,-Map=' + MAP_FILE
CPATH = ''
LPATH = ''

View File

@@ -56,33 +56,35 @@ static int wifi_debug_set_autoconnect(int argc, char *argv[]);
#endif
/* cmd table */
static const struct wifi_cmd_des cmd_tab[] =
{
{"scan", wifi_scan},
{"help", wifi_help},
{"status", wifi_status},
{"join", wifi_join},
{"ap", wifi_ap},
{"list_sta", wifi_list_sta},
{"disc", wifi_disconnect},
{"ap_stop", wifi_ap_stop},
{"smartconfig", RT_NULL},
static const struct wifi_cmd_des cmd_tab[] = {
{ "scan", wifi_scan },
{ "help", wifi_help },
{ "status", wifi_status },
{ "join", wifi_join },
{ "ap", wifi_ap },
{ "list_sta", wifi_list_sta },
{ "disc", wifi_disconnect },
{ "ap_stop", wifi_ap_stop },
{ "smartconfig", RT_NULL },
#ifdef RT_WLAN_CMD_DEBUG
{"-d", wifi_debug},
{ "-d", wifi_debug },
#endif
};
#ifdef RT_WLAN_CMD_DEBUG
/* debug cmd table */
static const struct wifi_cmd_des debug_tab[] =
{
{"save_cfg", wifi_debug_save_cfg},
{"dump_cfg", wifi_debug_dump_cfg},
{"clear_cfg", wifi_debug_clear_cfg},
{"dump_prot", wifi_debug_dump_prot},
{"mode", wifi_debug_set_mode},
{"prot", wifi_debug_set_prot},
{"auto", wifi_debug_set_autoconnect},
static const struct wifi_cmd_des debug_tab[] = {
{ "save_cfg", wifi_debug_save_cfg },
{ "dump_cfg", wifi_debug_dump_cfg },
{ "clear_cfg", wifi_debug_clear_cfg },
#ifdef RT_WLAN_PROT_ENABLE
{ "dump_prot", wifi_debug_dump_prot },
{ "mode", wifi_debug_set_mode },
{ "prot", wifi_debug_set_prot },
#else
{ "mode", wifi_debug_set_mode },
#endif /* RT_WLAN_PROT_ENABLE */
{ "auto", wifi_debug_set_autoconnect },
};
#endif
@@ -197,7 +199,8 @@ static rt_err_t wifi_scan_result_cache(struct rt_wlan_info *info)
int i, insert = -1;
rt_base_t level;
if ((info == RT_NULL) || (info->ssid.len == 0)) return -RT_EINVAL;
if ((info == RT_NULL) || (info->ssid.len == 0))
return -RT_EINVAL;
LOG_D("ssid:%s len:%d mac:%02x:%02x:%02x:%02x:%02x:%02x", info->ssid.val, info->ssid.len,
info->bssid[0], info->bssid[1], info->bssid[2], info->bssid[3], info->bssid[4], info->bssid[5]);
@@ -283,7 +286,7 @@ static rt_err_t wifi_scan_result_cache(struct rt_wlan_info *info)
LOG_E("wlan info malloc failed!");
return -RT_ENOMEM;
}
scan_result.num ++;
scan_result.num++;
/* copy info */
for (i = 0; i < scan_result.num; i++)
@@ -307,10 +310,8 @@ static rt_err_t wifi_scan_result_cache(struct rt_wlan_info *info)
}
static void wifi_scan_result_clean(void)
{
/* If there is data */
if (scan_result.num)
{
@@ -320,11 +321,11 @@ static void wifi_scan_result_clean(void)
}
}
static void print_ap_info(struct rt_wlan_info *info,int index)
static void print_ap_info(struct rt_wlan_info *info, int index)
{
char *security;
if(index == 0)
if (index == 0)
{
rt_kprintf(" SSID MAC security rssi chn Mbps\n");
rt_kprintf("------------------------------- ----------------- -------------- ---- --- ----\n");
@@ -338,8 +339,7 @@ static void print_ap_info(struct rt_wlan_info *info,int index)
info->bssid[2],
info->bssid[3],
info->bssid[4],
info->bssid[5]
);
info->bssid[5]);
switch (info->security)
{
case SECURITY_OPEN:
@@ -381,7 +381,6 @@ static void print_ap_info(struct rt_wlan_info *info,int index)
rt_kprintf("%3d ", info->channel);
rt_kprintf("%4d\n", info->datarate / 1000000);
}
}
static void user_ap_info_callback(int event, struct rt_wlan_buff *buff, void *parameter)
@@ -399,9 +398,9 @@ static void user_ap_info_callback(int event, struct rt_wlan_buff *buff, void *pa
index = *((int *)(parameter));
ret = wifi_scan_result_cache(info);
if(ret == RT_EOK)
if (ret == RT_EOK)
{
if(scan_filter == RT_NULL ||
if (scan_filter == RT_NULL ||
(scan_filter != RT_NULL &&
scan_filter->ssid.len == info->ssid.len &&
rt_memcmp(&scan_filter->ssid.val[0], &info->ssid.val[0], scan_filter->ssid.len) == 0))
@@ -410,14 +409,13 @@ static void user_ap_info_callback(int event, struct rt_wlan_buff *buff, void *pa
if (last_num < scan_result.num)
{
/*Print the info*/
print_ap_info(info,index);
print_ap_info(info, index);
}
index++;
*((int *)(parameter)) = index;
}
}
}
static int wifi_scan(int argc, char *argv[])
{
@@ -436,14 +434,14 @@ static int wifi_scan(int argc, char *argv[])
info = &filter;
}
ret = rt_wlan_register_event_handler(RT_WLAN_EVT_SCAN_REPORT,user_ap_info_callback,&i);
if(ret != RT_EOK)
ret = rt_wlan_register_event_handler(RT_WLAN_EVT_SCAN_REPORT, user_ap_info_callback, &i);
if (ret != RT_EOK)
{
LOG_E("Scan register user callback error:%d!\n",ret);
LOG_E("Scan register user callback error:%d!\n", ret);
return 0;
}
if(info)
if (info)
{
scan_filter = info;
}
@@ -451,14 +449,14 @@ static int wifi_scan(int argc, char *argv[])
/*Todo: what can i do for it return val */
ret = rt_wlan_scan_with_info(info);
if(ret != RT_EOK)
if (ret != RT_EOK)
{
LOG_E("Scan with info error:%d!\n",ret);
LOG_E("Scan with info error:%d!\n", ret);
}
/* clean scan result */
wifi_scan_result_clean();
if(info)
if (info)
{
scan_filter = RT_NULL;
}
@@ -678,7 +676,12 @@ static int wifi_debug_dump_prot(int argc, char *argv[])
{
if (argc == 1)
{
#ifdef RT_WLAN_PROT_ENABLE
rt_wlan_prot_dump();
#else
rt_kprintf("wlan protocol disabled\r\n");
return -1;
#endif
}
else
{
@@ -720,7 +723,12 @@ static int wifi_debug_set_prot(int argc, char *argv[])
return -1;
}
#ifdef RT_WLAN_PROT_ENABLE
rt_wlan_prot_attach(argv[2], argv[1]);
#else
rt_kprintf("wlan protocol disabled\r\n");
return -1;
#endif
return 0;
}

View File

@@ -5,6 +5,10 @@ path = [cwd]
src = Glob('*.c')
# 如果使用了GD32 WiFi包则排除sys_arch.cGD32有自己的实现
if GetDepend(['PKG_USING_GD32VW55X_WIFI']):
src = [f for f in src if not str(f).endswith('sys_arch.c')]
group = DefineGroup('lwIP', src, depend = ['RT_USING_LWIP'], CPPPATH = path)
Return('group')