From 3dbd62e25686e0f8742ae5da7fcc3741a64d1061 Mon Sep 17 00:00:00 2001 From: dechao_gong Date: Mon, 27 Jul 2026 19:07:20 +0800 Subject: [PATCH] arch/arm/rtl8721f: enable on-chip flash filesystem and WiFi networking Bring up the last two RTL8721F feature blocks and wire them into the nsh board configuration: - littlefs on the on-chip flash MTD region (P2). - WHC/INIC WiFi with the on-chip IPC control plane, NuttX net stack, DHCP client and the wapi command tool (P3). Two porting fixes were required for the WiFi control plane: - ameba_ipc.c: the AP IPC device base (IPCAP_DEV) was carried over verbatim from the RTL8720F template (0x40804000). On this SoC IPC0 lives at 0x40815000; using the wrong base makes ipc_table_init() program the RX-full mask in the wrong register block, so the NP->AP interrupt never fires and WiFi bring-up hangs waiting for the device to answer. Point IPCAP_DEV at the correct 0x40815000 base. - ameba_board.mk: the EVB silicon is B-cut, so link against the ameba_rom_symbol_bcut*.ld ROM symbol tables (the A-cut tables resolve the WiFi ROM helpers to the wrong addresses and fault at run time). Validated on hardware: NSH comes up, wapi scan lists real APs, a WPA2 connect succeeds, the DHCP client obtains a lease and ICMP to the public internet round-trips. The board defconfig keeps SSID/passphrase as placeholders; real credentials are supplied at run time via the wapi commands. Signed-off-by: dechao_gong --- arch/arm/src/rtl8721f/Kconfig | 2 +- arch/arm/src/rtl8721f/ameba_board.mk | 20 ++++++--- arch/arm/src/rtl8721f/ameba_ipc.c | 10 +++-- .../rtl8721f_evb/configs/nsh/defconfig | 42 +++++++++++++++++++ 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/arch/arm/src/rtl8721f/Kconfig b/arch/arm/src/rtl8721f/Kconfig index 63c6e5659f2..1afb0898885 100644 --- a/arch/arm/src/rtl8721f/Kconfig +++ b/arch/arm/src/rtl8721f/Kconfig @@ -71,7 +71,7 @@ config RTL8721F_FLASH_FS select MTD_BYTE_WRITE select FS_LITTLEFS ---help--- - Expose the SDK "VFS1" data partition (the last 128 KiB of the + Expose the SDK "VFS1" data partition (a dedicated region of the on-chip SPI NOR flash, which does not overlap the NP/AP firmware images) as a NuttX MTD device and mount a littlefs filesystem on it at /data. This provides persistent storage for application data and diff --git a/arch/arm/src/rtl8721f/ameba_board.mk b/arch/arm/src/rtl8721f/ameba_board.mk index 3b60aaef5cc..c29d51e1a1e 100644 --- a/arch/arm/src/rtl8721f/ameba_board.mk +++ b/arch/arm/src/rtl8721f/ameba_board.mk @@ -51,10 +51,10 @@ include $(TOPDIR)/arch/arm/src/armv8-m/Toolchain.defs # # ameba_layout.ld (included by ameba_img2_all.ld) # ameba_img2_all.ld -# ameba_rom_symbol_acut_s.ld (CONFIG_LINK_ROM_SYMB) +# ameba_rom_symbol_bcut_s.ld (CONFIG_LINK_ROM_SYMB; B-cut silicon) # # ameba_img2_all.ld is C-preprocessed (it #includes ameba_layout.ld and the -# generated platform_autoconf.h), then ameba_rom_symbol_acut_s.ld is appended. +# generated platform_autoconf.h), then ameba_rom_symbol_bcut_s.ld is appended. # Finally NuttX's own .vectors orphan section is folded into the loadable SRAM # data region so the (large power-of-two aligned) vector table does not land in # and overflow the tiny fixed KM4_IMG2_ENTRY region. This reproduces the @@ -73,16 +73,24 @@ AMEBA_PROJ = $(AMEBA_SOC)/project AMEBA_KM4_LD = $(AMEBA_PROJ)/project_km4tz/ld AMEBA_LAYOUT_LD = $(AMEBA_PROJ)/ameba_layout.ld AMEBA_IMG2_LD = $(AMEBA_KM4_LD)/ameba_img2_all.ld -AMEBA_ROM_LD = $(AMEBA_KM4_LD)/ameba_rom_symbol_acut_s.ld +# The EVB silicon is a B-cut part (the SDK autoconf sets +# CONFIG_AMEBAGREEN2_B_CUT=y and the NP/km4ns image is linked against the +# bcut ROM maps), so the AP image must use the *bcut* ROM symbol tables too. +# The two cuts have a different ROM layout: e.g. rtw_init_listhead is at +# 0x13796d on A-cut but 0x137df9 on B-cut. Linking the AP against acut +# addresses on this B-cut chip jumps WiFi ROM calls into the wrong ROM code +# and faults (the base-ROM funcs used by early bring-up happen to match +# across cuts, which is why this only surfaced once WiFi ROM was exercised). +AMEBA_ROM_LD = $(AMEBA_KM4_LD)/ameba_rom_symbol_bcut_s.ld # Green2's image2 link appends the non-secure base, WiFi and OS ROM symbol maps # on top of the secure one (RTL8720F pulled these from lib_rom.a, which # amebagreen2 does not ship). All entries are PROVIDE() (weak), so the secure # map keeps priority for any overlapping symbol and these only supply what it # lacks -- the WiFi ROM funcs (rtw_*/wifi_rom_*) and the non-secure ROM BSS # bounds (__rom_bss_*_ns__), etc. -AMEBA_ROM_LD_NS = $(AMEBA_KM4_LD)/ameba_rom_symbol_acut.ld -AMEBA_ROM_LD_WIFI = $(AMEBA_KM4_LD)/ameba_rom_symbol_acut_wifi.ld -AMEBA_ROM_LD_OS = $(AMEBA_KM4_LD)/ameba_rom_symbol_acut_os.ld +AMEBA_ROM_LD_NS = $(AMEBA_KM4_LD)/ameba_rom_symbol_bcut.ld +AMEBA_ROM_LD_WIFI = $(AMEBA_KM4_LD)/ameba_rom_symbol_bcut_wifi.ld +AMEBA_ROM_LD_OS = $(AMEBA_KM4_LD)/ameba_rom_symbol_bcut_os.ld AMEBA_PREBUILT = $(BOARD_DIR)$(DELIM)prebuilt AMEBA_PREBUILT_LIBS = $(AMEBA_PREBUILT)$(DELIM)libs diff --git a/arch/arm/src/rtl8721f/ameba_ipc.c b/arch/arm/src/rtl8721f/ameba_ipc.c index a3cc7a63306..be63696d428 100644 --- a/arch/arm/src/rtl8721f/ameba_ipc.c +++ b/arch/arm/src/rtl8721f/ameba_ipc.c @@ -68,13 +68,17 @@ /* AP (km4tz) IPC device register base = IPCAP_DEV / IPC0_REG_BASE, from the * SDK RTL8721F hal_platform.h. This matches the SDK km4tz main(), which - * calls ipc_table_init(IPCAP_DEV) with the NON-secure alias 0x40804000 - * (the secure alias 0x50804000 is NOT what the AP uses). + * calls ipc_table_init(IPCAP_DEV) with the NON-secure alias 0x40815000 + * (the secure alias 0x50815000 is NOT what the AP uses). NOTE: this base + * differs from the RTL8720F template (0x40804000); using the 8720F address + * here silently configures the wrong register block, so ipc_table_init() + * never unmasks the real IPC RX channels and the NP->AP interrupt never + * fires (WiFi bring-up then hangs waiting for the device to answer). * RTL8721F_IRQ_IPC_KM4 maps to APIRQn IPC_CPU0_IRQ (external vector 5) -- * see arch/.../irq.h. */ -#define IPCAP_DEV ((void *)0x40804000) +#define IPCAP_DEV ((void *)0x40815000) /**************************************************************************** * External Function Prototypes diff --git a/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig b/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig index 4477ec6ecbe..abfacc8a80e 100644 --- a/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig +++ b/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig @@ -20,19 +20,56 @@ CONFIG_DEBUG_FEATURES=y CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_SYMBOLS=y CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_DRIVERS_IEEE80211=y +CONFIG_DRIVERS_WIRELESS=y +CONFIG_EXAMPLES_DHCPD=y CONFIG_EXAMPLES_HELLO=y CONFIG_FS_PROCFS=y CONFIG_FS_TMPFS=y CONFIG_IDLETHREAD_STACKSIZE=4096 CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_IOB_BUFSIZE=512 +CONFIG_IOB_NBUFFERS=100 +CONFIG_IOB_NCHAINS=36 +CONFIG_IOB_THROTTLE=40 +CONFIG_LIBC_MEMFD_ERROR=y CONFIG_MM_DEFAULT_ALIGNMENT=32 +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 +CONFIG_NETUTILS_IPERF=y +CONFIG_NET_ARP_IPIN=y +CONFIG_NET_BROADCAST=y +CONFIG_NET_ETH_PKTSIZE=1514 +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_RECV_BUFSIZE=10000 +CONFIG_NET_SEND_BUFSIZE=16384 +CONFIG_NET_TCP=y +CONFIG_NET_TCP_DELAYED_ACK=y +CONFIG_NET_TCP_KEEPALIVE=y +CONFIG_NET_TCP_NOTIFIER=y +CONFIG_NET_TCP_OUT_OF_ORDER=y +CONFIG_NET_TCP_OUT_OF_ORDER_BUFSIZE=10000 +CONFIG_NET_TCP_WRITE_BUFFERS=y +CONFIG_NET_UDP=y CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_DISABLE_VCONFIG=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y CONFIG_PREALLOC_TIMERS=4 CONFIG_RAM_SIZE=401408 CONFIG_RAM_START=0x20006000 CONFIG_RR_INTERVAL=200 +CONFIG_RTL8721F_FLASH_FS=y +CONFIG_RTL8721F_WIFI=y CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_LPWORK=y @@ -41,8 +78,13 @@ CONFIG_STACK_COLORATION=y CONFIG_START_DAY=16 CONFIG_START_MONTH=6 CONFIG_START_YEAR=2026 +CONFIG_SYSTEM_DHCPC_RENEW=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_NSH_STACKSIZE=2500 +CONFIG_SYSTEM_PING=y CONFIG_TIMER=y CONFIG_TIMER_ARCH=y CONFIG_USEC_PER_TICK=1000 +CONFIG_WIRELESS=y +CONFIG_WIRELESS_WAPI=y +CONFIG_WIRELESS_WAPI_CMDTOOL=y