This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a60ac789a45f912853d98305cfd9c458be9ec838 Author: raul_chen <[email protected]> AuthorDate: Mon Jul 6 16:44:33 2026 +0800 arch/arm/ameba: register wlan0 synchronously for boot WiFi auto-connect rtl8720f_wifi_initialize() spawned a kthread to run the blocking WHC host bring-up and register wlan0, so the netdev appeared only after netinit had already run its one-shot associate -- the WiFi never auto-connected at boot. Do the bring-up synchronously on the board bring-up path (mirroring rtl8721dx_wifi_initialize) so wlan0 exists before netinit runs. Enable the standard netinit auto-connect machinery in both board defconfigs: NETINIT_THREAD (runs associate + DHCP off the NSH init path so the prompt is not blocked), NETINIT_DHCPC, and placeholder NETINIT_WAPI_SSID/PASSPHRASE the user replaces with their own credentials (WIRELESS_WAPI + the wapi cmdtool are already enabled). Signed-off-by: raul_chen <[email protected]> --- arch/arm/src/rtl8720f/ameba_wifi_init.c | 68 +++++++++------------- arch/arm/src/rtl8721dx/ameba_wifi_init.c | 68 +++++++++------------- .../rtl8720f/rtl8720f_evb/configs/nsh/defconfig | 4 ++ .../arm/rtl8721dx/pke8721daf/configs/nsh/defconfig | 4 ++ 4 files changed, 64 insertions(+), 80 deletions(-) diff --git a/arch/arm/src/rtl8720f/ameba_wifi_init.c b/arch/arm/src/rtl8720f/ameba_wifi_init.c index 2bff9b442dd..17b3a0d526b 100644 --- a/arch/arm/src/rtl8720f/ameba_wifi_init.c +++ b/arch/arm/src/rtl8720f/ameba_wifi_init.c @@ -67,38 +67,6 @@ extern int ameba_wifi_start(void); -/**************************************************************************** - * Name: ameba_wifi_start_task - * - * Description: - * Task entry running the blocking WHC host bring-up once the scheduler and - * IPC are up. - * - ****************************************************************************/ - -static int ameba_wifi_start_task(int argc, char *argv[]) -{ - UNUSED(argc); - UNUSED(argv); - - /* Power on the WHC host stack (blocks on the NP round-trip), then register - * the wlan0 network device. - */ - - int ret = ameba_wifi_start(); - - syslog(LOG_INFO, "[ameba-wifi] ameba_wifi_start -> %d\n", ret); - if (ret == 0) - { -#ifdef CONFIG_NET - ret = ameba_wlan_initialize(); - syslog(LOG_INFO, "[ameba-wifi] ameba_wlan_initialize -> %d\n", ret); -#endif - } - - return 0; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -107,17 +75,25 @@ static int ameba_wifi_start_task(int argc, char *argv[]) * Name: rtl8720f_wifi_initialize * * Description: - * Bring up the KM4 IPC transport for WiFi and start the WHC host stack. - * Call from board bring-up after the scheduler is running. + * Bring up the km4tz IPC transport for WiFi, start the WHC host stack and + * register the wlan0 network device. Call from board bring-up after the + * scheduler is running. + * + * Done synchronously (no worker task) so that wlan0 is registered before + * the network initialisation (netinit) runs -- the standard NuttX flow + * where the WiFi netdev already exists when board bring-up returns, so + * netinit can associate + DHCP automatically. wifi_on() blocks on the NP + * IPC round-trip; the NP is already running and IPC is initialised just + * above, so the wait is bounded. * * Returned Value: - * 0 on success; a negated errno on failure to spawn the bring-up task. + * 0 on success; a negated errno on failure. * ****************************************************************************/ int rtl8720f_wifi_initialize(void) { - int pid; + int ret; /* Route the km4tz IPC interrupt to the SDK dispatcher and register every * channel the linked objects contributed (WHC WiFi TRX channels included). @@ -126,9 +102,21 @@ int rtl8720f_wifi_initialize(void) ameba_ipc_initialize(); - /* wifi_on() blocks on the NP round-trip, so run it off the init path. */ + /* Power on the WHC host stack (blocks on the NP round-trip). */ + + ret = ameba_wifi_start(); + syslog(LOG_INFO, "[ameba-wifi] ameba_wifi_start -> %d\n", ret); + if (ret < 0) + { + return ret; + } + +#ifdef CONFIG_NET + /* Register wlan0 before returning so netinit sees it at bring-up. */ + + ret = ameba_wlan_initialize(); + syslog(LOG_INFO, "[ameba-wifi] ameba_wlan_initialize -> %d\n", ret); +#endif - pid = kthread_create("ameba_wifi", SCHED_PRIORITY_DEFAULT, 8192, - ameba_wifi_start_task, NULL); - return pid < 0 ? pid : 0; + return ret; } diff --git a/arch/arm/src/rtl8721dx/ameba_wifi_init.c b/arch/arm/src/rtl8721dx/ameba_wifi_init.c index 2ccd8f0b509..44e401765eb 100644 --- a/arch/arm/src/rtl8721dx/ameba_wifi_init.c +++ b/arch/arm/src/rtl8721dx/ameba_wifi_init.c @@ -102,38 +102,6 @@ static int ameba_ipc_interrupt(int irq, void *context, void *arg) return OK; } -/**************************************************************************** - * Name: ameba_wifi_start_task - * - * Description: - * Task entry running the blocking WHC host bring-up once the scheduler and - * IPC are up. - * - ****************************************************************************/ - -static int ameba_wifi_start_task(int argc, char *argv[]) -{ - UNUSED(argc); - UNUSED(argv); - - /* Power on the WHC host stack (blocks on the NP round-trip), then register - * the wlan0 network device. - */ - - int ret = ameba_wifi_start(); - - syslog(LOG_INFO, "[ameba-wifi] ameba_wifi_start -> %d\n", ret); - if (ret == 0) - { -#ifdef CONFIG_NET - ret = ameba_wlan_initialize(); - syslog(LOG_INFO, "[ameba-wifi] ameba_wlan_initialize -> %d\n", ret); -#endif - } - - return 0; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -142,17 +110,25 @@ static int ameba_wifi_start_task(int argc, char *argv[]) * Name: rtl8721dx_wifi_initialize * * Description: - * Bring up the KM4 IPC transport for WiFi and start the WHC host stack. - * Call from board bring-up after the scheduler is running. + * Bring up the KM4 IPC transport for WiFi, start the WHC host stack and + * register the wlan0 network device. Call from board bring-up after the + * scheduler is running. + * + * Done synchronously (no worker task) so that wlan0 is registered before + * the network initialisation (netinit) runs -- the standard NuttX flow + * where the WiFi netdev already exists when board bring-up returns, so + * netinit can associate + DHCP automatically. wifi_on() blocks on the NP + * IPC round-trip; the NP is already running and IPC is initialised just + * above, so the wait is bounded. * * Returned Value: - * 0 on success; a negated errno on failure to spawn the bring-up task. + * 0 on success; a negated errno on failure. * ****************************************************************************/ int rtl8721dx_wifi_initialize(void) { - int pid; + int ret; /* Route the KM4 IPC interrupt to the SDK dispatcher and register every * channel the linked objects contributed (WHC WiFi TRX channels included). @@ -162,9 +138,21 @@ int rtl8721dx_wifi_initialize(void) up_enable_irq(RTL8721DX_IRQ_IPC_KM4); ipc_table_init(IPCKM4_DEV); - /* wifi_on() blocks on the NP round-trip, so run it off the init path. */ + /* Power on the WHC host stack (blocks on the NP round-trip). */ + + ret = ameba_wifi_start(); + syslog(LOG_INFO, "[ameba-wifi] ameba_wifi_start -> %d\n", ret); + if (ret < 0) + { + return ret; + } + +#ifdef CONFIG_NET + /* Register wlan0 before returning so netinit sees it at bring-up. */ + + ret = ameba_wlan_initialize(); + syslog(LOG_INFO, "[ameba-wifi] ameba_wlan_initialize -> %d\n", ret); +#endif - pid = kthread_create("ameba_wifi", SCHED_PRIORITY_DEFAULT, 8192, - ameba_wifi_start_task, NULL); - return pid < 0 ? pid : 0; + return ret; } diff --git a/boards/arm/rtl8720f/rtl8720f_evb/configs/nsh/defconfig b/boards/arm/rtl8720f/rtl8720f_evb/configs/nsh/defconfig index c5fd399080f..b18613f488f 100644 --- a/boards/arm/rtl8720f/rtl8720f_evb/configs/nsh/defconfig +++ b/boards/arm/rtl8720f/rtl8720f_evb/configs/nsh/defconfig @@ -38,6 +38,10 @@ CONFIG_NET=y CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDEV_LATEINIT=y CONFIG_NETDEV_WIRELESS_IOCTL=y +CONFIG_NETINIT_DHCPC=y +CONFIG_NETINIT_THREAD=y +CONFIG_NETINIT_WAPI_PASSPHRASE="YOUR_WIFI_PASSWORD" +CONFIG_NETINIT_WAPI_SSID="YOUR_WIFI_SSID" CONFIG_NETUTILS_DHCPD=y CONFIG_NETUTILS_DHCPD_ROUTERIP=0xc0a80401 CONFIG_NETUTILS_DHCPD_STARTIP=0xc0a80402 diff --git a/boards/arm/rtl8721dx/pke8721daf/configs/nsh/defconfig b/boards/arm/rtl8721dx/pke8721daf/configs/nsh/defconfig index 55f3b8e5013..e50b5c94877 100644 --- a/boards/arm/rtl8721dx/pke8721daf/configs/nsh/defconfig +++ b/boards/arm/rtl8721dx/pke8721daf/configs/nsh/defconfig @@ -38,6 +38,10 @@ CONFIG_NET=y CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDEV_LATEINIT=y CONFIG_NETDEV_WIRELESS_IOCTL=y +CONFIG_NETINIT_DHCPC=y +CONFIG_NETINIT_THREAD=y +CONFIG_NETINIT_WAPI_PASSPHRASE="YOUR_WIFI_PASSWORD" +CONFIG_NETINIT_WAPI_SSID="YOUR_WIFI_SSID" CONFIG_NETUTILS_DHCPD=y CONFIG_NETUTILS_DHCPD_ROUTERIP=0xc0a80401 CONFIG_NETUTILS_DHCPD_STARTIP=0xc0a80402
