diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/README.md b/bsp/gd32/risc-v/gd32vw553h-eval/README.md index 53589e4c007..b9e7fc0f34d 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/README.md +++ b/bsp/gd32/risc-v/gd32vw553h-eval/README.md @@ -170,7 +170,51 @@ msh > 完成上述配置后即可点击调试选项进行调试,调试时boot管脚均置为低电平即可,调试时同样会进行固件下载。 -## 4 注意事项 +## 4.WIFI使用 + +使用ENV,menuconfig,修改和使能下面的配置 + +* 修改 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版本不匹配的问题。 diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/applications/main.c b/bsp/gd32/risc-v/gd32vw553h-eval/applications/main.c index 706c3d03bb6..e26413bf713 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/applications/main.c +++ b/bsp/gd32/risc-v/gd32vw553h-eval/applications/main.c @@ -13,15 +13,57 @@ #include #include #include - +#ifdef BSP_USING_WLAN +#include "gd32vw55x_platform.h" +#include "wrapper_os.h" +#include "wifi_management.h" +#include "wifi_init.h" +#include "user_setting.h" +#include "util.h" +#endif /* BSP_USING_WLAN */ /* LED1 ~ LED3 pin: PA4 PA5 PA6 */ #define LED1_PIN GET_PIN(A, 4) -int main(void) + +#ifdef RT_USING_WIFI +#define START_TASK_STACK_SIZE 512 +#define START_TASK_PRIO 4 + +static void application_init(void) { - rt_kprintf("Hello GD32VW553H\n"); - /* set LED1 pin mode to output */ - rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT); + 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 */ + +/* LED blink thread */ +static void led_thread_entry(void *param) +{ + (void)param; while (1) { @@ -30,6 +72,63 @@ int main(void) rt_pin_write(LED1_PIN, PIN_LOW); rt_thread_mdelay(500); } +} + +int main(void) +{ + rt_thread_t led_thread; + + rt_kprintf("Hello GD32VW553H\n"); + /* set LED1 pin mode to output */ + rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT); + +#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 */ + + /* Create LED blink thread */ + led_thread = rt_thread_create("led", + led_thread_entry, + RT_NULL, + 1024, + 25, /* Lower priority to not block shell */ + 10); + if (led_thread != RT_NULL) { + rt_thread_startup(led_thread); + rt_kprintf("LED thread started\n"); + } else { + rt_kprintf("Failed to create LED thread\n"); + } + /* Return from main to allow shell to work properly */ return RT_EOK; } diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig index 8d0f34949a2..7f5404a79ad 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig @@ -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" diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript b/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript index 71fadebe66f..5fd20e23bac 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript @@ -12,12 +12,17 @@ board.c trap_gcc.S ''') +# add WiFi driver +if GetDepend(['BSP_USING_WLAN']): + src += ['drv_wlan.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'] diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/drv_wlan.c b/bsp/gd32/risc-v/gd32vw553h-eval/board/drv_wlan.c new file mode 100644 index 00000000000..d594a37cd41 --- /dev/null +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/drv_wlan.c @@ -0,0 +1,513 @@ +/* + * 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 + */ + +#include +#include +#include "board.h" + +#ifdef RT_USING_WIFI +#include "drv_wlan.h" +#include "gd32vw55x_platform.h" +#include "wifi_management.h" +#include "wifi_init.h" + +#define DBG_TAG "drv.wlan" +#define DBG_LVL DBG_INFO +#include + +enum { + WIFI_VIF_STA = 0, + WIFI_VIF_AP, + WIFI_VIF_MAX +}; + +/* GD32VW553H WiFi device structure */ +struct gd32_wlan_device +{ + struct rt_wlan_device *wlan; + rt_uint8_t if_idx; /* Interface index: 0 - STA, 1 - AP */ + rt_uint8_t dev_addr[MAC_ADDR_LEN]; /* MAC address */ +}; + +static struct gd32_wlan_device wlan_sta_device; +static struct gd32_wlan_device wlan_ap_device; + +/** + * @brief WiFi initialization callback + */ +static rt_err_t gd32_wlan_init(struct rt_wlan_device *wlan) +{ + LOG_D("WiFi device init: %s", wlan->name); + + return RT_EOK; +} + +/** + * @brief WiFi mode configuration + */ +static rt_err_t gd32_wlan_mode(struct rt_wlan_device *wlan, rt_wlan_mode_t mode) +{ + LOG_D("Set WiFi mode: %d", mode); + + /* TODO: Set WiFi mode (STA/AP/STA+AP) */ + + return RT_EOK; +} + +static inline int wifi_freq_to_channel(uint16_t freq) +{ + if ((freq >= 2412) && (freq <= 2484)) { + if (freq == 2484) + return 14; + else + return (freq - 2407) / 5; + } + return 0; +} + +static void scan_done_callback(void *eloop_data, void *user_ctx) +{ + int idx; + struct macif_scan_results *results = RT_NULL; + struct mac_scan_result *bss_info = RT_NULL; + struct rt_wlan_info wlan_info; + struct rt_wlan_buff buff; + + results = (struct macif_scan_results *)rt_malloc(sizeof(struct macif_scan_results)); + if (RT_NULL == results) { + LOG_E("Failed to allocate memory for scan results\r\n"); + return; + } + + if (wifi_netlink_scan_results_get(WIFI_VIF_STA, results)) { + rt_free(results); + rt_kprintf("WIFI scan results get failed\r\n"); + return; + } + + for (idx = 0; idx < results->result_cnt; idx++) { + bss_info = &results->result[idx]; + + rt_memset(&wlan_info, 0, sizeof(wlan_info)); + + rt_memcpy(&wlan_info.bssid[0], (char *)bss_info->bssid.array, MAC_ADDR_LEN); + rt_memcpy(wlan_info.ssid.val, (char *)bss_info->ssid.array, bss_info->ssid.length); + wlan_info.ssid.len = bss_info->ssid.length; + wlan_info.hidden = bss_info->ssid.length > 0 ? 0 : 1; + + wlan_info.channel = wifi_freq_to_channel(bss_info->chan->freq); + wlan_info.rssi = bss_info->rssi; + wlan_info.band = RT_802_11_BAND_2_4GHZ; + + wlan_info.security = SECURITY_UNKNOWN; + + if (bss_info->akm & CO_BIT(MAC_AKM_NONE)) { + wlan_info.security = SECURITY_OPEN; + } else if (bss_info->akm == CO_BIT(MAC_AKM_PRE_RSN)) { + wlan_info.security = SECURITY_WEP_PSK; + } else if (bss_info->akm & CO_BIT(MAC_AKM_PRE_RSN)) { // WPA + if (bss_info->pairwise_cipher & CO_BIT(MAC_CIPHER_TKIP)) { + wlan_info.security = SECURITY_WPA_TKIP_PSK; + } else if (bss_info->pairwise_cipher & CO_BIT(MAC_CIPHER_CCMP)) { + wlan_info.security = SECURITY_WPA_AES_PSK; + } + } else { // WPA2 + if ((bss_info->pairwise_cipher & CO_BIT(MAC_CIPHER_TKIP)) && + (bss_info->pairwise_cipher & CO_BIT(MAC_CIPHER_CCMP))) { + wlan_info.security = SECURITY_WPA2_MIXED_PSK; + } else if (bss_info->pairwise_cipher & CO_BIT(MAC_CIPHER_TKIP)) { + wlan_info.security = SECURITY_WPA2_TKIP_PSK; + } else if (bss_info->pairwise_cipher & CO_BIT(MAC_CIPHER_CCMP)) { + wlan_info.security = SECURITY_WPA2_AES_PSK; + } + } + + buff.data = &wlan_info; + buff.len = sizeof(wlan_info); + rt_wlan_dev_indicate_event_handle(wlan_sta_device.wlan, RT_WLAN_DEV_EVT_SCAN_REPORT, &buff); + } + + rt_free(results); + rt_wlan_dev_indicate_event_handle(wlan_sta_device.wlan, RT_WLAN_DEV_EVT_SCAN_DONE, RT_NULL); + + eloop_event_unregister(WIFI_MGMT_EVENT_SCAN_DONE); + eloop_event_unregister(WIFI_MGMT_EVENT_SCAN_FAIL); +} + +static void scan_fail_callback(void *eloop_data, void *user_ctx) +{ + rt_kprintf("WIFI_SCAN: failed\r\n"); + eloop_event_unregister(WIFI_MGMT_EVENT_SCAN_DONE); + eloop_event_unregister(WIFI_MGMT_EVENT_SCAN_FAIL); +} + +/** + * @brief WiFi scan + */ +static rt_err_t gd32_wlan_scan(struct rt_wlan_device *wlan, struct rt_scan_info *scan_info) +{ + // rt_kprintf("WiFi scan start\r\n"); + + eloop_event_register(WIFI_MGMT_EVENT_SCAN_DONE, scan_done_callback, NULL, NULL); + eloop_event_register(WIFI_MGMT_EVENT_SCAN_FAIL, scan_fail_callback, NULL, NULL); + + if (wifi_management_scan(false, NULL)) { + eloop_event_unregister(WIFI_MGMT_EVENT_SCAN_DONE); + eloop_event_unregister(WIFI_MGMT_EVENT_SCAN_FAIL); + rt_kprintf("Wifi scan failed\r\n"); + } + + return RT_EOK; +} + +static void sta_conn_success_cb(void *eloop_data, void *user_ctx) +{ + LOG_D("WIFI_JOIN_SUCCESS"); + rt_kprintf("WiFi connected successfully\r\n"); + + eloop_event_unregister(WIFI_MGMT_EVENT_CONNECT_SUCCESS); + eloop_event_unregister(WIFI_MGMT_EVENT_CONNECT_FAIL); + + rt_wlan_dev_indicate_event_handle(wlan_sta_device.wlan, RT_WLAN_DEV_EVT_CONNECT, RT_NULL); +} + +static void sta_conn_fail_cb(void *eloop_data, void *user_ctx) +{ + LOG_D("WIFI_JOIN_FAILED"); + rt_kprintf("WiFi connection failed\r\n"); + + eloop_event_unregister(WIFI_MGMT_EVENT_CONNECT_SUCCESS); + eloop_event_unregister(WIFI_MGMT_EVENT_CONNECT_FAIL); + + rt_wlan_dev_indicate_event_handle(wlan_sta_device.wlan, RT_WLAN_DEV_EVT_CONNECT_FAIL, RT_NULL); +} + +/** + * @brief WiFi join (connect to AP) + */ +static rt_err_t gd32_wlan_join(struct rt_wlan_device *wlan, struct rt_sta_info *sta_info) +{ + LOG_D("WiFi join SSID: %s", sta_info->ssid.val); + // rt_kprintf("WiFi join start\r\n"); + + // 先注销可能存在的旧回调 + eloop_event_unregister(WIFI_MGMT_EVENT_CONNECT_SUCCESS); + eloop_event_unregister(WIFI_MGMT_EVENT_CONNECT_FAIL); + + if (wifi_management_connect(sta_info->ssid.val, sta_info->key.val, 0) < 0) { + rt_kprintf("WiFi join failed\r\n"); + return -RT_ERROR; + } + + eloop_event_register(WIFI_MGMT_EVENT_CONNECT_SUCCESS, sta_conn_success_cb, NULL, NULL); + eloop_event_register(WIFI_MGMT_EVENT_CONNECT_FAIL, sta_conn_fail_cb, NULL, NULL); + + return RT_EOK; +} + +/** + * @brief WiFi softap start + */ +static rt_err_t gd32_wlan_softap(struct rt_wlan_device *wlan, struct rt_ap_info *ap_info) +{ + LOG_D("WiFi softap start SSID: %s", ap_info->ssid.val); + + wifi_ap_auth_mode_t auth_mode; + char *ssid = ap_info->ssid.val; + char *passwd = ap_info->key.val; + uint32_t channel = ap_info->channel; + uint32_t hidden = ap_info->hidden; + + if (wifi_management_concurrent_get() == 0) { + wifi_management_concurrent_set(1); + } + + switch (ap_info->security) + { + case SECURITY_OPEN: + passwd = RT_NULL; + auth_mode = AUTH_MODE_OPEN; + break; + + case SECURITY_WEP_PSK: + case SECURITY_WEP_SHARED: + auth_mode = AUTH_MODE_WEP; + break; + + case SECURITY_WPA_TKIP_PSK: + case SECURITY_WPA_AES_PSK: + auth_mode = AUTH_MODE_WPA; + break; + + case SECURITY_WPA2_TKIP_PSK: + case SECURITY_WPA2_AES_PSK: + auth_mode = AUTH_MODE_WPA2; + break; + + case SECURITY_WPA2_MIXED_PSK: + auth_mode = AUTH_MODE_WPA_WPA2; + break; + + case SECURITY_UNKNOWN: + auth_mode = AUTH_MODE_UNKNOWN; + break; + + default: + rt_kprintf("Unsupported AP security mode %d, set to OPEN\r\n", ap_info->security); + auth_mode = AUTH_MODE_OPEN; + break; + } + + if (wifi_management_ap_start(ssid, passwd, channel, auth_mode, hidden) < 0) { + rt_kprintf("WiFi softap start failed\r\n"); + return -RT_ERROR; + } + + rt_wlan_dev_indicate_event_handle(wlan_ap_device.wlan, RT_WLAN_DEV_EVT_AP_START, RT_NULL); + + return RT_EOK; +} + +/** + * @brief WiFi disconnect + */ +static rt_err_t gd32_wlan_disconnect(struct rt_wlan_device *wlan) +{ + LOG_D("WiFi disconnect"); + + wifi_management_disconnect(); + + rt_wlan_dev_indicate_event_handle(wlan_sta_device.wlan, RT_WLAN_DEV_EVT_DISCONNECT, RT_NULL); + + return RT_EOK; +} + +/** + * @brief WiFi AP disconnect station + */ +static rt_err_t gd32_wlan_ap_stop(struct rt_wlan_device *wlan) +{ + LOG_D("WiFi AP stop"); + + if (wifi_management_concurrent_get() == 0) { + wifi_management_concurrent_set(1); + } + + if (wifi_management_ap_stop() < 0) { + rt_kprintf("WiFi AP stop failed\r\n"); + return -RT_ERROR; + } + + rt_wlan_dev_indicate_event_handle(wlan_ap_device.wlan, RT_WLAN_DEV_EVT_AP_STOP, RT_NULL); + return RT_EOK; +} + +/** + * @brief WiFi AP deauthenticate station + */ +static rt_err_t gd32_wlan_ap_deauth(struct rt_wlan_device *wlan, rt_uint8_t mac[]) +{ + LOG_D("WiFi AP deauth station"); + + if (wifi_management_concurrent_get() == 0) { + wifi_management_concurrent_set(1); + } + + if (wifi_management_ap_delete_client(mac) < 0) { + rt_kprintf("WiFi AP deauth station failed\r\n"); + return -RT_ERROR; + } + + return RT_EOK; +} + +/** + * @brief Get WiFi RSSI + */ +static rt_err_t gd32_wlan_scan_stop(struct rt_wlan_device *wlan) +{ + LOG_D("WiFi scan stop"); + + /* TODO: Stop WiFi scan */ + + return RT_EOK; +} + +/** + * @brief Get WiFi channel + */ +static int gd32_wlan_get_rssi(struct rt_wlan_device *wlan) +{ + int rssi = 0; + + /* TODO: Get current RSSI value */ + + return rssi; +} + +/** + * @brief Set WiFi channel + */ +static rt_err_t gd32_wlan_set_channel(struct rt_wlan_device *wlan, int channel) +{ + LOG_D("Set WiFi channel: %d", channel); + + /* TODO: Set WiFi channel */ + + return RT_EOK; +} + +/** + * @brief Get WiFi channel + */ +static int gd32_wlan_get_channel(struct rt_wlan_device *wlan) +{ + int channel = 1; + + /* TODO: Get current WiFi channel */ + + return channel; +} + +/** + * @brief Set WiFi country code + */ +static rt_err_t gd32_wlan_set_country(struct rt_wlan_device *wlan, rt_country_code_t country_code) +{ + LOG_D("Set WiFi country code: %d", country_code); + + /* TODO: Set WiFi country code */ + + return RT_EOK; +} + +/** + * @brief Get WiFi country code + */ +static rt_country_code_t gd32_wlan_get_country(struct rt_wlan_device *wlan) +{ + /* TODO: Get WiFi country code */ + + return RT_COUNTRY_CHINA; +} + +/** + * @brief Set WiFi MAC address + */ +static rt_err_t gd32_wlan_set_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[]) +{ + LOG_D("Set WiFi MAC: %02x:%02x:%02x:%02x:%02x:%02x", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + /* TODO: Set WiFi MAC address */ + + return RT_EOK; +} + +/** + * @brief Get WiFi MAC address + */ +static rt_err_t gd32_wlan_get_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[]) +{ + return RT_EOK; +} + +/** + * @brief WiFi receive callback + */ +static int gd32_wlan_recv(struct rt_wlan_device *wlan, void *buff, int len) +{ + /* 不需要实现 - GD32 SDK LwIP 内部处理数据接收 */ + /* 数据接收流程:*/ + /* 硬件中断 -> MAC层 -> net_if_input() -> lwip tcpip_input() -> 协议栈处理 */ + + return RT_EOK; +} + +/** + * @brief WiFi send + */ +static int gd32_wlan_send(struct rt_wlan_device *wlan, void *buff, int len) +{ + /* 不需要实现 - GD32 SDK LwIP 内部处理数据发送 */ + /* 数据发送流程:*/ + /* 应用层 -> lwIP协议栈 -> netif->linkoutput() -> net_if_output() -> MAC层 */ + + return len; +} + +/* WiFi operations */ +static const struct rt_wlan_dev_ops gd32_wlan_ops = +{ + .wlan_init = gd32_wlan_init, + .wlan_mode = gd32_wlan_mode, + .wlan_scan = gd32_wlan_scan, + .wlan_join = gd32_wlan_join, + .wlan_softap = gd32_wlan_softap, + .wlan_disconnect = gd32_wlan_disconnect, + .wlan_ap_stop = gd32_wlan_ap_stop, + .wlan_ap_deauth = gd32_wlan_ap_deauth, + .wlan_scan_stop = gd32_wlan_scan_stop, + .wlan_get_rssi = gd32_wlan_get_rssi, + .wlan_set_powersave = RT_NULL, + .wlan_get_powersave = RT_NULL, + .wlan_cfg_promisc = RT_NULL, + .wlan_cfg_filter = RT_NULL, + .wlan_set_channel = gd32_wlan_set_channel, + .wlan_get_channel = gd32_wlan_get_channel, + .wlan_set_country = gd32_wlan_set_country, + .wlan_get_country = gd32_wlan_get_country, + .wlan_set_mac = gd32_wlan_set_mac, + .wlan_get_mac = gd32_wlan_get_mac, + .wlan_recv = gd32_wlan_recv, + .wlan_send = gd32_wlan_send, +}; + +/** + * @brief Initialize WiFi driver + */ +int rt_hw_wlan_init(void) +{ + static rt_bool_t init_flag = RT_FALSE; + + if (init_flag) + { + return RT_EOK; + } + + platform_init(); + + /* Initialize WiFi device structure */ + rt_memset(&wlan_sta_device, 0, sizeof(struct gd32_wlan_device)); + rt_memset(&wlan_ap_device, 0, sizeof(struct gd32_wlan_device)); + + // 向系统注册 + static struct rt_wlan_device wlan_sta; + static struct rt_wlan_device wlan_ap; + + /* Register WiFi STA device */ + wlan_sta_device.if_idx = WIFI_VIF_STA; /* STA interface */ + rt_err_t ret = rt_wlan_dev_register(&wlan_sta, RT_WLAN_DEVICE_STA_NAME, &gd32_wlan_ops, 0, &wlan_sta_device); + wlan_sta_device.wlan = &wlan_sta; + + + /* Register WiFi AP device */ + wlan_ap_device.if_idx = WIFI_VIF_AP; /* AP interface */ + ret |= rt_wlan_dev_register(&wlan_ap, RT_WLAN_DEVICE_AP_NAME, &gd32_wlan_ops, 0, &wlan_ap_device); + wlan_ap_device.wlan = &wlan_ap; + + init_flag = RT_TRUE; + + LOG_I("GD32 WiFi driver initialized"); + + return ret; +} +INIT_DEVICE_EXPORT(rt_hw_wlan_init); +#endif \ No newline at end of file diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/drv_wlan.h b/bsp/gd32/risc-v/gd32vw553h-eval/board/drv_wlan.h new file mode 100644 index 00000000000..8ac7585de24 --- /dev/null +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/drv_wlan.h @@ -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__ */ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/linker_scripts/link.lds b/bsp/gd32/risc-v/gd32vw553h-eval/board/linker_scripts/link.lds index 82516919c27..a763c1918ea 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/linker_scripts/link.lds +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/linker_scripts/link.lds @@ -3,12 +3,12 @@ OUTPUT_ARCH( "riscv" ) ENTRY( _start ) MEMORY -{ - /* Run in FLASH */ +{ + /* Run in FLASH */ flash (rxai!w) : ORIGIN = 0x08000000, LENGTH = 4096k - ram (wxa!ri) : ORIGIN = 0x20000000, LENGTH = 288K + ram (wxa!ri) : ORIGIN = 0x20000000, LENGTH = 288K - /* Run in RAM */ + /* Run in RAM */ /* flash (rxai!w) : ORIGIN = 0x20000000, LENGTH = 32k ram (wxa!ri) : ORIGIN = 0x20008000, LENGTH = 256K */ @@ -23,27 +23,64 @@ SECTIONS .init : { KEEP (*(SORT_NONE(.init))) - } >flash AT>flash + } >flash AT>flash .ilalign : { . = ALIGN(4); PROVIDE( _ilm_lma = . ); - } >flash AT>flash + } >flash AT>flash .ialign : { PROVIDE( _ilm = . ); - } >flash AT>flash + } >flash AT>flash + + _sicode = LOADADDR(.code_to_sram); + + .code_to_sram : + { + . = ALIGN(4); + _scode = .; + + *trap_gcc.o* (.text*) + *port.o* (.text.eclic_mtip_handler) + *lib_a-memcpy.o* (.text*) + *wrapper_os.o* (.text.sys_memcpy*) + *inet_chksum.o* (.text.lwip_standard_chksum) + /**macsw/modules/ke/ke_event.o* (.rodata.ke_evt_hdlr*) + *rxl_cntrl.o* (.text.rxl_upload_evt)*/ + *txl_agg.o* (.text.txl_agg_push_mpdu .text.txl_agg_finish) + *txl_he.o* (.text.txl_he_tb_prot_trigger .text.txl_he_trigger_push) + *rxl_hwdesc.o* (.text.rxl_immediate_frame_get .text.rxl_rxcntrl_frame) + + + *txl_agg.o* (.text.* .rodata.*) + *txl_he.o* (.text.* .rodata.*) + *rxl_hwdesc.o* (.text.* .rodata.*) + + *drv_uart.o* (.text.USART0_IRQHandler .text.GD32_UART_IRQHandler) /* choose UART on condition */ + *gd32vw55x_usart.o* (.text.usart_interrupt_flag_get .text.usart_interrupt_flag_clear .text.usart_flag_get .text.usart_flag_clear) + *gd32vw55x_usart.o* (.text.usart_data_receive .text.usart_data_transmit) + *gd32vw55x_usart.o* (.text.usart_interrupt_enable .text.usart_interrupt_disable) + *dev_serial.o* (.text.rt_hw_serial_isr) + *save-restore.o* (.text*) + + + . = ALIGN(4); + _ecode = .; + } >ram AT>flash + + .text : { - *(.rodata .rodata.*) + *(.rodata .rodata.*) *(.text.unlikely .text.unlikely.*) *(.text.startup .text.startup.*) *(.text .text.*) *(.gnu.linkonce.t.*) - + /* section information for finsh shell */ . = ALIGN(4); __fsymtab_start = .; @@ -67,12 +104,12 @@ SECTIONS __rtmsymtab_start = .; KEEP(*(RTMSymTab)) __rtmsymtab_end = .; - } >flash AT>flash + } >flash AT>flash .fini : { KEEP (*(SORT_NONE(.fini))) - } >flash AT>flash + } >flash AT>flash . = ALIGN(4); @@ -86,7 +123,7 @@ SECTIONS PROVIDE_HIDDEN (__preinit_array_start = .); KEEP (*(.preinit_array)) PROVIDE_HIDDEN (__preinit_array_end = .); - } >flash AT>flash + } >flash AT>flash .init_array : { @@ -94,7 +131,7 @@ SECTIONS KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) PROVIDE_HIDDEN (__init_array_end = .); - } >flash AT>flash + } >flash AT>flash .fini_array : { @@ -102,7 +139,7 @@ SECTIONS KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) PROVIDE_HIDDEN (__fini_array_end = .); - } >flash AT>flash + } >flash AT>flash .ctors : { @@ -124,7 +161,7 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) - } >flash AT>flash + } >flash AT>flash .dtors : { @@ -133,7 +170,7 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) - } >flash AT>flash + } >flash AT>flash . = ALIGN(4); PROVIDE( _eilm = . ); @@ -142,24 +179,24 @@ SECTIONS { . = ALIGN(4); PROVIDE( _data_lma = . ); - } >flash AT>flash + } >flash AT>flash .dalign : { . = ALIGN(4); - PROVIDE( _data = . ); - } >ram AT>flash - - + } >ram AT>flash + + .data : { - *(.rdata) - + PROVIDE( _data = . ); + *(.rdata) + *(.gnu.linkonce.r.*) *(.data .data.*) *(.gnu.linkonce.d.*) . = ALIGN(8); - PROVIDE( __global_pointer$ = . + 0x800); + PROVIDE( __global_pointer$ = . + 0x800); *(.sdata .sdata.*) *(.gnu.linkonce.s.*) . = ALIGN(8); @@ -168,7 +205,7 @@ SECTIONS *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) - } >ram AT>flash + } >ram AT>flash . = ALIGN(4); PROVIDE( _edata = . ); @@ -184,7 +221,7 @@ SECTIONS *(.gnu.linkonce.b.*) *(COMMON) . = ALIGN(4); - } >ram AT>ram + } >ram AT>ram . = ALIGN(8); PROVIDE( _end = . ); /*0X2000,0340*/ @@ -192,9 +229,9 @@ SECTIONS .stack ORIGIN(ram) + LENGTH(ram) - __stack_size : { - PROVIDE( _heap_end = . ); - . = __stack_size; + PROVIDE( _heap_end = . ); + . = __stack_size; PROVIDE( _sp = . ); PROVIDE( __rt_rvstack = .); - } >ram AT>ram + } >ram AT>ram } diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/trap_gcc.S b/bsp/gd32/risc-v/gd32vw553h-eval/board/trap_gcc.S index 3e6e070ae44..c237d190a4d 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/trap_gcc.S +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/trap_gcc.S @@ -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 @@ -42,4 +44,4 @@ rt_hw_do_after_save_above: LOAD ra, 0 * REGBYTES(sp) addi sp, sp, 4 - ret + ret \ No newline at end of file diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145545039.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145545039.png new file mode 100644 index 00000000000..74771fd7261 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145545039.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145642371.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145642371.png new file mode 100644 index 00000000000..6016c21f83f Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145642371.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145735119.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145735119.png new file mode 100644 index 00000000000..7d07b8e16d7 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145735119.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145751469.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145751469.png new file mode 100644 index 00000000000..7d07b8e16d7 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145751469.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145759739.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145759739.png new file mode 100644 index 00000000000..7d07b8e16d7 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145759739.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145806668.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145806668.png new file mode 100644 index 00000000000..7d07b8e16d7 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145806668.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145856756.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145856756.png new file mode 100644 index 00000000000..8aaa71d961f Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145856756.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145903955.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145903955.png new file mode 100644 index 00000000000..8aaa71d961f Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205145903955.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205150826393.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205150826393.png new file mode 100644 index 00000000000..0b1013b8918 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205150826393.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151251937.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151251937.png new file mode 100644 index 00000000000..655a6e3dcfa Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151251937.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151356304.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151356304.png new file mode 100644 index 00000000000..a5b4067fe17 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151356304.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151403278.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151403278.png new file mode 100644 index 00000000000..a5b4067fe17 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151403278.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151409209.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151409209.png new file mode 100644 index 00000000000..a5b4067fe17 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151409209.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151644687.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151644687.png new file mode 100644 index 00000000000..d02bcab0fe2 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151644687.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151712234.png b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151712234.png new file mode 100644 index 00000000000..1fc38bea834 Binary files /dev/null and b/bsp/gd32/risc-v/gd32vw553h-eval/figures/image-20260205151712234.png differ diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/rtconfig.py b/bsp/gd32/risc-v/gd32vw553h-eval/rtconfig.py index 79d8de523e7..cb895196fc6 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/rtconfig.py +++ b/bsp/gd32/risc-v/gd32vw553h-eval/rtconfig.py @@ -43,14 +43,27 @@ 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 符号表 + import os + wifi_pkg_path = os.path.join(os.path.dirname(__file__), 'packages', 'gd32vw55x-wifi') + 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 = '' @@ -61,7 +74,7 @@ else: CFLAGS += ' -O2' - CXXFLAGS = CFLAGS + CXXFLAGS = CFLAGS POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' diff --git a/components/drivers/wlan/dev_wlan_cmd.c b/components/drivers/wlan/dev_wlan_cmd.c index 6592281dac5..accf782ffa2 100644 --- a/components/drivers/wlan/dev_wlan_cmd.c +++ b/components/drivers/wlan/dev_wlan_cmd.c @@ -79,10 +79,14 @@ 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}, - {"auto", wifi_debug_set_autoconnect}, +#else + {"mode", wifi_debug_set_mode }, +#endif /* RT_WLAN_PROT_ENABLE */ + {"auto", wifi_debug_set_autoconnect }, }; #endif @@ -171,7 +175,7 @@ static rt_bool_t wifi_info_isequ(struct rt_wlan_info *info1, struct rt_wlan_info is_equ &= rt_memcmp(&info2->ssid.val[0], &info1->ssid.val[0], info1->ssid.len) == 0; } if (is_equ && (rt_memcmp(&info1->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH)) && - (rt_memcmp(&info2->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH))) + (rt_memcmp(&info2->bssid[0], bssid_zero, RT_WLAN_BSSID_MAX_LENGTH))) { is_equ &= rt_memcmp(&info1->bssid[0], &info2->bssid[0], RT_WLAN_BSSID_MAX_LENGTH) == 0; } @@ -197,10 +201,11 @@ 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]); + info->bssid[0], info->bssid[1], info->bssid[2], info->bssid[3], info->bssid[4], info->bssid[5]); /* scanning result filtering */ level = rt_hw_interrupt_disable(); @@ -222,7 +227,7 @@ static rt_err_t wifi_scan_result_cache(struct rt_wlan_info *info) for (i = 0; i < scan_result.num; i++) { if ((info->ssid.len == scan_result.info[i].ssid.len) && - (rt_memcmp(&info->bssid[0], &scan_result.info[i].bssid[0], RT_WLAN_BSSID_MAX_LENGTH) == 0)) + (rt_memcmp(&info->bssid[0], &scan_result.info[i].bssid[0], RT_WLAN_BSSID_MAX_LENGTH) == 0)) { return RT_EOK; } @@ -283,7 +288,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 +312,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,68 +323,66 @@ 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; + char *security; - if(index == 0) - { - rt_kprintf(" SSID MAC security rssi chn Mbps\n"); - rt_kprintf("------------------------------- ----------------- -------------- ---- --- ----\n"); - } + if (index == 0) + { + rt_kprintf(" SSID MAC security rssi chn Mbps\n"); + rt_kprintf("------------------------------- ----------------- -------------- ---- --- ----\n"); + } + { + rt_kprintf("%-32.32s", &(info->ssid.val[0])); + rt_kprintf("%02x:%02x:%02x:%02x:%02x:%02x ", + info->bssid[0], + info->bssid[1], + info->bssid[2], + info->bssid[3], + info->bssid[4], + info->bssid[5]); + switch (info->security) { - rt_kprintf("%-32.32s", &(info->ssid.val[0])); - rt_kprintf("%02x:%02x:%02x:%02x:%02x:%02x ", - info->bssid[0], - info->bssid[1], - info->bssid[2], - info->bssid[3], - info->bssid[4], - info->bssid[5] - ); - switch (info->security) - { - case SECURITY_OPEN: - security = "OPEN"; - break; - case SECURITY_WEP_PSK: - security = "WEP_PSK"; - break; - case SECURITY_WEP_SHARED: - security = "WEP_SHARED"; - break; - case SECURITY_WPA_TKIP_PSK: - security = "WPA_TKIP_PSK"; - break; - case SECURITY_WPA_AES_PSK: - security = "WPA_AES_PSK"; - break; - case SECURITY_WPA2_AES_PSK: - security = "WPA2_AES_PSK"; - break; - case SECURITY_WPA2_TKIP_PSK: - security = "WPA2_TKIP_PSK"; - break; - case SECURITY_WPA2_MIXED_PSK: - security = "WPA2_MIXED_PSK"; - break; - case SECURITY_WPS_OPEN: - security = "WPS_OPEN"; - break; - case SECURITY_WPS_SECURE: - security = "WPS_SECURE"; - break; - default: - security = "UNKNOWN"; - break; - } - rt_kprintf("%-14.14s ", security); - rt_kprintf("%-4d ", info->rssi); - rt_kprintf("%3d ", info->channel); - rt_kprintf("%4d\n", info->datarate / 1000000); + case SECURITY_OPEN: + security = "OPEN"; + break; + case SECURITY_WEP_PSK: + security = "WEP_PSK"; + break; + case SECURITY_WEP_SHARED: + security = "WEP_SHARED"; + break; + case SECURITY_WPA_TKIP_PSK: + security = "WPA_TKIP_PSK"; + break; + case SECURITY_WPA_AES_PSK: + security = "WPA_AES_PSK"; + break; + case SECURITY_WPA2_AES_PSK: + security = "WPA2_AES_PSK"; + break; + case SECURITY_WPA2_TKIP_PSK: + security = "WPA2_TKIP_PSK"; + break; + case SECURITY_WPA2_MIXED_PSK: + security = "WPA2_MIXED_PSK"; + break; + case SECURITY_WPS_OPEN: + security = "WPS_OPEN"; + break; + case SECURITY_WPS_SECURE: + security = "WPS_SECURE"; + break; + default: + security = "UNKNOWN"; + break; } - + rt_kprintf("%-14.14s ", security); + rt_kprintf("%-4d ", info->rssi); + 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,25 +400,24 @@ 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 || - (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)) + 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)) { /*Check whether a new ap is added*/ 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 +436,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 +451,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; } @@ -472,7 +472,7 @@ static int wifi_join(int argc, char *argv[]) struct rt_wlan_cfg_info cfg_info; rt_memset(&cfg_info, 0, sizeof(cfg_info)); - if (argc == 2) + if (argc == 2) { #ifdef RT_WLAN_CFG_ENABLE /* get info to connect */ @@ -678,7 +678,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 +725,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; } diff --git a/components/net/lwip/port/SConscript b/components/net/lwip/port/SConscript index c2ca3678a46..d838b4c08aa 100644 --- a/components/net/lwip/port/SConscript +++ b/components/net/lwip/port/SConscript @@ -5,6 +5,10 @@ path = [cwd] src = Glob('*.c') +# 如果使用了GD32 WiFi包,则排除sys_arch.c(GD32有自己的实现) +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') diff --git a/libcpu/risc-v/common/interrupt_gcc.S b/libcpu/risc-v/common/interrupt_gcc.S index 6eb0ef371f6..65f53932bd8 100644 --- a/libcpu/risc-v/common/interrupt_gcc.S +++ b/libcpu/risc-v/common/interrupt_gcc.S @@ -17,7 +17,7 @@ .align 6 #else .align 2 -#endif +#endif .global SW_handler SW_handler: @@ -102,12 +102,21 @@ SW_handler: /* interrupt handle */ call rt_interrupt_enter /* Do the work after saving the above */ - jal rt_hw_do_after_save_above - +#ifdef SOC_GD32VW553H + call rt_hw_do_after_save_above +#else + jal rt_hw_do_after_save_above +#endif call rt_interrupt_leave /* switch to from thread stack */ csrrw sp,mscratch,sp - +#ifdef SOC_GD32VW553H + /* Check if we are in interrupt nesting, if so, skip task switching */ + la t0, rt_interrupt_nest + lw t1, 0(t0) + li t3, 1 + bge t1, t3, 1f +#endif /* SOC_GD32VW553H */ /* Determine whether to trigger scheduling at the interrupt function */ la t0, rt_thread_switch_interrupt_flag lw t2, 0(t0)