From 60722963895b01adabf59ee416124d8676212afe Mon Sep 17 00:00:00 2001 From: dechao_gong Date: Mon, 27 Jul 2026 13:35:53 +0800 Subject: [PATCH 1/4] arch/arm/rtl8721f: add RTL8721F (Green2) chip and EVB board skeleton Add a P0 skeleton port for the Realtek RTL8721F (SDK codename Green2 / amebagreen2). Structurally the RTL8721F is a twin of the RTL8720F -- the AP/host core is km4tz (ARMv8-M.main, TrustZone secure) and the WiFi MAC/PHY runs on the km4ns network-processor core -- so this port is modelled on the RTL8720F one and shares the IC-agnostic ameba glue in arch/arm/src/common/ameba. This is the "configures and links" skeleton (rtl8721f_evb:nsh builds an image end to end). Four differences from the RTL8720F template were needed to make the empty shell link against amebagreen2: * km4tz has no FPU (cmsis_cpu.h defines __FPU_PRESENT 0), so the chip does not select ARCH_HAVE_FPU and the image is built soft-float. * ameba_app_start.c matches amebagreen2's ram_km4tz silicon init: the nocache MPU map, the non-secure ROM BSS clear, OSC4M (not OSC2M) calibration gated on EFUSE cut >= B and CHIP_TYPE_ASIC_POSTSIM. * amebagreen2 ships no lib_rom.a, so the ROM archive whole-archive link is dropped; the WiFi/OS/non-secure ROM symbols come from the SDK ameba_rom_symbol_acut{,_wifi,_os}.ld maps appended to the image2 linker script, exactly as green2's own image2 link does. * the AP WiFi security lib is lib_wifi_common.a (was lib_wifi_com_sec.a). The per-chip IRQ vector table (irq.h) and the RAM_START/RAM_SIZE layout still carry RTL8720F values and are refined in the follow-up bring-up work. Signed-off-by: dechao_gong Co-Authored-By: Claude Opus 4.8 --- arch/arm/Kconfig | 16 + arch/arm/include/rtl8721f/chip.h | 53 +++ arch/arm/include/rtl8721f/irq.h | 147 ++++++ arch/arm/src/rtl8721f/CMakeLists.txt | 182 +++++++ arch/arm/src/rtl8721f/Kconfig | 85 ++++ arch/arm/src/rtl8721f/Make.defs | 217 +++++++++ arch/arm/src/rtl8721f/ameba_allocateheap.c | 141 ++++++ arch/arm/src/rtl8721f/ameba_app_start.c | 256 ++++++++++ arch/arm/src/rtl8721f/ameba_board.mk | 448 ++++++++++++++++++ arch/arm/src/rtl8721f/ameba_ipc.c | 150 ++++++ arch/arm/src/rtl8721f/ameba_ipc.h | 51 ++ arch/arm/src/rtl8721f/ameba_irq.c | 382 +++++++++++++++ arch/arm/src/rtl8721f/ameba_irq.h | 76 +++ arch/arm/src/rtl8721f/ameba_loguart.c | 413 ++++++++++++++++ arch/arm/src/rtl8721f/ameba_start.c | 172 +++++++ arch/arm/src/rtl8721f/ameba_timerisr.c | 72 +++ arch/arm/src/rtl8721f/ameba_wifi_init.c | 122 +++++ arch/arm/src/rtl8721f/chip.h | 39 ++ .../src/rtl8721f/hardware/ameba_memorymap.h | 62 +++ boards/Kconfig | 12 + .../arm/rtl8721f/rtl8721f_evb/CMakeLists.txt | 28 ++ boards/arm/rtl8721f/rtl8721f_evb/Kconfig | 7 + .../arm/rtl8721f/rtl8721f_evb/ameba_sdk.conf | 10 + .../rtl8721f_evb/ameba_sdk_force.conf | 11 + .../rtl8721f_evb/configs/nsh/defconfig | 90 ++++ .../arm/rtl8721f/rtl8721f_evb/include/board.h | 66 +++ .../rtl8721f/rtl8721f_evb/prebuilt/.gitignore | 22 + .../rtl8721f/rtl8721f_evb/scripts/Make.defs | 33 ++ .../rtl8721f/rtl8721f_evb/src/CMakeLists.txt | 28 ++ boards/arm/rtl8721f/rtl8721f_evb/src/Makefile | 27 ++ .../rtl8721f/rtl8721f_evb/src/rtl8721f_boot.c | 69 +++ .../rtl8721f_evb/src/rtl8721f_bringup.c | 203 ++++++++ .../rtl8721f_evb/src/rtl8721f_rtl8721f_evb.h | 100 ++++ 33 files changed, 3790 insertions(+) create mode 100644 arch/arm/include/rtl8721f/chip.h create mode 100644 arch/arm/include/rtl8721f/irq.h create mode 100644 arch/arm/src/rtl8721f/CMakeLists.txt create mode 100644 arch/arm/src/rtl8721f/Kconfig create mode 100644 arch/arm/src/rtl8721f/Make.defs create mode 100644 arch/arm/src/rtl8721f/ameba_allocateheap.c create mode 100644 arch/arm/src/rtl8721f/ameba_app_start.c create mode 100644 arch/arm/src/rtl8721f/ameba_board.mk create mode 100644 arch/arm/src/rtl8721f/ameba_ipc.c create mode 100644 arch/arm/src/rtl8721f/ameba_ipc.h create mode 100644 arch/arm/src/rtl8721f/ameba_irq.c create mode 100644 arch/arm/src/rtl8721f/ameba_irq.h create mode 100644 arch/arm/src/rtl8721f/ameba_loguart.c create mode 100644 arch/arm/src/rtl8721f/ameba_start.c create mode 100644 arch/arm/src/rtl8721f/ameba_timerisr.c create mode 100644 arch/arm/src/rtl8721f/ameba_wifi_init.c create mode 100644 arch/arm/src/rtl8721f/chip.h create mode 100644 arch/arm/src/rtl8721f/hardware/ameba_memorymap.h create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/CMakeLists.txt create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/Kconfig create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk.conf create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk_force.conf create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/include/board.h create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/prebuilt/.gitignore create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/src/CMakeLists.txt create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/src/Makefile create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_boot.c create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_bringup.c create mode 100644 boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_rtl8721f_evb.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 15e449e52b73e..febb01301d86f 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -880,6 +880,18 @@ config ARCH_CHIP_RTL8720F runs on the km4ns network-processor core. Shares the IC-agnostic ameba glue in arch/arm/src/common/ameba. +config ARCH_CHIP_RTL8721F + bool "Realtek RTL8721F" + select ARCH_CORTEXM33 + select ARMV8M_HAVE_STACKCHECK + select OTHER_UART_SERIALDRIVER + ---help--- + Realtek RTL8721F (SDK codename Green2 / amebagreen2; km4tz + application/host core, ARMv8-M.main / Cortex-M33). Dual-core WHC + like the RTL8720F; the WiFi MAC/PHY runs on the km4ns + network-processor core. Shares the IC-agnostic ameba glue in + arch/arm/src/common/ameba. + config ARCH_CHIP_QEMU_ARM bool "QEMU virt platform (ARMv7a)" select ARCH_HAVE_POWEROFF @@ -1372,6 +1384,7 @@ config ARCH_CHIP default "mps" if ARCH_CHIP_MPS default "rtl8721dx" if ARCH_CHIP_RTL8721DX default "rtl8720f" if ARCH_CHIP_RTL8720F + default "rtl8721f" if ARCH_CHIP_RTL8721F default "goldfish" if ARCH_CHIP_GOLDFISH_ARM default "at32" if ARCH_CHIP_AT32 default "cxd32xx" if ARCH_CHIP_CXD32XX @@ -1947,6 +1960,9 @@ endif if ARCH_CHIP_RTL8720F source "arch/arm/src/rtl8720f/Kconfig" endif +if ARCH_CHIP_RTL8721F +source "arch/arm/src/rtl8721f/Kconfig" +endif if ARCH_CHIP_GOLDFISH_ARM source "arch/arm/src/goldfish/Kconfig" endif diff --git a/arch/arm/include/rtl8721f/chip.h b/arch/arm/include/rtl8721f/chip.h new file mode 100644 index 0000000000000..37d9d9773d438 --- /dev/null +++ b/arch/arm/include/rtl8721f/chip.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * arch/arm/include/rtl8721f/chip.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_INCLUDE_RTL8721F_CHIP_H +#define __ARCH_ARM_INCLUDE_RTL8721F_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Prototypes + ****************************************************************************/ + +#define NVIC_SYSH_PRIORITY_MIN 0xf0 /* Bits [7:5] set in minimum priority */ +#define NVIC_SYSH_PRIORITY_DEFAULT 0x80 /* Midpoint is the default */ +#define NVIC_SYSH_PRIORITY_MAX 0x00 /* Zero is maximum priority */ +#define NVIC_SYSH_PRIORITY_STEP 0x10 /* Four bits of interrupt priority used */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +#endif /* __ARCH_ARM_INCLUDE_RTL8721F_CHIP_H */ diff --git a/arch/arm/include/rtl8721f/irq.h b/arch/arm/include/rtl8721f/irq.h new file mode 100644 index 0000000000000..5210d2529a7ca --- /dev/null +++ b/arch/arm/include/rtl8721f/irq.h @@ -0,0 +1,147 @@ +/**************************************************************************** + * arch/arm/include/rtl8721f/irq.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/* This file should never be included directly but, rather, only indirectly + * through nuttx/irq.h + */ + +#ifndef __ARCH_ARM_INCLUDE_RTL8721F_IRQ_H +#define __ARCH_ARM_INCLUDE_RTL8721F_IRQ_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Processor Exceptions (vectors 0-15) */ + +#define RTL8721F_IRQ_RESERVED (0) /* Reserved vector (only used with + * CONFIG_DEBUG_FEATURES) */ + /* Vector 1: Reset (not handler) */ +#define RTL8721F_IRQ_NMI (2) /* Vector 2: Non-Maskable Interrupt */ +#define RTL8721F_IRQ_HARDFAULT (3) /* Vector 3: Hard fault */ +#define RTL8721F_IRQ_MEMFAULT (4) /* Vector 4: Memory management (MPU) */ +#define RTL8721F_IRQ_BUSFAULT (5) /* Vector 5: Bus fault */ +#define RTL8721F_IRQ_USAGEFAULT (6) /* Vector 6: Usage fault */ +#define RTL8721F_IRQ_SECUREFAULT (7) /* Vector 7: Secure fault */ +#define RTL8721F_IRQ_SVCALL (11) /* Vector 11: SVC call */ +#define RTL8721F_IRQ_DBGMONITOR (12) /* Vector 12: Debug Monitor */ +#define RTL8721F_IRQ_PENDSV (14) /* Vector 14: Pendable system service */ +#define RTL8721F_IRQ_SYSTICK (15) /* Vector 15: System tick */ +#define RTL8721F_IRQ_FIRST (16) /* Vector number of the first external + * interrupt */ + +/* External interrupts (vectors >= 16). These map to the RTL8721F km4tz + * (AP / host) peripheral interrupt vector numbers (APIRQn, 0..57) as defined + * by the SDK's component/soc/RTL8721F/fwlib/include/ameba_vector_table.h + * (CONFIG_ARM_CORE_CM4_KM4TZ branch). + */ + +#define RTL8721F_IRQ_WIFI_FISR_FESR (RTL8721F_IRQ_FIRST + 0) +#define RTL8721F_IRQ_WL_PROTOCOL (RTL8721F_IRQ_FIRST + 1) +#define RTL8721F_IRQ_AP_WAKE (RTL8721F_IRQ_FIRST + 2) +#define RTL8721F_IRQ_IPC_KM4 (RTL8721F_IRQ_FIRST + 3) /* IPC_KM4TZ */ +#define RTL8721F_IRQ_IWDG (RTL8721F_IRQ_FIRST + 4) +#define RTL8721F_IRQ_TIMER0 (RTL8721F_IRQ_FIRST + 5) +#define RTL8721F_IRQ_TIMER1 (RTL8721F_IRQ_FIRST + 6) +#define RTL8721F_IRQ_TIMER2 (RTL8721F_IRQ_FIRST + 7) +#define RTL8721F_IRQ_TIMER3 (RTL8721F_IRQ_FIRST + 8) +#define RTL8721F_IRQ_TIMER4 (RTL8721F_IRQ_FIRST + 9) +#define RTL8721F_IRQ_TIMER5 (RTL8721F_IRQ_FIRST + 10) +#define RTL8721F_IRQ_TIMER6 (RTL8721F_IRQ_FIRST + 11) +#define RTL8721F_IRQ_PMC_TIMER0 (RTL8721F_IRQ_FIRST + 12) +#define RTL8721F_IRQ_PMC_TIMER1 (RTL8721F_IRQ_FIRST + 13) +#define RTL8721F_IRQ_UART0 (RTL8721F_IRQ_FIRST + 14) +#define RTL8721F_IRQ_UART1 (RTL8721F_IRQ_FIRST + 15) +#define RTL8721F_IRQ_UART2 (RTL8721F_IRQ_FIRST + 16) +#define RTL8721F_IRQ_UART_LOG (RTL8721F_IRQ_FIRST + 17) +#define RTL8721F_IRQ_GPIOA (RTL8721F_IRQ_FIRST + 18) +#define RTL8721F_IRQ_RSVD (RTL8721F_IRQ_FIRST + 19) +#define RTL8721F_IRQ_I2C0 (RTL8721F_IRQ_FIRST + 20) +#define RTL8721F_IRQ_I2C1 (RTL8721F_IRQ_FIRST + 21) +#define RTL8721F_IRQ_GDMA0_CH0 (RTL8721F_IRQ_FIRST + 22) +#define RTL8721F_IRQ_GDMA0_CH1 (RTL8721F_IRQ_FIRST + 23) +#define RTL8721F_IRQ_GDMA0_CH2 (RTL8721F_IRQ_FIRST + 24) +#define RTL8721F_IRQ_GDMA0_CH3 (RTL8721F_IRQ_FIRST + 25) +#define RTL8721F_IRQ_GDMA0_CH4 (RTL8721F_IRQ_FIRST + 26) +#define RTL8721F_IRQ_GDMA0_CH5 (RTL8721F_IRQ_FIRST + 27) +#define RTL8721F_IRQ_GDMA0_CH6 (RTL8721F_IRQ_FIRST + 28) +#define RTL8721F_IRQ_GDMA0_CH7 (RTL8721F_IRQ_FIRST + 29) +#define RTL8721F_IRQ_SPI0 (RTL8721F_IRQ_FIRST + 30) +#define RTL8721F_IRQ_SPI1 (RTL8721F_IRQ_FIRST + 31) +#define RTL8721F_IRQ_SPORT (RTL8721F_IRQ_FIRST + 32) +#define RTL8721F_IRQ_RTC (RTL8721F_IRQ_FIRST + 33) +#define RTL8721F_IRQ_ADC (RTL8721F_IRQ_FIRST + 34) +#define RTL8721F_IRQ_BOR (RTL8721F_IRQ_FIRST + 35) +#define RTL8721F_IRQ_PWR_DOWN (RTL8721F_IRQ_FIRST + 36) +#define RTL8721F_IRQ_PKE (RTL8721F_IRQ_FIRST + 37) +#define RTL8721F_IRQ_TRNG (RTL8721F_IRQ_FIRST + 38) +#define RTL8721F_IRQ_AON_TIM (RTL8721F_IRQ_FIRST + 39) +#define RTL8721F_IRQ_AON_WAKEPIN (RTL8721F_IRQ_FIRST + 40) +#define RTL8721F_IRQ_SDIO_WIFI (RTL8721F_IRQ_FIRST + 41) +#define RTL8721F_IRQ_SDIO_BT (RTL8721F_IRQ_FIRST + 42) +#define RTL8721F_IRQ_RXI300 (RTL8721F_IRQ_FIRST + 43) +#define RTL8721F_IRQ_PSRAMC (RTL8721F_IRQ_FIRST + 44) +#define RTL8721F_IRQ_SPI_FLASH (RTL8721F_IRQ_FIRST + 45) +#define RTL8721F_IRQ_RSIP (RTL8721F_IRQ_FIRST + 46) +#define RTL8721F_IRQ_AES (RTL8721F_IRQ_FIRST + 47) +#define RTL8721F_IRQ_SHA (RTL8721F_IRQ_FIRST + 48) +#define RTL8721F_IRQ_AES_S (RTL8721F_IRQ_FIRST + 49) +#define RTL8721F_IRQ_SHA_S (RTL8721F_IRQ_FIRST + 50) +#define RTL8721F_IRQ_KM4NS_WDG_RST (RTL8721F_IRQ_FIRST + 51) +#define RTL8721F_IRQ_KM4TZ_NS_WDG (RTL8721F_IRQ_FIRST + 52) +#define RTL8721F_IRQ_KM4TZ_S_WDG (RTL8721F_IRQ_FIRST + 53) +#define RTL8721F_IRQ_OCP (RTL8721F_IRQ_FIRST + 54) +#define RTL8721F_IRQ_BT_CTRL_HIGH (RTL8721F_IRQ_FIRST + 55) +#define RTL8721F_IRQ_BT_CTRL_LOW (RTL8721F_IRQ_FIRST + 56) +#define RTL8721F_IRQ_IR (RTL8721F_IRQ_FIRST + 57) + +#define RTL8721F_IRQ_NEXTINT (58) /* Number of external interrupts + * (APIRQn PERI_IRQ_MAX) */ + +#define NR_IRQS (RTL8721F_IRQ_FIRST + RTL8721F_IRQ_NEXTINT) + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif +#endif + +#endif /* __ARCH_ARM_INCLUDE_RTL8721F_IRQ_H */ diff --git a/arch/arm/src/rtl8721f/CMakeLists.txt b/arch/arm/src/rtl8721f/CMakeLists.txt new file mode 100644 index 0000000000000..2f1720c229abe --- /dev/null +++ b/arch/arm/src/rtl8721f/CMakeLists.txt @@ -0,0 +1,182 @@ +# ############################################################################## +# arch/arm/src/rtl8721f/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +# IC-specific register drivers + IPC wiring live here; IC-agnostic glue is +# shared from arch/arm/src/common/ameba. +set(SRCS ameba_allocateheap.c ameba_irq.c ameba_loguart.c ameba_start.c + ameba_timerisr.c) + +set(AMEBA_COMMON ${CMAKE_CURRENT_LIST_DIR}/../common/ameba) + +list(APPEND SRCS ${AMEBA_COMMON}/ameba_os_wrap.c) + +# km4tz<->km4ns IPC bring-up: needed by the SDK flash erase/program path +# (inter-core XIP pause) AND by WiFi, so compile it whenever either is enabled. +if(CONFIG_RTL8721F_WIFI OR CONFIG_RTL8721F_FLASH_FS) + list(APPEND SRCS ameba_ipc.c) +endif() + +if(CONFIG_RTL8721F_WIFI) + list(APPEND SRCS ameba_wifi_init.c ${AMEBA_COMMON}/ameba_kv.c) + if(CONFIG_NET) + list(APPEND SRCS ${AMEBA_COMMON}/ameba_wlan.c) + endif() +endif() + +if(CONFIG_RTL8721F_FLASH_FS) + list(APPEND SRCS ${AMEBA_COMMON}/ameba_flash_mtd.c) +endif() + +target_include_directories(arch PRIVATE ${AMEBA_COMMON}) +target_sources(arch PRIVATE ${SRCS}) + +# ############################################################################## +# Vendor-SDK build machinery (shared mechanism in common/ameba/cmake). This +# IC's differing inputs are set here (RTL8721F: km4tz AP core, km4ns NP core). +# ############################################################################## + +set(AMEBA_SOC_NAME amebagreen2) +set(AMEBA_PY_SOC RTL8721F) +set(AMEBA_AP_PROJECT km4tz) +set(AMEBA_KM_PROJ project_km4tz) +set(AMEBA_NP_TARGET km4ns) +set(AMEBA_CFG_WIFI ${CONFIG_RTL8721F_WIFI}) +set(AMEBA_CFG_FLASHFS ${CONFIG_RTL8721F_FLASH_FS}) + +# Resolve AMEBA_SDK / asdk toolchain (provisioned by `. tools/ameba/env.sh`) +# before the SDK-relative source lists below reference it. +include(${AMEBA_COMMON}/cmake/ameba_sdk.cmake) + +set(AMEBA_SOC ${AMEBA_SDK}/component/soc/${AMEBA_SOC_NAME}) +set(AMEBA_PREBUILT ${NUTTX_BOARD_DIR}/prebuilt) +set(AMEBA_WIFI_DIR ${AMEBA_COMMON}/wifi) + +# fwlib register-layer sources compiled into libameba_fwlib.a, plus the +# NuttX-owned image2 entry (ameba_app_start.c, IC-specific). +set(AMEBA_FWLIB_SRCS + ${AMEBA_SOC}/fwlib/ram_common/ameba_arch.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_loguart.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_ipc_api.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_ipc_ram.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_clk.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_pmctimer.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_pmu.c + ${CMAKE_CURRENT_LIST_DIR}/ameba_app_start.c + ${AMEBA_SOC}/fwlib/ram_common/ameba_mpu_ram.c + ${AMEBA_SOC}/fwlib/ram_km4tz/ameba_data_flashclk.c + ${AMEBA_SOC}/fwlib/ram_km4tz/ameba_flashclk.c + ${AMEBA_SOC}/fwlib/ram_km4tz/ameba_pinmap.c + ${AMEBA_SDK}/component/soc/usrcfg/${AMEBA_SOC_NAME}/ameba_flashcfg.c + ${AMEBA_SDK}/component/soc/usrcfg/${AMEBA_SOC_NAME}/ameba_pinmapcfg.c) + +if(CONFIG_RTL8721F_FLASH_FS) + list(APPEND AMEBA_FWLIB_SRCS ${AMEBA_SOC}/fwlib/ram_common/ameba_flash_ram.c) +endif() + +# Silence a couple of warnings the vendored SDK sources trip under NuttX's +# warning set, scoped to this fwlib compile only (never relaxing NuttX's own): +# -Wno-int-conversion: the SDK passes NULL to irq_register()'s u32 "Data" +# (interrupt context) argument in many places -- an intentional idiom. +# -Wno-shadow: SDK swlib/log.c shadows a file-scope global with a parameter. +set(AMEBA_FWLIB_INC + -Wno-int-conversion + -Wno-shadow + -I${AMEBA_COMMON}/sdk_shim + -I${AMEBA_SOC}/fwlib/include + -I${AMEBA_SOC}/fwlib/include/rom + -I${AMEBA_SOC}/swlib + -I${AMEBA_SOC}/hal/include + -I${AMEBA_SOC}/hal/src + -I${AMEBA_SDK}/component/soc/common/include + -I${AMEBA_SDK}/component/soc/common/include/cmsis + -I${AMEBA_SOC}/app/monitor/include + -I${AMEBA_SDK}/component/soc/usrcfg/${AMEBA_SOC_NAME}/include + -I${AMEBA_SDK}/component/soc/usrcfg/common + -I${AMEBA_SOC}/misc + -I${AMEBA_SDK}/component/os/os_wrapper/include + -I${AMEBA_SDK}/component/ssl/mbedtls-3.6.5/include + -I${AMEBA_SDK}/component/soc/common/crashdump/include + -I${AMEBA_PREBUILT}) + +# Host WiFi glue -> libameba_wifi.a (identical source/include set to the other +# Ameba ICs; shim include first, SDK autoconf force-included). +set(AMEBA_WIFI_SRCS + ${AMEBA_SDK}/component/soc/usrcfg/${AMEBA_SOC_NAME}/ameba_wificfg.c + ${AMEBA_SDK}/component/wifi/common/rtw_task_size.c + ${AMEBA_SDK}/component/wifi/common/rtw_event.c + ${AMEBA_SDK}/component/soc/common/diagnose/ameba_diagnose_none.c + ${AMEBA_SDK}/component/wifi/wpa_supplicant/wpa_supplicant/wifi_p2p_disable.c + ${AMEBA_WIFI_DIR}/ameba_wifi_depend.c + ${AMEBA_WIFI_DIR}/ameba_wifi.c) + +set(AMEBA_WIFI_INC + -include + ${AMEBA_PREBUILT}/platform_autoconf.h + -include + ${AMEBA_WIFI_DIR}/include/ameba_lwip_off.h + -I${AMEBA_WIFI_DIR}/include + -I${AMEBA_WIFI_DIR}/.. + -I${AMEBA_SDK}/component/wifi/api + -I${AMEBA_SDK}/component/wifi/common + -I${AMEBA_SDK}/component/wifi/driver/include + -I${AMEBA_SDK}/component/wifi/driver/intf + -I${AMEBA_SDK}/component/wifi/whc + -I${AMEBA_SDK}/component/wifi/whc/whc_host_rtos + -I${AMEBA_SDK}/component/wifi/whc/whc_host_rtos/ipc + -I${AMEBA_SDK}/component/at_cmd + -I${AMEBA_SDK}/component/wifi/wpa_supplicant/wpa_supplicant + -I${AMEBA_SDK}/component/wifi/wpa_supplicant/wpa_lite + -I${AMEBA_SDK}/component/wifi/wpa_supplicant/wpa_lite/rom + -I${AMEBA_SDK}/component/wifi/wpa_supplicant/src + -I${AMEBA_SDK}/component/wifi/wpa_supplicant/src/utils + -I${AMEBA_SDK}/component/wifi/rtk_app/wifi_auto_reconnect + -I${AMEBA_SDK}/component/network + -I${AMEBA_SDK}/component/soc/common/diagnose + -I${AMEBA_SOC}/app/monitor/include + -I${AMEBA_SOC}/fwlib/include + -I${AMEBA_SOC}/fwlib/include/rom + -I${AMEBA_SOC}/swlib + -I${AMEBA_SOC}/hal/include + -I${AMEBA_SOC}/misc + -I${AMEBA_SDK}/component/soc/common/include + -I${AMEBA_SDK}/component/soc/common/include/cmsis + -I${AMEBA_SDK}/component/os/os_wrapper/include + -I${AMEBA_SDK}/component/soc/usrcfg/${AMEBA_SOC_NAME}/include + -I${AMEBA_SDK}/component/soc/usrcfg/common + -I${AMEBA_SDK}/component/ssl/mbedtls-3.6.5/include + -I${AMEBA_PREBUILT}) + +# KM4TZ-side host WiFi control libs. Unlike RTL8721Dx, lib_coex.a is NP-side +# (km4ns) on RTL8721F and is NOT linked into the AP image. +set(_ameba_app_lib ${AMEBA_SOC}/project/${AMEBA_KM_PROJ}/lib/application) +set(AMEBA_WIFI_APP_LIBS + ${_ameba_app_lib}/lib_wifi_whc_ap.a ${_ameba_app_lib}/lib_wifi_rtk_app.a + ${_ameba_app_lib}/lib_wifi_common.a ${_ameba_app_lib}/lib_wpa_lite.a) + +# NOTE (RTL8721F/Green2 vs RTL8720F): amebagreen2 ships no lib_rom.a / +# lib_rom_tz.a in project_km4tz/lib/soc, so there is no ROM archive to +# whole-archive. ROM symbol addresses come solely from the +# ameba_rom_symbol_*.ld appended to the generated ld script (the amebadplus +# model). +set(AMEBA_EXTRA_LINK_OPTIONS) + +include(${AMEBA_COMMON}/cmake/ameba_board.cmake) diff --git a/arch/arm/src/rtl8721f/Kconfig b/arch/arm/src/rtl8721f/Kconfig new file mode 100644 index 0000000000000..63c6e5659f25b --- /dev/null +++ b/arch/arm/src/rtl8721f/Kconfig @@ -0,0 +1,85 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_CHIP_RTL8721F + +menu "RTL8721F Chip Selection" + +config RTL8721F_KM4 + bool + default y + ---help--- + The Realtek RTL8721F KM4 application core + (ARMv8-M.main / Cortex-M33). + +endmenu # RTL8721F Chip Selection + +menu "RTL8721F Bring-up Options" + +config RTL8721F_HEAP_SIZE + hex "NuttX reserved heap size (bytes)" + default 0x10000 + ---help--- + During bring-up NuttX runs as a guest on the Realtek SDK image and + must not touch RAM that the SDK owns. Instead of claiming all SRAM + from the end of NuttX's BSS to the end of memory (which overlaps the + SDK heap), NuttX uses a self-contained, statically reserved heap of + this size placed in NuttX's own .bss. up_allocate_heap() returns + this buffer. Keep it within the 288KB KM4 SRAM budget after NuttX + text/data/bss. + +config RTL8721F_LOGUART_RXBUFSIZE + int "LOG-UART console RX buffer size" + default 256 + ---help--- + Size of the NuttX receive buffer for the LOG-UART console. + +config RTL8721F_LOGUART_TXBUFSIZE + int "LOG-UART console TX buffer size" + default 256 + ---help--- + Size of the NuttX transmit buffer for the LOG-UART console. + +endmenu # RTL8721F Bring-up Options + +menu "RTL8721F WiFi" + +config RTL8721F_WIFI + bool "WiFi (WHC host) support" + default n + ---help--- + Link the Realtek WHC (WiFi Host Controller) host stack so the AP can + drive the WiFi MAC/PHY that runs on the NP network processor. The + AP-side host WiFi control libraries (lib_wifi_whc_ap and friends) + are linked from the pinned SDK; the lwIP / event glue they expect is + provided by NuttX (arch/arm/src/common/ameba/wifi/), routing frames + into NuttX's native network stack instead of lwIP. + + M3.1 brings up the control plane only (wifi_on + scan); the data + path and netdev/wireless-extension wiring follow. + +endmenu # RTL8721F WiFi + +menu "RTL8721F Storage" + +config RTL8721F_FLASH_FS + bool "On-chip SPI NOR data filesystem (littlefs)" + default n + select MTD + select MTD_BYTE_WRITE + select FS_LITTLEFS + ---help--- + Expose the SDK "VFS1" data partition (the last 128 KiB 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 + backs the WiFi fast-connect / PMK key-value store (rt_kv_*). + + The MTD backend wraps the SDK's dual-core-locked FLASH_xxx flash + primitives (ameba_flash_mtd.c). + +endmenu # RTL8721F Storage + +endif # ARCH_CHIP_RTL8721F diff --git a/arch/arm/src/rtl8721f/Make.defs b/arch/arm/src/rtl8721f/Make.defs new file mode 100644 index 0000000000000..172fc7a6fb087 --- /dev/null +++ b/arch/arm/src/rtl8721f/Make.defs @@ -0,0 +1,217 @@ +############################################################################ +# arch/arm/src/rtl8721f/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include armv8-m/Make.defs + +# IC-agnostic Ameba glue (os_wrapper backend, netdev, KV, flash MTD, ...) is +# shared by every ameba ARM chip from arch/arm/src/common/ameba/. Put it on +# VPATH + the include path so the CHIP_CSRCS filenames below resolve there +# (single source, no per-IC duplication). Truly IC-specific files (register +# drivers, IPC wiring, chip.h) stay in this chip directory. + +AMEBA_COMMON_SRC = $(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba +VPATH += common$(DELIM)ameba +INCLUDES += ${INCDIR_PREFIX}$(AMEBA_COMMON_SRC) + +CHIP_CSRCS = ameba_start.c ameba_loguart.c ameba_irq.c ameba_timerisr.c +CHIP_CSRCS += ameba_allocateheap.c +CHIP_CSRCS += ameba_os_wrap.c + +# km4tz<->km4ns IPC bring-up. Needed by the SDK flash erase/program path +# (inter-core XIP pause) AND by WiFi, so compile it whenever either is enabled. +ifneq ($(CONFIG_RTL8721F_WIFI)$(CONFIG_RTL8721F_FLASH_FS),) +CHIP_CSRCS += ameba_ipc.c +endif + +ifeq ($(CONFIG_RTL8721F_WIFI),y) +CHIP_CSRCS += ameba_wifi_init.c +# rt_kv_* symbols are referenced by the WHC host WiFi libraries -- always +# provide them (backed by the data filesystem, or stubbed if it is disabled). +CHIP_CSRCS += ameba_kv.c +ifeq ($(CONFIG_NET),y) +CHIP_CSRCS += ameba_wlan.c +endif +endif + +ifeq ($(CONFIG_RTL8721F_FLASH_FS),y) +CHIP_CSRCS += ameba_flash_mtd.c +endif + +############################################################################ +# Realtek RTL8721F SDK integration +# +# Direction A (vendored-SDK model): NuttX owns the AP image2 and is the +# *primary* linker. The reduced image2 link reuses the vendor SDK chip +# libraries + ROM symbols + linker scripts; FreeRTOS / lwIP / mbedTLS / +# WiFi / BT / file-system / at_cmd / ota are all dropped (NuttX provides its +# own). This folds the prototype scripts (nuttx-ameba-ext/link_img2.sh and +# package_app.sh) into NuttX's native build: the linked `nuttx` ELF *is* the +# AP (km4tz) image2 .axf, and POSTBUILD (board scripts/Make.defs) packages it +# into a flashable nuttx.bin. +# +# The vendor SDK (ameba-rtos) is treated as a referenced 3rd-party checkout: +# its sources, ROM symbol files and linker scripts are referenced at build time +# and never committed to NuttX. The pre-compiled chip archives + the build +# staging area are kept under boards/arm/rtl8721f/rtl8721f_evb/prebuilt/ +# (gitignored, not part of the NuttX source tree, as vendor blobs are kept +# out of NuttX). +############################################################################ + +# This IC (RTL8721F) maps to the SDK's RTL8721F SoC subtree. Set before +# including the shared locator so future chips can reuse the one SDK checkout +# by selecting their own AMEBA_SOC_NAME. + +# RTL8721F maps to the SDK's amebagreen2 (Green2) SoC subtree. +AMEBA_SOC_NAME = amebagreen2 + +# Locate (and, when unset, auto-fetch) the one shared ameba-rtos SDK. Shared +# with the board's scripts/Make.defs via common/ameba/ameba_sdk.mk so both make +# instances resolve $(AMEBA_SDK) identically. See that file for the two modes. + +include $(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba$(DELIM)ameba_sdk.mk + +# SDK sub-trees referenced by the image2 link. + +# NOTE (RTL8721F/Green2, like RTL8720F): the AP/host core is km4tz (TrustZone +# secure), vs km4 on amebadplus. So the application-core project subtree is +# project_km4tz (NP/device core is km4ns, the prebuilt-blob core -- analogous +# to amebadplus's km0). +AMEBA_SOC = $(AMEBA_SDK)/component/soc/$(AMEBA_SOC_NAME) +AMEBA_PROJ = $(AMEBA_SOC)/project +AMEBA_KM4_PROJ = $(AMEBA_PROJ)/project_km4tz +AMEBA_SOC_LIB = $(AMEBA_KM4_PROJ)/lib/soc + +# Vendored prebuilt area inside the board (gitignored vendor blobs). + +AMEBA_PREBUILT = $(BOARD_DIR)$(DELIM)prebuilt +AMEBA_PREBUILT_LIBS = $(AMEBA_PREBUILT)$(DELIM)libs + +# --- Pre-compiled chip libraries kept in the reduced image2 ---------------- +# +# Vendor chip archives produced by a full SDK build, vendored under +# prebuilt/libs/. The chipinfo / pmc soc archives ship pre-compiled inside the +# SDK source tree, so they are taken directly from $(AMEBA_SDK). These are +# normal archives (members pulled on demand) and are appended to EXTRA_LIBS so +# they sit inside NuttX's standard --start-group/--end-group, resolving against +# each other and the NuttX libs. Everything unreferenced is dropped by +# --gc-sections, so listing an archive only costs link time, not image size. +# +# NOTE: the mbed-style "hal" layer (serial_api/gpio_api/...) is intentionally +# NOT linked -- NuttX provides its own uart_ops/ioexpander drivers, so the SDK +# hal is dead weight here (it contributed 0 objects). NuttX drivers sit +# directly on the fwlib register layer instead. + +# fwlib register-layer objects NuttX actually uses are compiled FROM SDK SOURCE +# into libameba_fwlib.a by the board PREBUILD (see scripts/Make.defs: +# AMEBA_FWLIB_SRCS), not vendored as a prebuilt blob -- so a bare checkout that +# only auto-fetched the SDK source can still link. --gc-sections keeps only the +# referenced members. Add fwlib sources there as new drivers need them. +EXTRA_LIBS += $(AMEBA_PREBUILT_LIBS)$(DELIM)libameba_fwlib.a + +# chipinfo / pmc ship pre-compiled INSIDE the SDK source tree (lib/soc), so a +# fresh SDK clone already has them -- linked directly from $(AMEBA_SDK), no +# vendored blob needed. (0 members pulled today, but kept for chip-init use.) +EXTRA_LIBS += $(AMEBA_SOC_LIB)$(DELIM)lib_chipinfo.a +EXTRA_LIBS += $(AMEBA_SOC_LIB)$(DELIM)lib_pmc.a + +# --- WiFi (WHC host) chip libraries (CONFIG_RTL8721F_WIFI) ----------------- +# +# KM4-side host WiFi control libs from the pinned SDK. STA-PSK reduced set: +# the host controller (whc_ap), rtk_app helpers, security/crypto, the WPA-lite +# supplicant and coexistence -- eap/p2p/wps are NOT linked. The lwIP / event +# glue these expect is supplied by NuttX in libameba_wifi.a (built from a few +# SDK config sources + arch/.../wifi/ameba_wifi_depend.c by the board PREBUILD). +# Everything unreferenced is dropped by --gc-sections; all of these sit inside +# NuttX's --start-group so they resolve against each other and the NuttX libs. + +ifeq ($(CONFIG_RTL8721F_WIFI),y) +AMEBA_APP_LIB = $(AMEBA_KM4_PROJ)/lib/application +EXTRA_LIBS += $(AMEBA_APP_LIB)$(DELIM)lib_wifi_whc_ap.a +EXTRA_LIBS += $(AMEBA_APP_LIB)$(DELIM)lib_wifi_rtk_app.a +EXTRA_LIBS += $(AMEBA_APP_LIB)$(DELIM)lib_wifi_common.a +EXTRA_LIBS += $(AMEBA_APP_LIB)$(DELIM)lib_wpa_lite.a +# NOTE: unlike RTL8721Dx (where lib_coex.a is an AP-side lib), on RTL8721F the +# WiFi/BT coexistence lib lives on the NP (km4ns/lib/application/lib_coex.a) and +# is linked into the NP prebuilt image -- the AP (NuttX host) must NOT link it. +EXTRA_LIBS += $(AMEBA_PREBUILT_LIBS)$(DELIM)libameba_wifi.a +endif + +# crtbegin.o / crtend.o (asdk gcc runtime) and -lm / -lstdc++ from the SDK +# image2 link rule. crtbegin/crtend must be positional objects, so they are +# added via EXTRA_LIBS (which the link rule places inside the group, after the +# archives); the C++ / math libs are name-spec'd through EXTRA_LIBS too. + +CRT_DIR := $(dir $(shell $(CC) $(ARCHCPUFLAGS) -print-file-name=crtbegin.o)) + +EXTRA_LIBS += $(CRT_DIR)crtbegin.o +EXTRA_LIBS += $(CRT_DIR)crtend.o + +# --- Link flags reproducing link_img2.sh ----------------------------------- +# +# -u/-e app_start : force-pull the SDK's app_start object (runs silicon +# init then calls NuttX's main()); NuttX provides the +# Img2EntryFun0 entry descriptor pointing at it. +# --gc-sections : drop everything unreferenced (this is what removes +# FreeRTOS / lwIP / mbedTLS members of the chip libs). +# --defsym aliases : map NuttX's _sbss/_ebss/_sdata/_edata/_eronly onto +# the SDK linker-script symbols (the SDK ld owns the +# section layout). +# --no-enum-size-warning / --warn-common / --build-id=none / --cref: match the +# SDK link rule. + +LDFLAGS += -u app_start +LDFLAGS += -e app_start +LDFLAGS += --gc-sections + +# NOTE (RTL8721F/Green2 vs RTL8720F): amebagreen2 ships NO lib_rom.a / +# lib_rom_tz.a in project_km4tz/lib/soc (only chipinfo/pmc/crashdump/bootloader), +# so -- unlike RTL8720F -- there is no ROM archive to whole-archive here. ROM +# symbol addresses come solely from the ameba_rom_symbol_*.ld appended by the +# board's ameba_board.mk (the amebadplus model). +LDFLAGS += --no-enum-size-warning +LDFLAGS += --warn-common +LDFLAGS += --build-id=none +LDFLAGS += --cref +LDFLAGS += --defsym=_sbss=__bss_start__ +LDFLAGS += --defsym=_ebss=__bss_end__ +LDFLAGS += --defsym=_sdata=__sram_image2_start__ +LDFLAGS += --defsym=_edata=__sram_image2_start__ +LDFLAGS += --defsym=_eronly=__sram_image2_start__ + +# Emit a fresh map next to the ELF for verification (mirrors text.map). + +LDFLAGS += -Map=$(TOPDIR)$(DELIM)nuttx.map + +# -lm / -lstdc++ are name-spec libs: add them through LIBPATHS/EXTRA_LIBS so the +# linker pulls libstdc++ (C++ static-init support that crtbegin/crtend expect) +# and libm. They go last in the group via EXTRA_LIBS ordering above is fine +# because they are searched as archives. + +LDLIBS += -lm -lstdc++ + +# --- Auto-fetched SDK: intentionally NOT removed on distclean -------------- +# +# sdk.mk clones the pinned ameba-rtos into arch/arm/src/common/ameba/ameba-rtos +# (gitignored) when AMEBA_SDK is unset. It is a cache shared by all ameba ICs, +# NOT a build artifact, so it must SURVIVE `make distclean`: switching ICs does +# distclean + reconfigure + build, and re-cloning the multi-GB SDK every time is +# unacceptable. A pristine reset is a manual `rm -rf` of the checkout. diff --git a/arch/arm/src/rtl8721f/ameba_allocateheap.c b/arch/arm/src/rtl8721f/ameba_allocateheap.c new file mode 100644 index 0000000000000..0bb08a316f30e --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_allocateheap.c @@ -0,0 +1,141 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_allocateheap.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "arm_internal.h" +#include "chip.h" +#include "hardware/ameba_memorymap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Terminology. + * In the flat build (CONFIG_BUILD_FLAT=y), there is only a single heap + * accessed with the standard allocations (malloc/free). This heap is + * referred to as the user heap. Only the flat build with a single SRAM + * region is supported on the RTL8721F. + */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* NuttX heap = all remaining KM4 on-chip SRAM. + * + * The KM4 image2 linker script (ameba_img2_all.ld) lays out this region for + * us: __bdram_heap_buffer_start__ is the first byte after NuttX's .bss, and + * __bdram_heap_buffer_size__ is an ABSOLUTE symbol whose VALUE is the number + * of bytes from there to the end of the KM4 SRAM region + * (__km4_bd_ram_end__). Using these gives NuttX every SRAM byte the SDK did + * not reserve, instead of a fixed compile-time buffer, and tracks the + * chip/board RAM automatically. + * + * Boards with PSRAM can add it as a second region via arm_addregion() using + * __psram_heap_buffer_start__/__psram_heap_buffer_size__ (zero on + * PKE8721DAF, which has no PSRAM). + */ + +extern uint8_t __bdram_heap_buffer_start__[]; +extern uint8_t __bdram_heap_buffer_size__[]; /* ABS symbol: value == bytes */ + +#define NUTTX_HEAP_BASE ((void *)__bdram_heap_buffer_start__) +#define NUTTX_HEAP_SIZE ((size_t)((uintptr_t)__bdram_heap_buffer_size__)) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_allocate_heap + * + * Description: + * This function will be called to dynamically set aside the heap region. + * + * For the flat build, this returns the location and size of the single + * heap: all KM4 SRAM remaining after NuttX's .data/.bss, as computed by + * the SDK linker script. + * + ****************************************************************************/ + +void up_allocate_heap(void **heap_start, size_t *heap_size) +{ + *heap_start = NUTTX_HEAP_BASE; + *heap_size = NUTTX_HEAP_SIZE; + +#if defined(CONFIG_MM_KERNEL_HEAP) + *heap_size -= CONFIG_MM_KERNEL_HEAPSIZE; +#endif +} + +/**************************************************************************** + * Name: up_allocate_kheap + * + * Description: + * For the kernel build (CONFIG_BUILD_PROTECTED/KERNEL=y) with both kernel- + * and user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates + * the kernel-space heap. + * + ****************************************************************************/ + +#if defined(CONFIG_MM_KERNEL_HEAP) +void up_allocate_kheap(void **heap_start, size_t *heap_size) +{ + /* Carve the kernel heap off the top of the SRAM heap region. */ + + *heap_start = (void *)((uintptr_t)NUTTX_HEAP_BASE + + (NUTTX_HEAP_SIZE - CONFIG_MM_KERNEL_HEAPSIZE)); + *heap_size = CONFIG_MM_KERNEL_HEAPSIZE; +} +#endif + +/**************************************************************************** + * Name: arm_addregion + * + * Description: + * Memory may be added in non-contiguous chunks. Additional chunks are + * added by calling this function. + * + ****************************************************************************/ + +#if CONFIG_MM_REGIONS > 1 +void arm_addregion(void) +{ +} +#endif diff --git a/arch/arm/src/rtl8721f/ameba_app_start.c b/arch/arm/src/rtl8721f/ameba_app_start.c new file mode 100644 index 0000000000000..ed50e532a44a4 --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_app_start.c @@ -0,0 +1,256 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_app_start.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * NuttX-owned image2 entry for the RTL8721F km4tz application core. + * + * This is a NuttX adaptation of the Realtek SDK's app_start() + * (component/soc/RTL8721F/fwlib/ram_km4tz/ameba_app_start.c). It runs the + * same OS-independent silicon init the SDK boot performs -- enable cache, + * clear image2 BSS, set the log level, data-flash high-speed setup, OSC + * calibration, the system timer, pin-mux and MPU, then call NuttX's main(). + * The SDK FreeRTOS/newlib bring-up and its fault-backtrace patch are + * intentionally omitted; NuttX provides its own scheduler, libc and crash + * reporting. + * + * Owning this file (not patching the SDK ameba_app_start.c) keeps the + * vendor SDK pristine. It is compiled with the SDK fwlib include set (see + * the board AMEBA_FWLIB_SRCS), not the NuttX header set. The image2 entry + * uses a NULL ram_wakeup so the SDK deep-sleep (SOCPS) wake path is not + * pulled into the image. + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "ameba_soc.h" +#include "os_wrapper.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const char *TAG = "APP"; + +/**************************************************************************** + * External Function Prototypes + ****************************************************************************/ + +extern int main(void); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +u32 app_mpu_nocache_check(u32 mem_addr) +{ + mpu_region_config mpu_cfg; + + mpu_cfg.region_base = (uint32_t)__ram_nocache_start__; + mpu_cfg.region_size = __ram_nocache_end__ - __ram_nocache_start__; + + if ((mem_addr >= mpu_cfg.region_base) && + (mem_addr < (mpu_cfg.region_base + mpu_cfg.region_size))) + { + return TRUE; + } + else + { + return FALSE; + } +} + +/* AP has 8 secure mpu entries & 8 non-secure mpu entries. */ + +u32 app_mpu_nocache_init(void) +{ + mpu_region_config mpu_cfg; + u32 mpu_entry = 0; + + /* ROM code inside the CPU does not enter cache; set it RO so a NULL-ptr + * access faults. On Green2 the TCM cache window (0x000F0000..0x00100000) + * is used as RAM in fullmac mode and must not be read-only, so the RO + * region stops at 0x000F0000. + */ + + mpu_entry = mpu_entry_alloc(); + mpu_cfg.region_base = 0; + mpu_cfg.region_size = 0x000F0000; + mpu_cfg.xn = MPU_EXEC_ALLOW; + mpu_cfg.ap = MPU_UN_PRIV_RO; + mpu_cfg.sh = MPU_NON_SHAREABLE; + mpu_cfg.attr_idx = MPU_MEM_ATTR_IDX_NC; + mpu_region_cfg(mpu_entry, &mpu_cfg); + + /* nocache region */ + + mpu_entry = mpu_entry_alloc(); + mpu_cfg.region_base = (uint32_t)__ram_nocache_start__; + mpu_cfg.region_size = __ram_nocache_end__ - __ram_nocache_start__; + mpu_cfg.xn = MPU_EXEC_ALLOW; + mpu_cfg.ap = MPU_UN_PRIV_RW; + mpu_cfg.sh = MPU_NON_SHAREABLE; + mpu_cfg.attr_idx = MPU_MEM_ATTR_IDX_NC; + if (mpu_cfg.region_size >= 32) + { + mpu_region_cfg(mpu_entry, &mpu_cfg); + } + + return 0; +} + +#if defined(__GNUC__) +/* Provided for C++ support so the toolchain init does not fail to link. */ + +void _init(void) +{ +} +#endif + +void app_testmode_status(void) +{ + /* OTPC and SIC share one master port; OTPC uses it by default and SIC can + * use it once OTPC autoload is done. + */ + + if (SYSCFG_TRP_TestMode()) + { + if (SYSCFG_TRP_OTPBYP()) + { + RTK_LOGI(TAG, "Bypass OTP autoload\r\n"); + } + else + { + RTK_LOGI(TAG, "In Test mode: 0x%lx\r\n", SYSCFG_TRP_ICFG()); + } + } +} + +void app_init_debug_flag(void) +{ + /* Initialise the log level used by the ROM-code global variable. */ + + if (SYSCFG_OTP_DisBootLog() == FALSE) + { + rtk_log_level_set("*", RTK_LOG_INFO); + } + else + { + rtk_log_level_set("*", RTK_LOG_ERROR); + } +} + +void os_init(void) +{ +#ifdef CONFIG_PSRAM_ALL_FOR_AP_HEAP +#if (defined CONFIG_WHC_HOST || defined CONFIG_WHC_NONE) + extern bool os_heap_add(u8 *start_addr, size_t heap_size); + if (ChipInfo_PsramExists()) + { + os_heap_add((uint8_t *)__km4tz_bd_psram_start__, + (size_t)(__non_secure_psram_end__ - + __km4tz_bd_psram_start__)); + } + +#endif +#endif + rtos_mem_init(); +} + +/* The image2 application entry point. */ + +void app_start(void) +{ + /* Enable the non-secure cache. */ + + Cache_Enable(ENABLE); + + /* Clear the non-secure ROM BSS and the image2 BSS (the latter covers + * NuttX's .bss too). + */ + + _memset((void *)__rom_bss_start_ns__, 0, + (__rom_bss_end_ns__ - __rom_bss_start_ns__)); + _memset((void *)__bss_start__, 0, (__bss_end__ - __bss_start__)); + + RBSS_UDELAY_DIV = 5; + + app_init_debug_flag(); + +#ifdef CONFIG_TRUSTZONE + PutChar = (void (*)(char))LOGUART_PutChar; + SCB->VTOR = (u32)RomVectorTable; + RomVectorTable[0] = (HAL_VECTOR_FUN)MSP_RAM_HP_NS; +#endif + + app_testmode_status(); + + data_flash_highspeed_setup(); + + SystemCoreClockUpdate(); + RTK_LOGI(TAG, "AP CPU CLK: %lu Hz \n", SystemCoreClock); + + /* Heap region setup (a no-op under NuttX, which owns its own heap). */ + + os_init(); + XTAL_INIT(); + + if (EFUSE_GetChipVersion() >= SYSCFG_CUT_VERSION_B) + { + if (SYSCFG_CHIPType_Get() == CHIP_TYPE_ASIC_POSTSIM) + { + /* Only ASIC needs OSC calibration. */ + + OSC4M_Init(); + OSC4M_Calibration(30000); + } + } + + SYSTIMER_Init(); + + /* Low-power pins do not need pinmap init again after wake from dslp. */ + + pinmap_init(); + + mpu_init(); + app_mpu_nocache_init(); + + main(); +} + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Image2 entry descriptor: the SDK bootloader (image1) jumps to ram_start. + * A NULL ram_wakeup keeps the SDK deep-sleep (SOCPS) wake path -- which the + * SDK's own descriptor wires to SOCPS_WakeFromPG_AP -- out of the image. + */ + +IMAGE2_ENTRY_SECTION +RAM_START_FUNCTION Img2EntryFun0 = +{ + app_start, + NULL, + (u32)RomVectorTable +}; diff --git a/arch/arm/src/rtl8721f/ameba_board.mk b/arch/arm/src/rtl8721f/ameba_board.mk new file mode 100644 index 0000000000000..3bb9f3ab98a62 --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_board.mk @@ -0,0 +1,448 @@ +############################################################################ +# arch/arm/src/rtl8721f/ameba_board.mk +# +# Shared board-build definitions for the RTL8721F (Ameba WHC) -- the SDK +# include sets, fwlib/WiFi source lists, image2 linker-script generation, +# PREBUILD and POSTBUILD. A board's scripts/Make.defs is a thin wrapper that +# just `include`s this file, so every RTL8721F board shares one definition +# (and a second board on this IC needs no copy). Board-specific paths come +# from $(BOARD_DIR), so each board keeps its own prebuilt/ staging dir. +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk + +# Resolve (and, when AMEBA_SDK is unset, auto-fetch) the one shared ameba-rtos +# SDK, and prepend the SDK-matched asdk toolchain to PATH. This MUST precede +# Toolchain.defs: that file probes the compiler version to compute flags (e.g. +# --param=min-pagesize=0 on newer GCC), so the SDK toolchain has to be on PATH +# first or the flags get computed for the wrong compiler. AMEBA_SOC_NAME +# selects this IC's SoC subtree. + +AMEBA_SOC_NAME = amebagreen2 +include $(TOPDIR)/arch/arm/src/common/ameba/ameba_sdk.mk + +include $(TOPDIR)/arch/arm/src/armv8-m/Toolchain.defs + +############################################################################ +# Linker script +# +# The `nuttx` ELF must be linked as the Realtek KM4 image2 .axf, so the link +# uses the *SDK's own* layout + image2 + ROM-symbol linker scripts (exactly as +# the prototype link_img2.sh did): +# +# ameba_layout.ld (included by ameba_img2_all.ld) +# ameba_img2_all.ld +# ameba_rom_symbol_acut_s.ld (CONFIG_LINK_ROM_SYMB) +# +# 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. +# 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 +# generated rlx8721d.ld byte-for-byte without editing any SDK source file +# (the SDK tree stays read-only). +# +# The combined script is generated into scripts/ as ld.script and used as the +# single ARCHSCRIPT. ld.script content is already fully expanded (no macros, +# no #include), so the standard ARCHSCRIPT cpp .tmp pass is idempotent. +############################################################################ + +# SDK linker-script sources and the vendored, config-derived autoconf header. + +AMEBA_SOC = $(AMEBA_SDK)/component/soc/$(AMEBA_SOC_NAME) +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 +# 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_PREBUILT = $(BOARD_DIR)$(DELIM)prebuilt +AMEBA_PREBUILT_LIBS = $(AMEBA_PREBUILT)$(DELIM)libs +AMEBA_AUTOCONF = $(AMEBA_PREBUILT)$(DELIM)platform_autoconf.h + +# fwlib register-layer objects, compiled FROM SDK SOURCE into libameba_fwlib.a +# (linked via arch/.../rtl8721f/Make.defs EXTRA_LIBS) instead of vendoring a +# prebuilt blob -- so a bare checkout that only auto-fetched the SDK source can +# still link. Grow AMEBA_FWLIB_SRCS as NuttX drivers call more fwlib functions; +# --gc-sections keeps only what is referenced. AMEBA_FWLIB_INC is the SDK's +# fwlib include set, kept scoped to this compile so SDK headers never leak into +# the NuttX core build (where they would clash). + +AMEBA_FWLIB_A = $(AMEBA_PREBUILT_LIBS)$(DELIM)libameba_fwlib.a +# RTL8721F: ameba_pmu.c lives in fwlib/ram_common (not misc/), and DiagPrintf +# is a ROM symbol (provided by ameba_rom_symbol_acut_s.ld), so no swlib/log.c. +AMEBA_FWLIB_SRCS = $(AMEBA_SOC)/fwlib/ram_common/ameba_arch.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_loguart.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_ipc_api.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_ipc_ram.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_clk.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_pmctimer.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_pmu.c + +# NuttX owns the image2 entry: arch/arm/src/rtl8721f/ameba_app_start.c is a +# NuttX adaptation of the SDK app_start() that runs all OS-independent silicon +# init (cache/data-flash/pinmux/system-timer/MPU/...), zeroes BSS, then calls +# NuttX's main() (ameba_start.c). It is built with the SDK fwlib include set, +# so the fwlib sources it pulls in are listed alongside it. +AMEBA_FWLIB_SRCS += $(TOPDIR)/arch/arm/src/rtl8721f/ameba_app_start.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_mpu_ram.c \ + $(AMEBA_SOC)/fwlib/ram_km4tz/ameba_data_flashclk.c \ + $(AMEBA_SOC)/fwlib/ram_km4tz/ameba_flashclk.c \ + $(AMEBA_SOC)/fwlib/ram_km4tz/ameba_pinmap.c \ + $(AMEBA_SDK)/component/soc/usrcfg/$(AMEBA_SOC_NAME)/ameba_flashcfg.c \ + $(AMEBA_SDK)/component/soc/usrcfg/$(AMEBA_SOC_NAME)/ameba_pinmapcfg.c + +# Flash primitives (FLASH_ReadStream/WriteStream/EraseXIP) for the MTD data +# filesystem. These self-lock against the NP core (inter-core HW semaphore + +# IPC pause) and disable IRQs around erase/program. +ifeq ($(CONFIG_RTL8721F_FLASH_FS),y) +AMEBA_FWLIB_SRCS += $(AMEBA_SOC)/fwlib/ram_common/ameba_flash_ram.c +endif +# -Wno-int-conversion: the vendored SDK passes NULL to irq_register()'s u32 +# "Data" (interrupt context) argument in many places -- an intentional +# NULL-as-context idiom. Silence -Wint-conversion for the SDK fwlib sources +# here rather than editing every call site (which also re-breaks whenever a new +# SDK file/site is added). Scoped to this fwlib compile, so it never relaxes +# NuttX's own warning set. +AMEBA_FWLIB_INC = -Wno-int-conversion \ + -I$(TOPDIR)/arch/arm/src/common/ameba/sdk_shim \ + -I$(AMEBA_SOC)/fwlib/include \ + -I$(AMEBA_SOC)/fwlib/include/rom \ + -I$(AMEBA_SOC)/swlib \ + -I$(AMEBA_SOC)/hal/include \ + -I$(AMEBA_SOC)/hal/src \ + -I$(AMEBA_SDK)/component/soc/common/include \ + -I$(AMEBA_SDK)/component/soc/common/include/cmsis \ + -I$(AMEBA_SOC)/app/monitor/include \ + -I$(AMEBA_SDK)/component/soc/usrcfg/$(AMEBA_SOC_NAME)/include \ + -I$(AMEBA_SDK)/component/soc/usrcfg/common \ + -I$(AMEBA_SOC)/misc \ + -I$(AMEBA_SDK)/component/os/os_wrapper/include \ + -I$(AMEBA_SDK)/component/ssl/mbedtls-3.6.5/include \ + -I$(AMEBA_SDK)/component/soc/common/crashdump/include \ + -I$(AMEBA_PREBUILT) + +# --- WiFi (WHC host) glue lib (CONFIG_RTL8721F_WIFI) ---------------------- +# +# libameba_wifi.a holds the NuttX-side glue the precompiled host WiFi libs +# expect: a couple of SDK config sources (the user WiFi config + the task-size +# table, compiled from source so their struct layouts match the libs' ABI) and +# the NuttX lwIP/event shim (arch/.../wifi/ameba_wifi_depend.c). It is built +# with the vendor WiFi include set -- which collides with NuttX's own headers +# (lwIP vs NuttX atomic.h, ...) -- so it is compiled in its own PREBUILD loop +# (like libameba_fwlib.a), NOT through the normal arch CSRCS path. The shim +# include dir comes FIRST so its minimal shadows the SDK's. +AMEBA_WIFI_A = $(AMEBA_PREBUILT_LIBS)$(DELIM)libameba_wifi.a +AMEBA_WIFI_DIR = $(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba$(DELIM)wifi +AMEBA_WIFI_SRCS = $(AMEBA_SDK)/component/soc/usrcfg/$(AMEBA_SOC_NAME)/ameba_wificfg.c \ + $(AMEBA_SDK)/component/wifi/common/rtw_task_size.c \ + $(AMEBA_SDK)/component/wifi/common/rtw_event.c \ + $(AMEBA_SDK)/component/soc/common/diagnose/ameba_diagnose_none.c \ + $(AMEBA_SDK)/component/wifi/wpa_supplicant/wpa_supplicant/wifi_p2p_disable.c \ + $(AMEBA_WIFI_DIR)/ameba_wifi_depend.c \ + $(AMEBA_WIFI_DIR)/ameba_wifi.c +# +# Force-include the SDK autoconf so EVERY wifi source sees CONFIG_WHC_HOST / +# CONFIG_WHC_INTF_IPC / ... (the SDK build force-includes platform_autoconf.h +# globally). Without this, sources that don't #include it themselves silently +# compile the wrong #if branch -- e.g. rtw_task_size.c's wifi_set_task_size() +# becomes empty, leaving g_rtw_task_size all-zero, so the WHC host event tasks +# are created with stack size 0 and never run -> wifi_connect() blocks forever +# waiting for the join-status event. +AMEBA_WIFI_INC = -include $(AMEBA_AUTOCONF) \ + -include $(AMEBA_WIFI_DIR)/include/ameba_lwip_off.h \ + -I$(AMEBA_WIFI_DIR)/include \ + -I$(AMEBA_WIFI_DIR)/.. \ + -I$(AMEBA_SDK)/component/wifi/api \ + -I$(AMEBA_SDK)/component/wifi/common \ + -I$(AMEBA_SDK)/component/wifi/driver/include \ + -I$(AMEBA_SDK)/component/wifi/driver/intf \ + -I$(AMEBA_SDK)/component/wifi/whc \ + -I$(AMEBA_SDK)/component/wifi/whc/whc_host_rtos \ + -I$(AMEBA_SDK)/component/wifi/whc/whc_host_rtos/ipc \ + -I$(AMEBA_SDK)/component/at_cmd \ + -I$(AMEBA_SDK)/component/wifi/wpa_supplicant/wpa_supplicant \ + -I$(AMEBA_SDK)/component/wifi/wpa_supplicant/wpa_lite \ + -I$(AMEBA_SDK)/component/wifi/wpa_supplicant/wpa_lite/rom \ + -I$(AMEBA_SDK)/component/wifi/wpa_supplicant/src \ + -I$(AMEBA_SDK)/component/wifi/wpa_supplicant/src/utils \ + -I$(AMEBA_SDK)/component/wifi/rtk_app/wifi_auto_reconnect \ + -I$(AMEBA_SDK)/component/network \ + -I$(AMEBA_SDK)/component/soc/common/diagnose \ + -I$(AMEBA_SOC)/app/monitor/include \ + -I$(AMEBA_SOC)/fwlib/include \ + -I$(AMEBA_SOC)/fwlib/include/rom \ + -I$(AMEBA_SOC)/swlib \ + -I$(AMEBA_SOC)/hal/include \ + -I$(AMEBA_SOC)/misc \ + -I$(AMEBA_SDK)/component/soc/common/include \ + -I$(AMEBA_SDK)/component/soc/common/include/cmsis \ + -I$(AMEBA_SDK)/component/os/os_wrapper/include \ + -I$(AMEBA_SDK)/component/soc/usrcfg/$(AMEBA_SOC_NAME)/include \ + -I$(AMEBA_SDK)/component/soc/usrcfg/common \ + -I$(AMEBA_SDK)/component/ssl/mbedtls-3.6.5/include \ + -I$(AMEBA_PREBUILT) + +# The combined script is generated under prebuilt/ (gitignored) by PREBUILD +# (below) and used as the single ARCHSCRIPT. Its content is already fully +# expanded (no macros, no #include), so the standard ARCHSCRIPT cpp .tmp pass +# is idempotent. ARCHSCRIPT must name a plain file here (not a rule target): +# defining an explicit recipe in this globally-included Make.defs would hijack +# the default make goal, so the generation is done in PREBUILD instead. + +GENLDSCRIPT = $(AMEBA_PREBUILT)$(DELIM)ld.script.gen + +ARCHSCRIPT += $(GENLDSCRIPT) + +# NP/device image (km4ns) + bootloader. +# +# The NP image and boot are ALWAYS (re)built from the pinned SDK source on every +# NuttX build -- no "use a stale vendored blob" shortcut -- so the two cores can +# never drift out of alignment. The NP build runs AFTER the KM4TZ (NuttX) link +# because the SDK WiFi "noused" generator strips any host WiFi API the AP image +# does not reference (calling a stripped API later deadlocks the NP -- "Compile +# NP after AP!"). So it is a POSTBUILD step handed NuttX's own disassembly +# (target_img2.asm, produced earlier in POSTBUILD) as the AP image via +# AMEBA_AP_ASM. The NP target is km4ns (the 5th arg). +# +# AMEBA_PY_SOC is the ameba.py SoC identifier for this board (public name), +# distinct from AMEBA_SOC_NAME (the SDK soc/ subdir). +AMEBA_PY_SOC = RTL8721F +AMEBA_BUILD_NP_SH = $(AMEBA_COMMON_DIR)$(DELIM)tools$(DELIM)ameba_build_np.sh + +# platform_autoconf.h is regenerated from the SDK menuconfig on every build (see +# ameba_gen_autoconf.sh) -- the SDK Kconfig is the single source of truth for +# the flash layout (CONFIG_FLASH_VFS1_*) and feature switches (CONFIG_WHC_* ...). +# AMEBA_AP_PROJECT is the AP-core SDK project subdir (km4tz on RTL8721F). +AMEBA_AP_PROJECT = km4tz +AMEBA_GEN_AUTOCONF = $(AMEBA_COMMON_DIR)$(DELIM)tools$(DELIM)ameba_gen_autoconf.sh + +# Board overlay applied on top of the SDK default config (prj.conf-style, e.g. +# CONFIG_SHELL=n). Fed to the SDK-config materializer (ameba_sdk_config.sh) via +# the AMEBA_SDK_CONF env var, by both the PREBUILD autoconf gen and the NP build. +# Edit it with `make ameba_menuconfig` (native SDK menuconfig UI). +AMEBA_SDK_CONF = $(BOARD_DIR)$(DELIM)ameba_sdk.conf + +AMEBA_NP_PREBUILD = true +AMEBA_NP_POSTBUILD = AMEBA_SDK_CONF=$(AMEBA_SDK_CONF) \ + $(AMEBA_BUILD_NP_SH) $(AMEBA_SDK) $(AMEBA_PY_SOC) \ + $(AMEBA_PREBUILT) $(AMEBA_PKGDIR)$(DELIM)target_img2.asm \ + km4ns $(AMEBA_AP_PROJECT) + +# PREBUILD -- (re)generate the combined image2 linker script before the build. +# +# ameba_img2_all.ld is C-preprocessed (it #includes ameba_layout.ld and the +# vendored, config-derived platform_autoconf.h, staged as +# project_km4/platform_autoconf.h on the include path), then +# ameba_rom_symbol_acut_s.ld is appended, then NuttX's .vectors orphan is folded +# into the loadable SRAM data region. This reproduces the SDK-generated +# rlx8721d.ld without editing any SDK source file. + +define PREBUILD + $(Q) test -n "$(AMEBA_SDK)" || \ + { echo "ERROR: AMEBA_SDK is not set. Export it to your ameba-rtos checkout."; exit 1; } + $(Q) $(AMEBA_FETCH_TOOLCHAIN) $(AMEBA_SDK) $(AMEBA_TOOLCHAIN_DIR) $(AMEBA_SOC_NAME) + $(Q) $(AMEBA_SETUP_ENV) $(AMEBA_SDK) $(AMEBA_TOOLCHAIN_DIR) + $(Q) AMEBA_SDK_CONF=$(AMEBA_SDK_CONF) \ + $(AMEBA_GEN_AUTOCONF) $(AMEBA_SDK) $(AMEBA_PY_SOC) $(AMEBA_AP_PROJECT) \ + $(AMEBA_AUTOCONF) + $(Q) $(AMEBA_NP_PREBUILD) + $(Q) echo "GEN: libameba_fwlib.a (fwlib from SDK source)" + $(Q) mkdir -p $(AMEBA_PREBUILT_LIBS)$(DELIM)fwlib_obj + $(Q) rebuild_fwlib=0; fwlib_objs=""; \ + for src in $(AMEBA_FWLIB_SRCS); do \ + obj=$(AMEBA_PREBUILT_LIBS)/fwlib_obj/`basename $$src .c`.o; \ + if [ "$$src" -nt "$$obj" ] 2>/dev/null || [ ! -f "$$obj" ]; then \ + $(CC) $(ARCHCPUFLAGS) -Os -ffunction-sections -fdata-sections \ + $(AMEBA_FWLIB_INC) -c $$src -o $$obj || exit 1; \ + rebuild_fwlib=1; \ + fi; \ + fwlib_objs="$$fwlib_objs $$obj"; \ + done; \ + if [ "$$rebuild_fwlib" = "1" ] || [ ! -f "$(AMEBA_FWLIB_A)" ]; then \ + rm -f $(AMEBA_FWLIB_A); \ + $(CROSSDEV)ar crs $(AMEBA_FWLIB_A) $$fwlib_objs; \ + fi + $(Q) if [ "$(CONFIG_RTL8721F_WIFI)" = "y" ]; then \ + echo "GEN: libameba_wifi.a (WHC host glue from SDK source + NuttX shim)"; \ + mkdir -p $(AMEBA_PREBUILT_LIBS)$(DELIM)wifi_obj; \ + rebuild_wifi=0; wifi_objs=""; \ + for src in $(AMEBA_WIFI_SRCS); do \ + obj=$(AMEBA_PREBUILT_LIBS)/wifi_obj/`basename $$src .c`.o; \ + if [ "$$src" -nt "$$obj" ] 2>/dev/null || [ ! -f "$$obj" ]; then \ + $(CC) $(ARCHCPUFLAGS) -Os -ffunction-sections -fdata-sections \ + $(AMEBA_WIFI_INC) -c $$src -o $$obj || exit 1; \ + rebuild_wifi=1; \ + fi; \ + wifi_objs="$$wifi_objs $$obj"; \ + done; \ + if [ "$$rebuild_wifi" = "1" ] || [ ! -f "$(AMEBA_WIFI_A)" ]; then \ + rm -f $(AMEBA_WIFI_A); \ + $(CROSSDEV)ar crs $(AMEBA_WIFI_A) $$wifi_objs; \ + fi; \ + fi + $(Q) echo "GEN: ld.script.gen (Ameba KM4 image2)" + $(Q) mkdir -p $(AMEBA_PREBUILT)$(DELIM)project_km4tz + $(Q) cp $(AMEBA_AUTOCONF) $(AMEBA_PREBUILT)$(DELIM)project_km4tz$(DELIM)platform_autoconf.h + $(Q) $(CC) -E -P -xc -c $(AMEBA_IMG2_LD) -o $(GENLDSCRIPT) -I $(AMEBA_PREBUILT) + $(Q) cat $(AMEBA_ROM_LD) $(AMEBA_ROM_LD_WIFI) $(AMEBA_ROM_LD_OS) \ + $(AMEBA_ROM_LD_NS) >> $(GENLDSCRIPT) + $(Q) sed -i 's|^\([[:space:]]*\)\*(\.data\*)|\1*(.vectors*)\n\1*(.data*)|' $(GENLDSCRIPT) +endef + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) + +CFLAGS += $(EXTRAFLAGS) +CPPFLAGS += $(EXTRAFLAGS) + +# VFS1 data-partition geometry for the littlefs MTD comes from the SDK flash +# layout (CONFIG_FLASH_VFS1_OFFSET/SIZE in the regenerated platform_autoconf.h), +# so ameba_flash_mtd.c never hardcodes it. Extract the two values and pass them +# as neutral -D macros (a NuttX C file must not force-include the SDK autoconf). +# The header falls back to the vendor default if these are absent (e.g. the very +# first parse on a clean clone, before PREBUILD has generated the autoconf). +ifneq ($(wildcard $(AMEBA_AUTOCONF)),) +AMEBA_VFS1_OFFSET := $(strip $(shell awk '$$2=="CONFIG_FLASH_VFS1_OFFSET"{print $$3}' $(AMEBA_AUTOCONF))) +AMEBA_VFS1_SIZE := $(strip $(shell awk '$$2=="CONFIG_FLASH_VFS1_SIZE"{print $$3}' $(AMEBA_AUTOCONF))) +CFLAGS += $(if $(AMEBA_VFS1_OFFSET),-DAMEBA_FLASH_VFS1_OFFSET_XIP=$(AMEBA_VFS1_OFFSET)) +CFLAGS += $(if $(AMEBA_VFS1_SIZE),-DAMEBA_FLASH_VFS1_SIZE_CFG=$(AMEBA_VFS1_SIZE)) +endif + +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +# NXFLAT module definitions + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)$(DELIM)binfmt$(DELIM)libnxflat$(DELIM)gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +############################################################################ +# POSTBUILD -- package the linked image2 into a flashable nuttx.bin +# +# Runs after `nuttx` (== the KM4 image2 .axf) is linked. This folds the +# prototype package_app.sh into NuttX's build: +# +# 1. Replicate the SDK image2 postbuild prologue (copy map/axf, nm/objdump). +# 2. Run the SDK km4tz image2 postbuild.cmake (axf2bin) -> km4tz_image2_all.bin. +# 3. Run the SDK project firmware_package postbuild.cmake combining the +# freshly built AP (km4tz) image2 with the freshly built NP (km4ns) image2 +# into the packed app image, copied into $(TOPDIR) as nuttx.bin. boot.bin +# is a prebuilt bootloader and stays in prebuilt/ (flashed from there). +# +# The NP (km4ns) image2 is rebuilt from the pinned SDK source every build (by +# AMEBA_NP_POSTBUILD, fed the AP disassembly), so the two cores never drift. +# The SDK scripts/cmake/python are invoked read-only; only artefacts under the +# build staging dir are written. +# +# Tooling resolved from the asdk toolchain on PATH and the python interpreter +# ameba_setup_env.sh resolved (recorded in .amebapy/bindir: a real SDK .venv +# when one exists, otherwise a system-python3 shim). CMAKE may be overridden +# via the CMAKE environment variable; it defaults to `cmake` on PATH. That bin +# dir is prepended to PATH for the SDK cmake/axf2bin steps so `python`/`python3` +# resolve to the deps-carrying interpreter. It is read at recipe run time (the +# `$$(cat ...)` defers until after ameba_setup_env.sh has written the file). +############################################################################ + +AMEBA_VENV_BIN = $$(cat $(AMEBA_SDK)/.amebapy/bindir 2>/dev/null) + +CMAKE ?= cmake +NM ?= $(CROSSDEV)nm +OBJDUMP ?= $(CROSSDEV)objdump +STRIP ?= $(CROSSDEV)strip +OBJCOPY ?= $(CROSSDEV)objcopy +SIZE ?= $(CROSSDEV)size + +AMEBA_SOC_PROJ = $(AMEBA_SOC)/project +AMEBA_KM4_PROJ = $(AMEBA_SOC_PROJ)/project_km4tz + +# Staging dir for the SDK packaging steps (under the board, gitignored). + +AMEBA_PKGDIR = $(AMEBA_PREBUILT)$(DELIM)pkg + +define POSTBUILD + $(Q) echo "PACK: nuttx.bin (Ameba AP km4tz image2 + NP km4ns image2)" + $(Q) test -n "$(AMEBA_SDK)" || \ + { echo "ERROR: AMEBA_SDK is not set"; exit 1; } + $(Q) $(AMEBA_SETUP_ENV) $(AMEBA_SDK) $(AMEBA_TOOLCHAIN_DIR) + $(Q) rm -rf $(AMEBA_PKGDIR) + $(Q) mkdir -p $(AMEBA_PKGDIR) + $(Q) cp $(TOPDIR)$(DELIM)nuttx $(AMEBA_PKGDIR)$(DELIM)target_img2.axf + $(Q) $(NM) $(AMEBA_PKGDIR)$(DELIM)target_img2.axf | sort \ + > $(AMEBA_PKGDIR)$(DELIM)target_img2.map + $(Q) $(OBJDUMP) -d $(AMEBA_PKGDIR)$(DELIM)target_img2.axf \ + > $(AMEBA_PKGDIR)$(DELIM)target_img2.asm + $(Q) $(AMEBA_NP_POSTBUILD) + $(Q) cp $(AMEBA_PKGDIR)$(DELIM)target_img2.axf \ + $(AMEBA_PKGDIR)$(DELIM)target_pure_img2.axf + $(Q) $(STRIP) $(AMEBA_PKGDIR)$(DELIM)target_pure_img2.axf + $(Q) cp $(AMEBA_PREBUILT)$(DELIM)config_km4 $(AMEBA_PKGDIR)$(DELIM).config_km4 + $(Q) cp $(AMEBA_PREBUILT)$(DELIM)config_fw $(AMEBA_PKGDIR)$(DELIM).config + $(Q) cp $(AMEBA_PREBUILT)$(DELIM)km4ns_image2_all.bin \ + $(AMEBA_PKGDIR)$(DELIM)km4ns_image2_all.bin + $(Q) printf '{\n "soc": {\n "name": "RTL8721F"\n }\n}\n' \ + > $(AMEBA_PKGDIR)$(DELIM)soc_info.json + $(Q) TARGET_SOC=RTL8721F PATH=$(AMEBA_VENV_BIN):$$PATH $(CMAKE) \ + -Dc_BASEDIR=$(AMEBA_SDK) \ + -Dc_CMAKE_FILES_DIR=$(AMEBA_SDK)/cmake \ + -Dc_SOC_PROJECT_DIR=$(AMEBA_SOC_PROJ) \ + -Dc_MCU_PROJECT_DIR=$(AMEBA_KM4_PROJ) \ + -Dc_MCU_PROJECT_NAME=km4tz \ + -Dc_MCU_KCONFIG_FILE=$(AMEBA_PKGDIR)$(DELIM).config_km4 \ + -Dc_SDK_IMAGE_TARGET_DIR=$(AMEBA_PKGDIR) \ + -DKM4_BUILDDIR= \ + -DFINAL_IMAGE_DIR=$(AMEBA_PKGDIR) \ + -DBUILD_TYPE=NONE -DANALYZE_MP_IMG=0 -DDAILY_BUILD=0 \ + -DEXTERN_DIR=$(AMEBA_PKGDIR) -DCODE_ANALYZE_RETRY= \ + -DIMAGESCRIPTDIR=$(AMEBA_SDK)/tools/image_scripts \ + -DCMAKE_SIZE=$(SIZE) -DCMAKE_OBJCOPY=$(OBJCOPY) \ + -P $(AMEBA_KM4_PROJ)/make/image2/postbuild.cmake + $(Q) TARGET_SOC=RTL8721F PATH=$(AMEBA_VENV_BIN):$$PATH $(CMAKE) \ + -Dc_BASEDIR=$(AMEBA_SDK) \ + -Dc_CMAKE_FILES_DIR=$(AMEBA_SDK)/cmake \ + -Dc_MCU_KCONFIG_FILE=$(AMEBA_PKGDIR)$(DELIM).config \ + -Dc_SOC_PROJECT_DIR=$(AMEBA_SOC_PROJ) \ + -Dc_SDK_IMAGE_TARGET_DIR= \ + -Dc_IMAGE_OUTPUT_DIR=$(AMEBA_PKGDIR) \ + -Dc_APP_BINARY_NAME=app.bin \ + -Dc_IMAGE1_ALL_FILES= \ + -Dc_IMAGE2_ALL_FILES="$(AMEBA_PKGDIR)/km4ns_image2_all.bin;$(AMEBA_PKGDIR)/km4tz_image2_all.bin" \ + -Dc_IMAGE3_ALL_FILES= \ + -DFINAL_IMAGE_DIR=$(AMEBA_PKGDIR) \ + -DANALYZE_MP_IMG=0 -DEXTERN_DIR=$(AMEBA_PKGDIR) \ + -P $(AMEBA_SOC_PROJ)/postbuild.cmake + $(Q) cp $(AMEBA_PKGDIR)$(DELIM)app.bin $(TOPDIR)$(DELIM)nuttx.bin + $(Q) echo "PACK: wrote $(TOPDIR)$(DELIM)nuttx.bin" + $(Q) echo " Flash with: make flash AMEBA_PORT=/dev/ttyUSB0" +endef diff --git a/arch/arm/src/rtl8721f/ameba_ipc.c b/arch/arm/src/rtl8721f/ameba_ipc.c new file mode 100644 index 0000000000000..ca6a98dcf3baf --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_ipc.c @@ -0,0 +1,150 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_ipc.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * RTL8721F km4tz<->km4ns IPC bring-up. + * + * The on-chip IPC links the AP (km4tz, runs NuttX) and the NP (km4ns, the + * prebuilt device blob). Several SDK fwlib subsystems use it, NOT just + * WiFi: + * + * - FLASH_Write_Lock()/Unlock() (ameba_flash_ram.c) IPC-pause the NP while + * the AP erases/programs flash. Both cores XIP from the SAME SPI NOR + * (NP@0x02000000, AP@0x04000000), so the NP MUST be paused during a + * flash erase/program or its XIP fetch faults. The lock sends + * IPC_A2N_FLASHPG_REQ and busy-waits for the NP to acknowledge; without + * IPC up the AP hangs. + * - The WHC host WiFi TRX channels. + * + * This must therefore be initialized before the flash filesystem mounts, + * independent of whether WiFi is enabled. It mirrors the SDK km4tz main(): + * + * ipc_table_init(IPCAP_DEV); + * InterruptRegister(IPC_INTHandler, IPC_KM4TZ_IRQ, IPCAP_DEV, ...); + * InterruptEn(IPC_KM4TZ_IRQ, ...); + * + * but using NuttX's irq_attach()/up_enable_irq() (NuttX owns the vector + * table). ipc_table_init() walks the .ipc.table.data section and registers + * every channel callback the linked SDK objects contributed. + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "ameba_irq.h" +#include "ameba_ipc.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* 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). + * RTL8721F_IRQ_IPC_KM4 maps to APIRQn IPC_KM4TZ_IRQ (external vector 3) -- + * see arch/.../irq.h. + */ + +#define IPCAP_DEV ((void *)0x40804000) + +/**************************************************************************** + * External Function Prototypes + ****************************************************************************/ + +/* SDK fwlib IPC (libameba_fwlib.a, compiled from SDK source). */ + +extern uint32_t IPC_INTHandler(void *data); +extern void ipc_table_init(void *ipcx); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static bool g_ameba_ipc_inited; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ameba_ipc_interrupt + * + * Description: + * NuttX IRQ handler shim for the km4tz IPC interrupt; forwards to the + * SDK's IPC_INTHandler, which dispatches to the registered channel + * callbacks. + * + ****************************************************************************/ + +static int ameba_ipc_interrupt(int irq, void *context, void *arg) +{ + UNUSED(irq); + UNUSED(context); + + IPC_INTHandler(arg); + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ameba_ipc_initialize + * + * Description: + * Bring up the km4tz<->km4ns IPC transport once, after the scheduler is + * running. Idempotent: safe to call from both the flash filesystem + * bring-up and the WiFi bring-up; only the first call wires the interrupt + * and walks the channel table. + * + ****************************************************************************/ + +void ameba_ipc_initialize(void) +{ + if (g_ameba_ipc_inited) + { + return; + } + + g_ameba_ipc_inited = true; + + /* Register every channel the linked SDK objects contributed (flash sync, + * and -- when linked -- the WHC WiFi TRX channels), then route the IPC + * interrupt to the SDK dispatcher. Order follows the SDK km4tz main(): + * table first, then unmask the NVIC line. + */ + + ipc_table_init(IPCAP_DEV); + irq_attach(RTL8721F_IRQ_IPC_KM4, ameba_ipc_interrupt, IPCAP_DEV); + up_enable_irq(RTL8721F_IRQ_IPC_KM4); +} diff --git a/arch/arm/src/rtl8721f/ameba_ipc.h b/arch/arm/src/rtl8721f/ameba_ipc.h new file mode 100644 index 0000000000000..a1552bee62421 --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_ipc.h @@ -0,0 +1,51 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_ipc.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_RTL8721F_AMEBA_IPC_H +#define __ARCH_ARM_SRC_RTL8721F_AMEBA_IPC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: ameba_ipc_initialize + * + * Description: + * Bring up the km4tz<->km4ns IPC transport once (idempotent). Required by + * the SDK flash erase/program path (inter-core pause) and by WiFi. Call + * after the scheduler is running and before the flash filesystem mounts. + * + ****************************************************************************/ + +void ameba_ipc_initialize(void); + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_RTL8721F_AMEBA_IPC_H */ diff --git a/arch/arm/src/rtl8721f/ameba_irq.c b/arch/arm/src/rtl8721f/ameba_irq.c new file mode 100644 index 0000000000000..1a2f4ed2008ac --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_irq.c @@ -0,0 +1,382 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_irq.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "arm_internal.h" +#include "ameba_irq.h" +#include "nvic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NVIC_ENA_OFFSET (0) +#define NVIC_CLRENA_OFFSET (NVIC_IRQ0_31_CLEAR - NVIC_IRQ0_31_ENABLE) + +#define DEFPRIORITY32 (NVIC_SYSH_PRIORITY_DEFAULT << 24 | \ + NVIC_SYSH_PRIORITY_DEFAULT << 16 | \ + NVIC_SYSH_PRIORITY_DEFAULT << 8 | \ + NVIC_SYSH_PRIORITY_DEFAULT) + +/* Size of the interrupt stack allocation */ + +#define INTSTACK_ALLOC (CONFIG_SMP_NCPUS * INTSTACK_SIZE) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_DEBUG_FEATURES +static int ameba_nmi(int irq, void *context, void *arg) +{ + up_irq_save(); + _err("PANIC!!! NMI received\n"); + PANIC(); + return 0; +} + +static int ameba_pendsv(int irq, void *context, void *arg) +{ +#ifndef CONFIG_ARCH_HIPRI_INTERRUPT + up_irq_save(); + _err("PANIC!!! PendSV received\n"); + PANIC(); +#endif + return 0; +} + +static int ameba_reserved(int irq, void *context, void *arg) +{ + up_irq_save(); + _err("PANIC!!! Reserved interrupt\n"); + PANIC(); + return 0; +} +#endif + +/**************************************************************************** + * Name: ameba_prioritize_syscall + * + * Description: + * Set the priority of an exception. This function may be needed + * internally even if support for prioritized interrupts is not enabled. + * + ****************************************************************************/ + +static inline void ameba_prioritize_syscall(int priority) +{ + uint32_t regval; + + /* SVCALL is system handler 11 */ + + regval = getreg32(NVIC_SYSH8_11_PRIORITY); + regval &= ~NVIC_SYSH_PRIORITY_PR11_MASK; + regval |= (priority << NVIC_SYSH_PRIORITY_PR11_SHIFT); + putreg32(regval, NVIC_SYSH8_11_PRIORITY); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_prioritize_irq + * + * Description: + * Set the priority of an IRQ. This function may be needed internally + * even if support for prioritized interrupts is not enabled. + * + ****************************************************************************/ + +int up_prioritize_irq(int irq, int priority) +{ + uint32_t regaddr; + uint32_t regval; + int shift; + + DEBUGASSERT(irq >= 0 && irq < NR_IRQS && + (unsigned)priority <= NVIC_SYSH_PRIORITY_MIN); + + if (irq < 16) + { + /* NVIC_SYSH_PRIORITY() maps {0..15} to one of three priority + * registers (0-3 are invalid) + */ + + regaddr = NVIC_SYSH_PRIORITY(irq); + irq -= 4; + } + else + { + /* NVIC_IRQ_PRIORITY() maps {0..} to one of many priority registers */ + + irq -= 16; + regaddr = NVIC_IRQ_PRIORITY(irq); + } + + regval = getreg32(regaddr); + shift = ((irq & 3) << 3); + regval &= ~(0xff << shift); + regval |= (priority << shift); + putreg32(regval, regaddr); + + return OK; +} + +/**************************************************************************** + * Name: up_irqinitialize + * + * Description: + * This function is called by up_initialize() during the bring-up of the + * system. It is the responsibility of this function to but the interrupt + * subsystem into the working and ready state. + * + ****************************************************************************/ + +void up_irqinitialize(void) +{ + uint32_t regaddr; + int num_priority_registers; + int i; + + /* Disable all interrupts */ + + for (i = 0; i < NR_IRQS - AMEBA_IRQ_FIRST; i += 32) + { + putreg32(0xffffffff, NVIC_IRQ_CLEAR(i)); + } + + putreg32((uint32_t)_vectors, NVIC_VECTAB); + +#ifdef CONFIG_ARCH_RAMVECTORS + /* If CONFIG_ARCH_RAMVECTORS is defined, then we are using a RAM-based + * vector table that requires special initialization. + */ + + up_ramvec_initialize(); +#endif + + /* Set all interrupts (and exceptions) to the default priority */ + + putreg32(DEFPRIORITY32, NVIC_SYSH4_7_PRIORITY); + putreg32(DEFPRIORITY32, NVIC_SYSH8_11_PRIORITY); + putreg32(DEFPRIORITY32, NVIC_SYSH12_15_PRIORITY); + + /* The NVIC ICTR register (bits 0-4) holds the number of of interrupt + * lines that the NVIC supports: + * + * 0 -> 32 interrupt lines, 8 priority registers + * 1 -> 64 " " " ", 16 priority registers + * 2 -> 96 " " " ", 32 priority registers + * ... + */ + + num_priority_registers = (getreg32(NVIC_ICTR) + 1) * 8; + + /* Now set all of the interrupt lines to the default priority */ + + regaddr = NVIC_IRQ0_3_PRIORITY; + while (num_priority_registers--) + { + putreg32(DEFPRIORITY32, regaddr); + regaddr += 4; + } + + /* Attach the SVCall and Hard Fault exception handlers. The SVCall + * exception is used for performing context switches; The Hard Fault + * must also be caught because a SVCall may show up as a Hard Fault + * under certain conditions. + */ + + irq_attach(AMEBA_IRQ_SVCALL, arm_svcall, NULL); + irq_attach(AMEBA_IRQ_HARDFAULT, arm_hardfault, NULL); + + /* Set the priority of the SVCall interrupt */ + + up_prioritize_irq(AMEBA_IRQ_PENDSV, NVIC_SYSH_PRIORITY_MIN); + + ameba_prioritize_syscall(NVIC_SYSH_SVCALL_PRIORITY); + + /* If the MPU is enabled, then attach and enable the Memory Management + * Fault handler. + */ + +#ifdef CONFIG_ARM_MPU + irq_attach(AMEBA_IRQ_MEMFAULT, arm_memfault, NULL); + up_enable_irq(AMEBA_IRQ_MEMFAULT); +#endif + + /* Attach all other processor exceptions (except reset and sys tick) */ + +#ifdef CONFIG_DEBUG_FEATURES + irq_attach(AMEBA_IRQ_NMI, ameba_nmi, NULL); +#ifndef CONFIG_ARM_MPU + irq_attach(AMEBA_IRQ_MEMFAULT, arm_memfault, NULL); +#endif + irq_attach(AMEBA_IRQ_BUSFAULT, arm_busfault, NULL); + irq_attach(AMEBA_IRQ_USAGEFAULT, arm_usagefault, NULL); + irq_attach(AMEBA_IRQ_PENDSV, ameba_pendsv, NULL); + arm_enable_dbgmonitor(); + irq_attach(AMEBA_IRQ_DBGMONITOR, arm_dbgmonitor, NULL); + irq_attach(AMEBA_IRQ_RESERVED, ameba_reserved, NULL); +#endif + +#ifndef CONFIG_SUPPRESS_INTERRUPTS + + /* And finally, enable interrupts */ + + arm_color_intstack(); + up_irq_enable(); +#endif +} + +static int ameba_irqinfo(int irq, uintptr_t *regaddr, uint32_t *bit, + uintptr_t offset) +{ + int n; + + DEBUGASSERT(irq >= AMEBA_IRQ_NMI && irq < NR_IRQS); + + /* Check for external interrupt */ + + if (irq >= AMEBA_IRQ_FIRST) + { + n = irq - AMEBA_IRQ_FIRST; + *regaddr = NVIC_IRQ_ENABLE(n) + offset; + *bit = (uint32_t)0x1 << (n & 0x1f); + } + + /* Handle processor exceptions. Only a few can be disabled */ + + else + { + *regaddr = NVIC_SYSHCON; + if (irq == AMEBA_IRQ_MEMFAULT) + { + *bit = NVIC_SYSHCON_MEMFAULTENA; + } + else if (irq == AMEBA_IRQ_BUSFAULT) + { + *bit = NVIC_SYSHCON_BUSFAULTENA; + } + else if (irq == AMEBA_IRQ_USAGEFAULT) + { + *bit = NVIC_SYSHCON_USGFAULTENA; + } + else if (irq == AMEBA_IRQ_SYSTICK) + { + *regaddr = NVIC_SYSTICK_CTRL; + *bit = NVIC_SYSTICK_CTRL_ENABLE; + } + else + { + return -EINVAL; /* Invalid or unsupported exception */ + } + } + + return OK; +} + +/**************************************************************************** + * Name: up_disable_irq + * + * Description: + * Disable the IRQ specified by 'irq' + * + ****************************************************************************/ + +void up_disable_irq(int irq) +{ + uintptr_t regaddr; + uint32_t regval; + uint32_t bit; + + if (ameba_irqinfo(irq, ®addr, &bit, NVIC_CLRENA_OFFSET) == 0) + { + /* Modify the appropriate bit in the register to disable the interrupt. + * For normal interrupts, we need to set the bit in the associated + * Interrupt Clear Enable register. For other exceptions, we need to + * clear the bit in the System Handler Control and State Register. + */ + + if (irq >= AMEBA_IRQ_FIRST) + { + putreg32(bit, regaddr); + } + else + { + regval = getreg32(regaddr); + regval &= ~bit; + putreg32(regval, regaddr); + } + } +} + +/**************************************************************************** + * Name: up_enable_irq + * + * Description: + * Enable the IRQ specified by 'irq' + * + ****************************************************************************/ + +void up_enable_irq(int irq) +{ + uintptr_t regaddr; + uint32_t regval; + uint32_t bit; + + if (ameba_irqinfo(irq, ®addr, &bit, NVIC_ENA_OFFSET) == 0) + { + /* Modify the appropriate bit in the register to enable the interrupt. + * For normal interrupts, we need to set the bit in the associated + * Interrupt Set Enable register. For other exceptions, we need to + * set the bit in the System Handler Control and State Register. + */ + + if (irq >= AMEBA_IRQ_FIRST) + { + putreg32(bit, regaddr); + } + else + { + regval = getreg32(regaddr); + regval |= bit; + putreg32(regval, regaddr); + } + } +} + +/**************************************************************************** + * Name: arm_ack_irq + ****************************************************************************/ + +void arm_ack_irq(int irq) +{ +} diff --git a/arch/arm/src/rtl8721f/ameba_irq.h b/arch/arm/src/rtl8721f/ameba_irq.h new file mode 100644 index 0000000000000..deb33267135f5 --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_irq.h @@ -0,0 +1,76 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_irq.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_RTL8721F_AMEBA_IRQ_H +#define __ARCH_ARM_SRC_RTL8721F_AMEBA_IRQ_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Processor exception aliases used by the chip-internal logic. These mirror + * the ARMv8-M processor exception vector numbers (0-15) exported by + * arch/rtl8721f/irq.h. + */ + +#define AMEBA_IRQ_RESERVED RTL8721F_IRQ_RESERVED +#define AMEBA_IRQ_NMI RTL8721F_IRQ_NMI +#define AMEBA_IRQ_HARDFAULT RTL8721F_IRQ_HARDFAULT +#define AMEBA_IRQ_MEMFAULT RTL8721F_IRQ_MEMFAULT +#define AMEBA_IRQ_BUSFAULT RTL8721F_IRQ_BUSFAULT +#define AMEBA_IRQ_USAGEFAULT RTL8721F_IRQ_USAGEFAULT +#define AMEBA_IRQ_SVCALL RTL8721F_IRQ_SVCALL +#define AMEBA_IRQ_DBGMONITOR RTL8721F_IRQ_DBGMONITOR +#define AMEBA_IRQ_PENDSV RTL8721F_IRQ_PENDSV +#define AMEBA_IRQ_SYSTICK RTL8721F_IRQ_SYSTICK +#define AMEBA_IRQ_FIRST RTL8721F_IRQ_FIRST + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_RTL8721F_AMEBA_IRQ_H */ diff --git a/arch/arm/src/rtl8721f/ameba_loguart.c b/arch/arm/src/rtl8721f/ameba_loguart.c new file mode 100644 index 0000000000000..ca7eb26a675ad --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_loguart.c @@ -0,0 +1,413 @@ +/*************************************************************************** + * arch/arm/src/rtl8721f/ameba_loguart.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ***************************************************************************/ + +/*************************************************************************** + * Included Files + ***************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include "arm_internal.h" +#include "chip.h" +#include "ameba_irq.h" + +/*************************************************************************** + * Pre-processor Definitions + ***************************************************************************/ + +/* This driver targets the RTL8721F LOG-UART, which NuttX (on + * the KM4 application core) owns directly. + * + * The Realtek SDK's app_start() runs BEFORE NuttX and has already + * configured the LOG-UART pinmux/clock/baud and printed its boot banner, + * so the hardware is not re-initialized here. + * + * The LOG-UART is physically shared with the NP, but the NP image is built + * with CONFIG_SHELL=n: the NP neither runs its monitor shell nor claims the + * LOG-UART RX interrupt. NuttX therefore routes the LOG-UART interrupt to + * the AP with LOGUART_INTCoreConfig() and reads RX directly via the ROM + * helpers, giving the AP sole ownership of the console (no IPC relay). + * + * NuttX installs its own vector table and re-points VTOR in + * up_irqinitialize(), so once NuttX is running it fully owns the NVIC. + */ + +/* LOGUART_INTConfig() interrupt-source bit (RX data available). */ + +#define LOGUART_BIT_ERBI (1u << 0) + +/* LOGUART_INTCoreConfig() per-core routing masks (SDK KM0/KM4 mask bits): + * select which core's NVIC the LOG-UART interrupt is delivered to. NP is + * the network core (km4ns), AP is the host core (km4tz / NuttX). + */ + +#define LOGUART_BIT_INTR_MASK_NP (1u << 0) +#define LOGUART_BIT_INTR_MASK_AP (1u << 1) + +/* SDK ENABLE/DISABLE values. */ + +#define AMEBA_ENABLE 1 +#define AMEBA_DISABLE 0 + +/* LOG-UART device base (UARTLOG_REG_BASE, from SDK RTL8721F + * hal_platform.h). NOTE: this is the RTL8721F address (0x401C6000) -- it + * differs from the RTL8721Dx LOG-UART (0x4100F000). Only + * LOGUART_INTConfig()/INTCoreConfig() take this base explicitly; the TX + * path (DiagPrintf/LOGUART_PutChar) is a ROM call with its own internal + * base, which is why TX worked even when this was wrong but configuring + * the RX interrupt bus-faulted. + */ + +#define LOGUART_DEV ((void *)0x401C6000) + +/*************************************************************************** + * External ROM/SDK Function Prototypes + ***************************************************************************/ + +/* These live in the RTL8721F ROM and are resolved at link time from the + * SDK's ROM symbol script. Declared here (instead of including the SDK + * headers) to keep the SDK include tree out of the NuttX build. + */ + +extern void LOGUART_PutChar(unsigned char c); +extern unsigned char LOGUART_Readable(void); +extern unsigned char LOGUART_GetChar(int pullmode); +extern void LOGUART_INTConfig(void *dev, unsigned int it, + unsigned int state); +extern void LOGUART_INTCoreConfig(void *dev, unsigned int mask, + unsigned int state); + +/*************************************************************************** + * Private Function Prototypes + ***************************************************************************/ + +static int loguart_setup(struct uart_dev_s *dev); +static void loguart_shutdown(struct uart_dev_s *dev); +static int loguart_attach(struct uart_dev_s *dev); +static void loguart_detach(struct uart_dev_s *dev); +static int loguart_interrupt(int irq, void *context, void *arg); +static int loguart_ioctl(struct file *filep, int cmd, unsigned long arg); +static int loguart_receive(struct uart_dev_s *dev, unsigned int *status); +static void loguart_rxint(struct uart_dev_s *dev, bool enable); +static bool loguart_rxavailable(struct uart_dev_s *dev); +static void loguart_send(struct uart_dev_s *dev, int ch); +static void loguart_txint(struct uart_dev_s *dev, bool enable); +static bool loguart_txready(struct uart_dev_s *dev); +static bool loguart_txempty(struct uart_dev_s *dev); + +/*************************************************************************** + * Private Data + ***************************************************************************/ + +static const struct uart_ops_s g_loguart_ops = +{ + .setup = loguart_setup, + .shutdown = loguart_shutdown, + .attach = loguart_attach, + .detach = loguart_detach, + .ioctl = loguart_ioctl, + .receive = loguart_receive, + .rxint = loguart_rxint, + .rxavailable = loguart_rxavailable, + .send = loguart_send, + .txint = loguart_txint, + .txready = loguart_txready, + .txempty = loguart_txempty, +}; + +/* I/O buffers for the LOG-UART console. */ + +static char g_loguart_rxbuffer[CONFIG_RTL8721F_LOGUART_RXBUFSIZE]; +static char g_loguart_txbuffer[CONFIG_RTL8721F_LOGUART_TXBUFSIZE]; + +/* The LOG-UART port device. */ + +static struct uart_dev_s g_loguart_port = +{ + .isconsole = true, + .recv = + { + .size = CONFIG_RTL8721F_LOGUART_RXBUFSIZE, + .buffer = g_loguart_rxbuffer, + }, + .xmit = + { + .size = CONFIG_RTL8721F_LOGUART_TXBUFSIZE, + .buffer = g_loguart_txbuffer, + }, + .ops = &g_loguart_ops, +}; + +/*************************************************************************** + * Private Functions + ***************************************************************************/ + +/*************************************************************************** + * Name: loguart_setup + ***************************************************************************/ + +static int loguart_setup(struct uart_dev_s *dev) +{ + UNUSED(dev); + return OK; +} + +/*************************************************************************** + * Name: loguart_shutdown + ***************************************************************************/ + +static void loguart_shutdown(struct uart_dev_s *dev) +{ + loguart_rxint(dev, false); +} + +/*************************************************************************** + * Name: loguart_attach + * + * Description: + * Route the LOG-UART interrupt to KM4 and attach the handler. The + * data-available (RX) source itself is enabled later via rxint(). + * + ***************************************************************************/ + +static int loguart_attach(struct uart_dev_s *dev) +{ + int ret; + + ret = irq_attach(RTL8721F_IRQ_UART_LOG, loguart_interrupt, dev); + if (ret == OK) + { + /* Claim the LOG-UART interrupt for the AP (the NP is built + * CONFIG_SHELL=n and does not claim it) and unmask it in the NVIC. + */ + + LOGUART_INTCoreConfig(LOGUART_DEV, LOGUART_BIT_INTR_MASK_NP, + AMEBA_DISABLE); + LOGUART_INTCoreConfig(LOGUART_DEV, LOGUART_BIT_INTR_MASK_AP, + AMEBA_ENABLE); + up_enable_irq(RTL8721F_IRQ_UART_LOG); + } + + return ret; +} + +/*************************************************************************** + * Name: loguart_detach + ***************************************************************************/ + +static void loguart_detach(struct uart_dev_s *dev) +{ + UNUSED(dev); + up_disable_irq(RTL8721F_IRQ_UART_LOG); + irq_detach(RTL8721F_IRQ_UART_LOG); +} + +/*************************************************************************** + * Name: loguart_interrupt + * + * Description: + * Common LOG-UART interrupt handler. Drains the RX FIFO into the NuttX + * receive buffer. + * + ***************************************************************************/ + +static int loguart_interrupt(int irq, void *context, void *arg) +{ + struct uart_dev_s *dev = (struct uart_dev_s *)arg; + + UNUSED(irq); + UNUSED(context); + + if (LOGUART_Readable()) + { + uart_recvchars(dev); + } + + return OK; +} + +/*************************************************************************** + * Name: loguart_ioctl + ***************************************************************************/ + +static int loguart_ioctl(struct file *filep, int cmd, unsigned long arg) +{ + UNUSED(filep); + UNUSED(cmd); + UNUSED(arg); + return -ENOTTY; +} + +/*************************************************************************** + * Name: loguart_receive + ***************************************************************************/ + +static int loguart_receive(struct uart_dev_s *dev, unsigned int *status) +{ + UNUSED(dev); + + *status = 0; + + /* Read one byte in polled (non-pull) mode. */ + + return (int)LOGUART_GetChar(false); +} + +/*************************************************************************** + * Name: loguart_rxint + ***************************************************************************/ + +static void loguart_rxint(struct uart_dev_s *dev, bool enable) +{ + irqstate_t flags; + + UNUSED(dev); + + flags = enter_critical_section(); + + if (enable) + { + LOGUART_INTConfig(LOGUART_DEV, LOGUART_BIT_ERBI, AMEBA_ENABLE); + } + else + { + LOGUART_INTConfig(LOGUART_DEV, LOGUART_BIT_ERBI, AMEBA_DISABLE); + } + + leave_critical_section(flags); +} + +/*************************************************************************** + * Name: loguart_rxavailable + ***************************************************************************/ + +static bool loguart_rxavailable(struct uart_dev_s *dev) +{ + UNUSED(dev); + return LOGUART_Readable() != 0; +} + +/*************************************************************************** + * Name: loguart_send + ***************************************************************************/ + +static void loguart_send(struct uart_dev_s *dev, int ch) +{ + UNUSED(dev); + LOGUART_PutChar((unsigned char)ch); +} + +/*************************************************************************** + * Name: loguart_txint + * + * Description: + * TX is synchronous (LOGUART_PutChar blocks for FIFO space), so there + * is no hardware TX interrupt; pump the transmit buffer when asked to + * enable. + * + ***************************************************************************/ + +static void loguart_txint(struct uart_dev_s *dev, bool enable) +{ + irqstate_t flags; + + if (enable) + { + flags = enter_critical_section(); + uart_xmitchars(dev); + leave_critical_section(flags); + } +} + +/*************************************************************************** + * Name: loguart_txready + ***************************************************************************/ + +static bool loguart_txready(struct uart_dev_s *dev) +{ + UNUSED(dev); + return true; +} + +/*************************************************************************** + * Name: loguart_txempty + ***************************************************************************/ + +static bool loguart_txempty(struct uart_dev_s *dev) +{ + UNUSED(dev); + return true; +} + +/*************************************************************************** + * Public Functions + ***************************************************************************/ + +/*************************************************************************** + * Name: arm_lowputc + ***************************************************************************/ + +void arm_lowputc(char ch) +{ + if (ch == '\n') + { + LOGUART_PutChar((unsigned char)'\r'); + } + + LOGUART_PutChar((unsigned char)ch); +} + +/*************************************************************************** + * Name: arm_earlyserialinit + ***************************************************************************/ + +void arm_earlyserialinit(void) +{ +} + +/*************************************************************************** + * Name: arm_serialinit + ***************************************************************************/ + +void arm_serialinit(void) +{ + uart_register("/dev/console", &g_loguart_port); + uart_register("/dev/ttyS0", &g_loguart_port); +} + +/*************************************************************************** + * Name: up_putc + ***************************************************************************/ + +void up_putc(int ch) +{ + arm_lowputc((char)ch); +} diff --git a/arch/arm/src/rtl8721f/ameba_start.c b/arch/arm/src/rtl8721f/ameba_start.c new file mode 100644 index 0000000000000..73bd14ba8efcc --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_start.c @@ -0,0 +1,172 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_start.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Description + * + * NuttX owns the km4tz image2. The entry is a NuttX-owned app_start() + * (arch/arm/src/rtl8721f/ameba_app_start.c, built with the SDK fwlib include + * set) that runs ALL the OS-independent silicon init (cache, data-flash + * high-speed, system timer, pinmux, MPU, ...) and zeroes BSS, then calls + * main(). Its Img2EntryFun0 descriptor (also in that file) is what the SDK + * bootloader jumps to. + * + * main() is therefore the hand-off point from silicon bring-up to NuttX: + * it switches MSP onto a NuttX-owned stack (the idle-thread stack), points + * VTOR at NuttX's own vector table, configures the FPU, and calls + * nx_start(). nx_start() never returns, so the SDK FreeRTOS scheduler is + * never launched. + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include + +#include "arm_internal.h" +#include "nvic.h" +#include "ameba_irq.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Reserved idle-thread stack, owned by NuttX (in NuttX's own .bss). The ARM + * full-descending stack grows down from the top of this buffer. + * g_idle_topstack points at the TOP and is consumed by the scheduler / idle + * thread bring-up logic. + */ + +static uint8_t g_idle_stack[CONFIG_IDLETHREAD_STACKSIZE] + aligned_data(8); + +const uintptr_t g_idle_topstack = + (uintptr_t)g_idle_stack + CONFIG_IDLETHREAD_STACKSIZE; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* NuttX vector table (armv8-m/arm_vectors.c). */ + +extern const void * const _vectors[]; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void ameba_start_continue(void) noreturn_function used_code; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ameba_start_continue + * + * Description: + * Runs on the NuttX idle stack (MSP already switched by main()). The SDK + * app_start() has already done all silicon init and zeroed BSS, so here we + * only take ownership of the vector table / FPU and enter the scheduler. + * + ****************************************************************************/ + +static void ameba_start_continue(void) +{ + /* Configure the FPU. */ + + arm_fpuconfig(); + + /* Point the vector table at NuttX's own table (the SDK app_start left VTOR + * pointing at the SDK/ROM table). + */ + + putreg32((uint32_t)_vectors, NVIC_VECTAB); + + /* Perform early serial initialization. */ + +#ifdef USE_EARLYSERIALINIT + arm_earlyserialinit(); +#endif + + /* Start NuttX. Never returns. */ + + nx_start(); + + for (; ; ); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: main + * + * Description: + * Hand-off from the SDK app_start() (which ran the silicon init and + * zeroed BSS) into NuttX. Switches MSP onto the NuttX idle stack as the + * very first action, then branches to ameba_start_continue() (which runs + * on that new stack). Declared naked so the compiler emits no prologue + * that would touch the (about-to-be-replaced) stack. Never returns. + * + ****************************************************************************/ + +int main(void) naked_function; +int main(void) +{ + __asm__ __volatile__ + ( + " movs r0, #0\n" + " msr msplim, r0\n" + " ldr r0, =g_idle_topstack\n" + " ldr r0, [r0]\n" + " msr msp, r0\n" + " b ameba_start_continue\n" + ); +} + +/**************************************************************************** + * Name: __start + * + * Description: + * Reset entry referenced by the NuttX armv8-m vector table (_vectors[1]). + * In this port the real image2 entry is Img2EntryFun0 -> app_start() -> + * main() (see ameba_app_start.c); __start exists so the vector table links + * and falls into the NuttX hand-off should the reset vector ever be taken. + * + ****************************************************************************/ + +void __start(void) naked_function; +void __start(void) +{ + __asm__ __volatile__ + ( + " b main\n" + ); +} diff --git a/arch/arm/src/rtl8721f/ameba_timerisr.c b/arch/arm/src/rtl8721f/ameba_timerisr.c new file mode 100644 index 0000000000000..ee1cb0ec8313c --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_timerisr.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_timerisr.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "arm_internal.h" +#include "systick.h" +#include "ameba_irq.h" +#include "nvic.h" + +/**************************************************************************** + * External Symbols + ****************************************************************************/ + +/* SDK CMSIS core-clock variable, set to the real KM4 CPU frequency (e.g. + * 240 MHz) by SystemCoreClockUpdate() in ameba_app_start() before NuttX + * runs. The ARMv8-M SysTick is clocked from the processor clock + * (CLKSOURCE=1, the 'true' below), so this is the correct reload base. + * Reading it at runtime avoids hard-coding a frequency that must track the + * SDK clock setup. + */ + +extern uint32_t SystemCoreClock; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: up_timer_initialize + * + * Description: + * This function is called during start-up to initialize + * the timer hardware. + * + ****************************************************************************/ + +void up_timer_initialize(void) +{ + uint32_t freq = SystemCoreClock; + + /* Set reload register and start the generic ARMv8-M SysTick driver. */ + + putreg32((freq / CLK_TCK) - 1, NVIC_SYSTICK_RELOAD); + up_timer_set_lowerhalf(systick_initialize(true, freq, -1)); +} diff --git a/arch/arm/src/rtl8721f/ameba_wifi_init.c b/arch/arm/src/rtl8721f/ameba_wifi_init.c new file mode 100644 index 0000000000000..2dadb2b6f9229 --- /dev/null +++ b/arch/arm/src/rtl8721f/ameba_wifi_init.c @@ -0,0 +1,122 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/ameba_wifi_init.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * NuttX side of the RTL8721F WiFi bring-up. + * + * The WHC host stack talks to the WiFi MAC/PHY (which runs on the NP network + * processor, km4ns) over the on-chip AP<->NP IPC. This file wires that IPC + * into NuttX's interrupt system -- mirroring the SDK AP main(): + * + * InterruptRegister(IPC_INTHandler, IPC_KM4_IRQ, IPCKM4_DEV, ...); + * InterruptEn(IPC_KM4_IRQ, ...); + * ipc_table_init(IPCKM4_DEV); + * + * but using NuttX's irq_attach()/up_enable_irq() (NuttX owns the vector + * table). ipc_table_init() then walks the .ipc.table.data section and + * registers every channel callback the linked SDK objects contributed, + * including the WHC WiFi TRX channels. Once IPC is live it spawns a task + * that runs the (blocking) host bring-up in ameba_wifi_start() (SDK-header + * side, libameba_wifi.a). + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "ameba_irq.h" +#include "ameba_ipc.h" +#ifdef CONFIG_NET +# include "ameba_wlan.h" +#endif + +/**************************************************************************** + * External Function Prototypes + ****************************************************************************/ + +/* Host WiFi bring-up (libameba_wifi.a, SDK-header side). */ + +extern int ameba_wifi_start(void); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtl8721f_wifi_initialize + * + * Description: + * 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. + * + ****************************************************************************/ + +int rtl8721f_wifi_initialize(void) +{ + int ret; + + /* Route the km4tz IPC interrupt to the SDK dispatcher and register every + * channel the linked objects contributed (WHC WiFi TRX channels included). + * Idempotent and shared with the flash filesystem bring-up. + */ + + ameba_ipc_initialize(); + + /* 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 + + return ret; +} diff --git a/arch/arm/src/rtl8721f/chip.h b/arch/arm/src/rtl8721f/chip.h new file mode 100644 index 0000000000000..9d5adce0f59fe --- /dev/null +++ b/arch/arm/src/rtl8721f/chip.h @@ -0,0 +1,39 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/chip.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_RTL8721F_CHIP_H +#define __ARCH_ARM_SRC_RTL8721F_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ARMV8M_PERIPHERAL_INTERRUPTS NR_IRQS + +#endif /* __ARCH_ARM_SRC_RTL8721F_CHIP_H */ diff --git a/arch/arm/src/rtl8721f/hardware/ameba_memorymap.h b/arch/arm/src/rtl8721f/hardware/ameba_memorymap.h new file mode 100644 index 0000000000000..6c9fb1983f100 --- /dev/null +++ b/arch/arm/src/rtl8721f/hardware/ameba_memorymap.h @@ -0,0 +1,62 @@ +/**************************************************************************** + * arch/arm/src/rtl8721f/hardware/ameba_memorymap.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_RTL8721F_HARDWARE_AMEBA_MEMORYMAP_H +#define __ARCH_ARM_SRC_RTL8721F_HARDWARE_AMEBA_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* RTL8721F memory map (from SDK + * component/soc/RTL8721F/project/ameba_layout.ld and + * fwlib/include/hal_platform.h). + * + * On-chip SRAM is 512 KiB: 0x2000_0000 .. 0x2008_0000 (secure alias at + * 0x3000_0000). Partitioned low->high: 8 KiB shared KM4TZ/KM4NS RAM, the + * KM4TZ IMG2 region (where NuttX runs), then the KM4NS IMG2 region + * (~184-192 KiB, the prebuilt NP/device image). + * + * NuttX runs on km4tz as IMG2. The heap is taken from the SDK image2 linker + * symbols __bdram_heap_buffer_start__/_size__ (see ameba_allocateheap.c), so + * the window below mainly feeds CONFIG_RAM_START/SIZE (kept in sync with the + * board defconfig). + */ + +/* Whole on-chip SRAM (secure alias base; km4tz runs in the secure world). */ + +#define AMEBA_SRAM_START 0x30000000 +#define AMEBA_SRAM_SIZE 0x00080000 /* 512 KiB */ + +/* km4tz IMG2 RAM window (matches board CONFIG_RAM_START/SIZE). */ + +#define PRIMARY_RAM_START 0x30008000 +#define PRIMARY_RAM_SIZE 0x00040000 +#define PRIMARY_RAM_END (PRIMARY_RAM_START + PRIMARY_RAM_SIZE) + +#endif /* __ARCH_ARM_SRC_RTL8721F_HARDWARE_AMEBA_MEMORYMAP_H */ diff --git a/boards/Kconfig b/boards/Kconfig index 5caafb33079bd..1357adcfa0b5b 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -2522,6 +2522,14 @@ config ARCH_BOARD_RTL8720F_EVB board featuring the Realtek RTL8720F (km4tz application/host core, Cortex-M33). +config ARCH_BOARD_RTL8721F_EVB + bool "Realtek RTL8721F_EVB" + depends on ARCH_CHIP_RTL8721F + ---help--- + This options selects support for NuttX on the RTL8721F_EVB + board featuring the Realtek RTL8721F (SDK codename Green2; + km4tz application/host core, Cortex-M33). + config ARCH_BOARD_SABRE_6QUAD bool "NXP/Freescale i.MX6 Sabre-6Quad board" depends on ARCH_CHIP_IMX6_6QUAD @@ -3982,6 +3990,7 @@ config ARCH_BOARD default "mps3-an547" if ARCH_BOARD_MPS3_AN547 default "pke8721daf" if ARCH_BOARD_PKE8721DAF default "rtl8720f_evb" if ARCH_BOARD_RTL8720F_EVB + default "rtl8721f_evb" if ARCH_BOARD_RTL8721F_EVB default "rv32m1-vega" if ARCH_BOARD_RV32M1_VEGA default "rv-virt" if ARCH_BOARD_QEMU_RV_VIRT default "star64" if ARCH_BOARD_JH7110_STAR64 @@ -4237,6 +4246,9 @@ endif if ARCH_BOARD_RTL8720F_EVB source "boards/arm/rtl8720f/rtl8720f_evb/Kconfig" endif +if ARCH_BOARD_RTL8721F_EVB +source "boards/arm/rtl8721f/rtl8721f_evb/Kconfig" +endif if ARCH_BOARD_QEMU_ARMV7A source "boards/arm/qemu/qemu-armv7a/Kconfig" endif diff --git a/boards/arm/rtl8721f/rtl8721f_evb/CMakeLists.txt b/boards/arm/rtl8721f/rtl8721f_evb/CMakeLists.txt new file mode 100644 index 0000000000000..dc460abfb4d15 --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/CMakeLists.txt @@ -0,0 +1,28 @@ +# ############################################################################## +# boards/arm/rtl8721f/rtl8721f_evb/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +# The vendor-SDK build machinery (SDK libs, image2 ld script, link flags and the +# nuttx.bin packaging POSTBUILD / nuttx_post_build target) is wired up from the +# shared arch/arm/src/common/ameba/cmake/ameba_board.cmake, included by this +# IC's arch CMakeLists. Nothing IC- or board-specific is needed here. + +add_subdirectory(src) diff --git a/boards/arm/rtl8721f/rtl8721f_evb/Kconfig b/boards/arm/rtl8721f/rtl8721f_evb/Kconfig new file mode 100644 index 0000000000000..4c026a5ab5c2f --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/Kconfig @@ -0,0 +1,7 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_RTL8721F_EVB +endif diff --git a/boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk.conf b/boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk.conf new file mode 100644 index 0000000000000..0d3485045d525 --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk.conf @@ -0,0 +1,10 @@ +# User-editable Ameba SDK options for this board (prj.conf-style, diff vs SDK +# default). Applied on top of the SDK default when building the NP / bootloader +# images; dependents cascade automatically via kconfiglib. +# +# Edit interactively with `make ameba_menuconfig` (writes the diff back here), +# or add CONFIG_* lines by hand. Picked up on the next build. +# +# Options that MUST stay at a fixed value (e.g. CONFIG_SHELL=n) live in +# ameba_sdk_force.conf, which is applied last and re-applied after the TUI +# saves -- so they cannot be overridden from here or the menuconfig UI. diff --git a/boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk_force.conf b/boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk_force.conf new file mode 100644 index 0000000000000..9e02a021a3077 --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/ameba_sdk_force.conf @@ -0,0 +1,11 @@ +# Forced Ameba SDK options for this board (prj.conf-style, diff vs SDK default). +# +# These are applied LAST -- after the SDK default and the user overlay +# (ameba_sdk.conf), on every build AND again after `make ameba_menuconfig` +# saves -- so they always win and cannot be turned on from the TUI. Use this +# file (not ameba_sdk.conf) for options that MUST stay at a fixed value for the +# port to work. +# +# CONFIG_SHELL: the SDK's NP-side shell conflicts with NuttX owning the +# LOG-UART console, so it must stay disabled. +CONFIG_SHELL=n diff --git a/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig b/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig new file mode 100644 index 0000000000000..7cba1fd8b1242 --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig @@ -0,0 +1,90 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_DEBUG_WARN is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="rtl8721f_evb" +CONFIG_ARCH_BOARD_RTL8721F_EVB=y +CONFIG_ARCH_CHIP="rtl8721f" +CONFIG_ARCH_CHIP_RTL8721F=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV8M_SYSTICK=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +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=262144 +CONFIG_RAM_START=0x30008000 +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 +CONFIG_SCHED_WAITPID=y +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 diff --git a/boards/arm/rtl8721f/rtl8721f_evb/include/board.h b/boards/arm/rtl8721f/rtl8721f_evb/include/board.h new file mode 100644 index 0000000000000..15f3c7d61f1d5 --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/include/board.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * boards/arm/rtl8721f/rtl8721f_evb/include/board.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_RTL8721F_RTL8721F_EVB_INCLUDE_BOARD_H +#define __BOARDS_ARM_RTL8721F_RTL8721F_EVB_INCLUDE_BOARD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The SysTick/core clock is taken from the SDK's SystemCoreClock global at + * runtime (see arch/arm/src/rtl8721f/ameba_timerisr.c), so no board-level + * clock constant is needed here. + */ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_RTL8721F_RTL8721F_EVB_INCLUDE_BOARD_H */ diff --git a/boards/arm/rtl8721f/rtl8721f_evb/prebuilt/.gitignore b/boards/arm/rtl8721f/rtl8721f_evb/prebuilt/.gitignore new file mode 100644 index 0000000000000..47ced693a46fb --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/prebuilt/.gitignore @@ -0,0 +1,22 @@ +# Realtek RTL8721F vendor blobs and build artefacts. +# +# These are NOT NuttX source and must never be committed upstream (vendor +# blobs are kept out of the NuttX tree). They are vendor outputs from the +# ameba-rtos SDK, placed here by the integrator: +# +# libs/*.a pre-compiled chip archives (fwlib/hal/swlib/misc/...) +# km4ns_image2_all.bin prebuilt NP (WiFi/LP core, km4ns) image2 blob +# platform_autoconf.h regenerated each build from the SDK menuconfig by +# ameba_gen_autoconf.sh (single source of truth) +# config_km4 / config_fw vendored SDK kconfig snapshots for axf2bin packaging +# +# Generated at build time: +# +# ld.script.gen[.tmp] combined image2 linker script +# project_km4tz/ staged include dir for ld preprocessing +# pkg/ axf2bin / firmware_package staging area +# +# Everything in this directory is ignored. + +* +!.gitignore diff --git a/boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs b/boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs new file mode 100644 index 0000000000000..e1a2bed186c5b --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs @@ -0,0 +1,33 @@ +############################################################################ +# boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +# All RTL8721F board-build definitions (SDK include sets, fwlib/WiFi source +# lists, image2 linker-script generation, PREBUILD/POSTBUILD) live in the +# shared per-IC fragment so every board on this IC uses one copy. This board's +# own paths (prebuilt/ staging) derive from $(BOARD_DIR) inside it. + +include $(TOPDIR)/arch/arm/src/rtl8721f/ameba_board.mk + +# Flashing via the SDK AmebaFlash.py (make flash AMEBA_PORT=/dev/ttyUSB0) + +AMEBA_FLASH_PROFILE = RTL8721F +include $(TOPDIR)/tools/ameba/Config.mk diff --git a/boards/arm/rtl8721f/rtl8721f_evb/src/CMakeLists.txt b/boards/arm/rtl8721f/rtl8721f_evb/src/CMakeLists.txt new file mode 100644 index 0000000000000..8738ce0a558aa --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/src/CMakeLists.txt @@ -0,0 +1,28 @@ +# ############################################################################## +# boards/arm/rtl8721f/rtl8721f_evb/src/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +set(SRCS rtl8721f_boot.c rtl8721f_bringup.c) + +target_sources(board PRIVATE ${SRCS}) + +# LD_SCRIPT is not set here: the Ameba image2 linker script is generated +# (prebuilt/ld.script.gen) and published by the shared ameba_board.cmake. diff --git a/boards/arm/rtl8721f/rtl8721f_evb/src/Makefile b/boards/arm/rtl8721f/rtl8721f_evb/src/Makefile new file mode 100644 index 0000000000000..d033b7a37bf02 --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/src/Makefile @@ -0,0 +1,27 @@ +############################################################################ +# boards/arm/rtl8721f/rtl8721f_evb/src/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +CSRCS = rtl8721f_boot.c rtl8721f_bringup.c + +include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_boot.c b/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_boot.c new file mode 100644 index 0000000000000..80b6c9be078a7 --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_boot.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_boot.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "rtl8721f_rtl8721f_evb.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtl8721f_boardinitialize + * + * Description: + * All RTL8721F architectures must provide the following entry point. + * This entry point is called early in the initialization -- after all + * memory has been configured and mapped but before any devices have been + * initialized. + * + ****************************************************************************/ + +void rtl8721f_boardinitialize(void) +{ + /* Board-specific early initialization. Nothing to do here. */ +} + +/**************************************************************************** + * Name: board_initialize + * + * Description: + * If CONFIG_BOARD_EARLY_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_initialize(). + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_EARLY_INITIALIZE +void board_early_initialize(void) +{ + rtl8721f_boardinitialize(); +} +#endif diff --git a/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_bringup.c b/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_bringup.c new file mode 100644 index 0000000000000..c08fcb2dcda4c --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_bringup.c @@ -0,0 +1,203 @@ +/**************************************************************************** + * boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_bringup.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "rtl8721f_rtl8721f_evb.h" + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* SDK ROM inter-core IPC-semaphore RTOS hooks. rtos_* come from the NuttX + * os_wrapper (ameba_os_wrap.c); IPC_* are SDK ROM symbols. + */ + +extern void rtos_critical_enter(uint32_t component_id); +extern void rtos_critical_exit(uint32_t component_id); +extern void rtos_time_delay_ms(uint32_t ms); +extern void IPC_patch_function(void (*enter)(uint32_t), + void (*leave)(uint32_t), uint32_t lock_id); +extern void IPC_SEMDelayStub(void (*delay)(uint32_t)); + +/* RTOS_CRITICAL_SEMA in the SDK os_wrapper_critical.h enum. Our + * rtos_critical_enter/exit ignore the component id, so the value is only + * passed through to satisfy the ROM signature. + */ + +#define AMEBA_RTOS_CRITICAL_SEMA 9 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rtl8721f_bringup + * + * Description: + * Bring up board features + * + ****************************************************************************/ + +int rtl8721f_bringup(void) +{ + int ret = 0; + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#ifdef CONFIG_FS_TMPFS + /* Mount the tmp file system */ + + ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount tmpfs at /tmp: %d\n", ret); + } +#endif + +#ifdef CONFIG_RTL8721F_FLASH_FS + /* Mount the persistent data filesystem (littlefs on the SPI NOR VFS1 + * partition) at /data before WiFi, so the WiFi KV store is available. + */ + + /* The SDK flash erase/program path IPC-pauses the NP (km4ns) while the AP + * writes the shared XIP flash, so the IPC transport must be up first. + */ + + ameba_ipc_initialize(); + + ret = ameba_flash_fs_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: ameba_flash_fs_initialize failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_RTL8721F_WIFI + /* Bring up the KM4 IPC transport and start the WHC host WiFi stack. */ + + ret = rtl8721f_wifi_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: rtl8721f_wifi_initialize failed: %d\n", ret); + } +#endif + + /* Install the inter-core HW IPC-semaphore RTOS hooks LAST -- after all the + * flash / WHC bring-up above, and just before this (board_late_initialize) + * path returns and nx_start() hands off to the init task. + * + * The shared-flash / WHC paths take the hardware IPC semaphore to + * serialize against the NP; the ROM semaphore code then calls an RTOS + * critical-section pair plus a delay callback while a contended waiter + * waits. That delay callback rtos_time_delay_ms() blocks, so it is only + * safe from a real task. Registering it here means the bring-up flash + * access above (which runs in this pre-task context) uses the ROM default + * (busy-spin, no callback), while every runtime IPC-semaphore user that + * follows runs in a task and yields properly. + */ + + IPC_patch_function(rtos_critical_enter, rtos_critical_exit, + AMEBA_RTOS_CRITICAL_SEMA); + IPC_SEMDelayStub(rtos_time_delay_ms); + + return ret; +} + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform application specific initialization. This function is never + * called directly from application code, but only indirectly via the + * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initialization logic and the + * matching application logic. The value could be such things as a + * mode enumeration value, a set of DIP switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARDCTL +int board_app_initialize(uintptr_t arg) +{ +#ifndef CONFIG_BOARD_LATE_INITIALIZE + /* Perform board initialization */ + + return rtl8721f_bringup(); +#else + return OK; +#endif +} +#endif /* CONFIG_BOARDCTL */ + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will + * be called immediately after up_initialize() is called and just before + * the initial application is started. This additional initialization + * phase may be used, for example, to initialize board-specific device + * drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board initialization */ + + rtl8721f_bringup(); +} +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ diff --git a/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_rtl8721f_evb.h b/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_rtl8721f_evb.h new file mode 100644 index 0000000000000..c1a6de69dee2b --- /dev/null +++ b/boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_rtl8721f_evb.h @@ -0,0 +1,100 @@ +/**************************************************************************** + * boards/arm/rtl8721f/rtl8721f_evb/src/rtl8721f_rtl8721f_evb.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_ARM_RTL8721F_RTL8721F_EVB_SRC_RTL8721F_RTL8721F_EVB_H +#define __BOARDS_ARM_RTL8721F_RTL8721F_EVB_SRC_RTL8721F_RTL8721F_EVB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Name: rtl8721f_boardinitialize + * + * Description: + * Perform board-specific early initialization. + * + ****************************************************************************/ + +void rtl8721f_boardinitialize(void); + +/**************************************************************************** + * Name: rtl8721f_bringup + * + * Description: + * Bring up board features. + * + ****************************************************************************/ + +int rtl8721f_bringup(void); + +#ifdef CONFIG_RTL8721F_WIFI +/**************************************************************************** + * Name: rtl8721f_wifi_initialize + * + * Description: + * Bring up the KM4 IPC transport and start the WHC host WiFi stack + * (arch/arm/src/rtl8721f/ameba_wifi_init.c). + * + ****************************************************************************/ + +int rtl8721f_wifi_initialize(void); +#endif + +#if defined(CONFIG_RTL8721F_FLASH_FS) || defined(CONFIG_RTL8721F_WIFI) +/**************************************************************************** + * Name: ameba_ipc_initialize + * + * Description: + * Bring up the km4tz<->km4ns IPC transport once (idempotent). Required by + * the SDK flash erase/program path (inter-core XIP pause) and by WiFi + * (arch/arm/src/rtl8721f/ameba_ipc.c). + * + ****************************************************************************/ + +void ameba_ipc_initialize(void); +#endif + +#ifdef CONFIG_RTL8721F_FLASH_FS +/**************************************************************************** + * Name: ameba_flash_fs_initialize + * + * Description: + * Register the on-chip SPI NOR data partition as an MTD device and mount + * a littlefs filesystem on it at /data + * (arch/arm/src/rtl8721f/ameba_flash_mtd.c). + * + ****************************************************************************/ + +int ameba_flash_fs_initialize(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_ARM_RTL8721F_RTL8721F_EVB_SRC_RTL8721F_RTL8721F_EVB_H */ From e974be69259b8f9405a33be4ae70c8bbdd97c52f Mon Sep 17 00:00:00 2001 From: dechao_gong Date: Mon, 27 Jul 2026 17:36:42 +0800 Subject: [PATCH 2/4] arch/arm/rtl8721f: bring up minimal NSH (P1) Wire the RTL8721F km4tz core up to a working NuttShell: - irq.h: renumber the KM4TZ external vector table to the RTL8721F APIRQn map (UART_LOG=24, IPC=5, +GPIOB/C, TIMER7/8, ...). - ameba_loguart.c: fix the LOG-UART base to 0x40810000. The former 0x401C6000 belongs to a different Ameba part; the wrong base bus- faulted on the RX interrupt-enable write while TX still worked (LOGUART_PutChar uses its own ROM-internal base). - ameba_app_start.c: adjust the MPU read-only / RAM regions for the RTL8721F memory map and seed the RTC on first power-on so the SDM32K-clocked SYSTIMER comes up (mirrors the SDK app_rtc_init). - ameba_ipc.c: move the km4tz<->km4ns IPC to APIRQn 5 (IPC_CPU0). - ameba_board.mk: pull in fwlib ameba_rtc.c for the RTC_* symbols. - defconfig: RTL8721F RAM map, enable TIMER/TIMER_ARCH/ARMV8M_SYSTICK for a live system tick, and drop the WiFi/NET stack for now. - scripts/Make.defs: use the RTL8721F_NOR flash profile. Boots cleanly to nsh> on hardware; tick, RX and builtin apps verified. Signed-off-by: dechao_gong --- arch/arm/include/rtl8721f/irq.h | 149 ++++++++++-------- arch/arm/src/rtl8721f/ameba_app_start.c | 53 ++++++- arch/arm/src/rtl8721f/ameba_board.mk | 1 + arch/arm/src/rtl8721f/ameba_ipc.c | 2 +- arch/arm/src/rtl8721f/ameba_loguart.c | 16 +- .../rtl8721f_evb/configs/nsh/defconfig | 46 +----- .../rtl8721f/rtl8721f_evb/scripts/Make.defs | 2 +- tools/nxstyle.c | 7 +- 8 files changed, 155 insertions(+), 121 deletions(-) diff --git a/arch/arm/include/rtl8721f/irq.h b/arch/arm/include/rtl8721f/irq.h index 5210d2529a7ca..8e377a31c2c41 100644 --- a/arch/arm/include/rtl8721f/irq.h +++ b/arch/arm/include/rtl8721f/irq.h @@ -55,73 +55,96 @@ #define RTL8721F_IRQ_FIRST (16) /* Vector number of the first external * interrupt */ -/* External interrupts (vectors >= 16). These map to the RTL8721F km4tz - * (AP / host) peripheral interrupt vector numbers (APIRQn, 0..57) as defined - * by the SDK's component/soc/RTL8721F/fwlib/include/ameba_vector_table.h - * (CONFIG_ARM_CORE_CM4_KM4TZ branch). +/* External interrupts (vectors >= 16). These map to the amebagreen2 km4tz + * (AP / host) peripheral interrupt vector numbers (APIRQn, 0..78) as defined + * by the SDK's + * component/soc/amebagreen2/fwlib/include/ameba_vector_table.h + * (CONFIG_ARM_CORE_CM4_KM4TZ branch). NOTE: this numbering differs from the + * RTL8721Dx / RTL8720F -- e.g. UART_LOG is 24 (not 17) and IPC is 5 (not 3). */ #define RTL8721F_IRQ_WIFI_FISR_FESR (RTL8721F_IRQ_FIRST + 0) -#define RTL8721F_IRQ_WL_PROTOCOL (RTL8721F_IRQ_FIRST + 1) -#define RTL8721F_IRQ_AP_WAKE (RTL8721F_IRQ_FIRST + 2) -#define RTL8721F_IRQ_IPC_KM4 (RTL8721F_IRQ_FIRST + 3) /* IPC_KM4TZ */ -#define RTL8721F_IRQ_IWDG (RTL8721F_IRQ_FIRST + 4) -#define RTL8721F_IRQ_TIMER0 (RTL8721F_IRQ_FIRST + 5) -#define RTL8721F_IRQ_TIMER1 (RTL8721F_IRQ_FIRST + 6) -#define RTL8721F_IRQ_TIMER2 (RTL8721F_IRQ_FIRST + 7) -#define RTL8721F_IRQ_TIMER3 (RTL8721F_IRQ_FIRST + 8) -#define RTL8721F_IRQ_TIMER4 (RTL8721F_IRQ_FIRST + 9) -#define RTL8721F_IRQ_TIMER5 (RTL8721F_IRQ_FIRST + 10) -#define RTL8721F_IRQ_TIMER6 (RTL8721F_IRQ_FIRST + 11) -#define RTL8721F_IRQ_PMC_TIMER0 (RTL8721F_IRQ_FIRST + 12) -#define RTL8721F_IRQ_PMC_TIMER1 (RTL8721F_IRQ_FIRST + 13) -#define RTL8721F_IRQ_UART0 (RTL8721F_IRQ_FIRST + 14) -#define RTL8721F_IRQ_UART1 (RTL8721F_IRQ_FIRST + 15) -#define RTL8721F_IRQ_UART2 (RTL8721F_IRQ_FIRST + 16) -#define RTL8721F_IRQ_UART_LOG (RTL8721F_IRQ_FIRST + 17) -#define RTL8721F_IRQ_GPIOA (RTL8721F_IRQ_FIRST + 18) -#define RTL8721F_IRQ_RSVD (RTL8721F_IRQ_FIRST + 19) -#define RTL8721F_IRQ_I2C0 (RTL8721F_IRQ_FIRST + 20) -#define RTL8721F_IRQ_I2C1 (RTL8721F_IRQ_FIRST + 21) -#define RTL8721F_IRQ_GDMA0_CH0 (RTL8721F_IRQ_FIRST + 22) -#define RTL8721F_IRQ_GDMA0_CH1 (RTL8721F_IRQ_FIRST + 23) -#define RTL8721F_IRQ_GDMA0_CH2 (RTL8721F_IRQ_FIRST + 24) -#define RTL8721F_IRQ_GDMA0_CH3 (RTL8721F_IRQ_FIRST + 25) -#define RTL8721F_IRQ_GDMA0_CH4 (RTL8721F_IRQ_FIRST + 26) -#define RTL8721F_IRQ_GDMA0_CH5 (RTL8721F_IRQ_FIRST + 27) -#define RTL8721F_IRQ_GDMA0_CH6 (RTL8721F_IRQ_FIRST + 28) -#define RTL8721F_IRQ_GDMA0_CH7 (RTL8721F_IRQ_FIRST + 29) -#define RTL8721F_IRQ_SPI0 (RTL8721F_IRQ_FIRST + 30) -#define RTL8721F_IRQ_SPI1 (RTL8721F_IRQ_FIRST + 31) -#define RTL8721F_IRQ_SPORT (RTL8721F_IRQ_FIRST + 32) -#define RTL8721F_IRQ_RTC (RTL8721F_IRQ_FIRST + 33) -#define RTL8721F_IRQ_ADC (RTL8721F_IRQ_FIRST + 34) -#define RTL8721F_IRQ_BOR (RTL8721F_IRQ_FIRST + 35) -#define RTL8721F_IRQ_PWR_DOWN (RTL8721F_IRQ_FIRST + 36) -#define RTL8721F_IRQ_PKE (RTL8721F_IRQ_FIRST + 37) -#define RTL8721F_IRQ_TRNG (RTL8721F_IRQ_FIRST + 38) -#define RTL8721F_IRQ_AON_TIM (RTL8721F_IRQ_FIRST + 39) -#define RTL8721F_IRQ_AON_WAKEPIN (RTL8721F_IRQ_FIRST + 40) -#define RTL8721F_IRQ_SDIO_WIFI (RTL8721F_IRQ_FIRST + 41) -#define RTL8721F_IRQ_SDIO_BT (RTL8721F_IRQ_FIRST + 42) -#define RTL8721F_IRQ_RXI300 (RTL8721F_IRQ_FIRST + 43) -#define RTL8721F_IRQ_PSRAMC (RTL8721F_IRQ_FIRST + 44) -#define RTL8721F_IRQ_SPI_FLASH (RTL8721F_IRQ_FIRST + 45) -#define RTL8721F_IRQ_RSIP (RTL8721F_IRQ_FIRST + 46) -#define RTL8721F_IRQ_AES (RTL8721F_IRQ_FIRST + 47) -#define RTL8721F_IRQ_SHA (RTL8721F_IRQ_FIRST + 48) -#define RTL8721F_IRQ_AES_S (RTL8721F_IRQ_FIRST + 49) -#define RTL8721F_IRQ_SHA_S (RTL8721F_IRQ_FIRST + 50) -#define RTL8721F_IRQ_KM4NS_WDG_RST (RTL8721F_IRQ_FIRST + 51) -#define RTL8721F_IRQ_KM4TZ_NS_WDG (RTL8721F_IRQ_FIRST + 52) -#define RTL8721F_IRQ_KM4TZ_S_WDG (RTL8721F_IRQ_FIRST + 53) -#define RTL8721F_IRQ_OCP (RTL8721F_IRQ_FIRST + 54) -#define RTL8721F_IRQ_BT_CTRL_HIGH (RTL8721F_IRQ_FIRST + 55) -#define RTL8721F_IRQ_BT_CTRL_LOW (RTL8721F_IRQ_FIRST + 56) -#define RTL8721F_IRQ_IR (RTL8721F_IRQ_FIRST + 57) +#define RTL8721F_IRQ_WIFI_FTSR_MBOX (RTL8721F_IRQ_FIRST + 1) +#define RTL8721F_IRQ_WL_DMA (RTL8721F_IRQ_FIRST + 2) +#define RTL8721F_IRQ_WL_PROTOCOL (RTL8721F_IRQ_FIRST + 3) +#define RTL8721F_IRQ_AP_WAKE (RTL8721F_IRQ_FIRST + 4) +#define RTL8721F_IRQ_IPC_KM4 (RTL8721F_IRQ_FIRST + 5) /* IPC_CPU0 */ +#define RTL8721F_IRQ_IWDG (RTL8721F_IRQ_FIRST + 6) +#define RTL8721F_IRQ_TIMER0 (RTL8721F_IRQ_FIRST + 7) +#define RTL8721F_IRQ_TIMER1 (RTL8721F_IRQ_FIRST + 8) +#define RTL8721F_IRQ_TIMER2 (RTL8721F_IRQ_FIRST + 9) +#define RTL8721F_IRQ_TIMER3 (RTL8721F_IRQ_FIRST + 10) +#define RTL8721F_IRQ_TIMER4 (RTL8721F_IRQ_FIRST + 11) +#define RTL8721F_IRQ_TIMER5 (RTL8721F_IRQ_FIRST + 12) +#define RTL8721F_IRQ_TIMER6 (RTL8721F_IRQ_FIRST + 13) +#define RTL8721F_IRQ_TIMER7 (RTL8721F_IRQ_FIRST + 14) +#define RTL8721F_IRQ_TIMER8 (RTL8721F_IRQ_FIRST + 15) +#define RTL8721F_IRQ_COEX_MAILBOX (RTL8721F_IRQ_FIRST + 16) +#define RTL8721F_IRQ_RSVD (RTL8721F_IRQ_FIRST + 17) +#define RTL8721F_IRQ_PMC_TIMER0 (RTL8721F_IRQ_FIRST + 18) +#define RTL8721F_IRQ_PMC_TIMER1 (RTL8721F_IRQ_FIRST + 19) +#define RTL8721F_IRQ_UART0 (RTL8721F_IRQ_FIRST + 20) +#define RTL8721F_IRQ_UART1 (RTL8721F_IRQ_FIRST + 21) +#define RTL8721F_IRQ_UART2 (RTL8721F_IRQ_FIRST + 22) +#define RTL8721F_IRQ_UART3 (RTL8721F_IRQ_FIRST + 23) +#define RTL8721F_IRQ_UART_LOG (RTL8721F_IRQ_FIRST + 24) +#define RTL8721F_IRQ_GPIOA (RTL8721F_IRQ_FIRST + 25) +#define RTL8721F_IRQ_GPIOB (RTL8721F_IRQ_FIRST + 26) +#define RTL8721F_IRQ_GPIOC (RTL8721F_IRQ_FIRST + 27) +#define RTL8721F_IRQ_I2C0 (RTL8721F_IRQ_FIRST + 28) +#define RTL8721F_IRQ_I2C1 (RTL8721F_IRQ_FIRST + 29) +#define RTL8721F_IRQ_GDMA0_CH0 (RTL8721F_IRQ_FIRST + 30) +#define RTL8721F_IRQ_GDMA0_CH1 (RTL8721F_IRQ_FIRST + 31) +#define RTL8721F_IRQ_GDMA0_CH2 (RTL8721F_IRQ_FIRST + 32) +#define RTL8721F_IRQ_GDMA0_CH3 (RTL8721F_IRQ_FIRST + 33) +#define RTL8721F_IRQ_GDMA0_CH4 (RTL8721F_IRQ_FIRST + 34) +#define RTL8721F_IRQ_GDMA0_CH5 (RTL8721F_IRQ_FIRST + 35) +#define RTL8721F_IRQ_GDMA0_CH6 (RTL8721F_IRQ_FIRST + 36) +#define RTL8721F_IRQ_GDMA0_CH7 (RTL8721F_IRQ_FIRST + 37) +#define RTL8721F_IRQ_SPI0 (RTL8721F_IRQ_FIRST + 38) +#define RTL8721F_IRQ_SPI1 (RTL8721F_IRQ_FIRST + 39) +#define RTL8721F_IRQ_SPORT0 (RTL8721F_IRQ_FIRST + 40) +#define RTL8721F_IRQ_RTC (RTL8721F_IRQ_FIRST + 41) +#define RTL8721F_IRQ_ADC (RTL8721F_IRQ_FIRST + 42) +#define RTL8721F_IRQ_ADC_COMP (RTL8721F_IRQ_FIRST + 43) +#define RTL8721F_IRQ_CAPTOUCH (RTL8721F_IRQ_FIRST + 44) +#define RTL8721F_IRQ_THERMAL (RTL8721F_IRQ_FIRST + 45) +#define RTL8721F_IRQ_BOR (RTL8721F_IRQ_FIRST + 46) +#define RTL8721F_IRQ_PWR_DOWN (RTL8721F_IRQ_FIRST + 47) +#define RTL8721F_IRQ_RMII (RTL8721F_IRQ_FIRST + 48) +#define RTL8721F_IRQ_LCDC (RTL8721F_IRQ_FIRST + 49) +#define RTL8721F_IRQ_MJPEG (RTL8721F_IRQ_FIRST + 50) +#define RTL8721F_IRQ_PPE (RTL8721F_IRQ_FIRST + 51) +#define RTL8721F_IRQ_PKE (RTL8721F_IRQ_FIRST + 52) +#define RTL8721F_IRQ_TRNG (RTL8721F_IRQ_FIRST + 53) +#define RTL8721F_IRQ_AON_TIM (RTL8721F_IRQ_FIRST + 54) +#define RTL8721F_IRQ_AON_WAKEPIN (RTL8721F_IRQ_FIRST + 55) +#define RTL8721F_IRQ_SDIO_WIFI (RTL8721F_IRQ_FIRST + 56) +#define RTL8721F_IRQ_SDIO_BT (RTL8721F_IRQ_FIRST + 57) +#define RTL8721F_IRQ_SDIO_HOST (RTL8721F_IRQ_FIRST + 58) +#define RTL8721F_IRQ_USB (RTL8721F_IRQ_FIRST + 59) +#define RTL8721F_IRQ_CAN0 (RTL8721F_IRQ_FIRST + 60) +#define RTL8721F_IRQ_CAN1 (RTL8721F_IRQ_FIRST + 61) +#define RTL8721F_IRQ_IR (RTL8721F_IRQ_FIRST + 62) +#define RTL8721F_IRQ_RXI300 (RTL8721F_IRQ_FIRST + 63) +#define RTL8721F_IRQ_PSRAMC (RTL8721F_IRQ_FIRST + 64) +#define RTL8721F_IRQ_SPI_FLASH (RTL8721F_IRQ_FIRST + 65) +#define RTL8721F_IRQ_RSIP (RTL8721F_IRQ_FIRST + 66) +#define RTL8721F_IRQ_AES (RTL8721F_IRQ_FIRST + 67) +#define RTL8721F_IRQ_SHA (RTL8721F_IRQ_FIRST + 68) +#define RTL8721F_IRQ_CPU0_NS_WDG (RTL8721F_IRQ_FIRST + 69) +#define RTL8721F_IRQ_CPU0_S_WDG (RTL8721F_IRQ_FIRST + 70) +#define RTL8721F_IRQ_OCP (RTL8721F_IRQ_FIRST + 71) +#define RTL8721F_IRQ_SPIC_ECC (RTL8721F_IRQ_FIRST + 72) +#define RTL8721F_IRQ_UVC_DEC (RTL8721F_IRQ_FIRST + 73) +#define RTL8721F_IRQ_RTC_DET (RTL8721F_IRQ_FIRST + 74) +#define RTL8721F_IRQ_BT_MAILBOX (RTL8721F_IRQ_FIRST + 75) +#define RTL8721F_IRQ_BT_SCB (RTL8721F_IRQ_FIRST + 76) +#define RTL8721F_IRQ_BT_WAKE_HOST (RTL8721F_IRQ_FIRST + 77) +#define RTL8721F_IRQ_CPU1_WDG_RST (RTL8721F_IRQ_FIRST + 78) -#define RTL8721F_IRQ_NEXTINT (58) /* Number of external interrupts - * (APIRQn PERI_IRQ_MAX) */ +#define RTL8721F_IRQ_NEXTINT (79) /* Number of external interrupts + * (APIRQn count, 0..78) */ #define NR_IRQS (RTL8721F_IRQ_FIRST + RTL8721F_IRQ_NEXTINT) diff --git a/arch/arm/src/rtl8721f/ameba_app_start.c b/arch/arm/src/rtl8721f/ameba_app_start.c index ed50e532a44a4..0b9170fa227b7 100644 --- a/arch/arm/src/rtl8721f/ameba_app_start.c +++ b/arch/arm/src/rtl8721f/ameba_app_start.c @@ -95,7 +95,7 @@ u32 app_mpu_nocache_init(void) mpu_entry = mpu_entry_alloc(); mpu_cfg.region_base = 0; - mpu_cfg.region_size = 0x000F0000; + mpu_cfg.region_size = 0x000f0000; mpu_cfg.xn = MPU_EXEC_ALLOW; mpu_cfg.ap = MPU_UN_PRIV_RO; mpu_cfg.sh = MPU_NON_SHAREABLE; @@ -177,6 +177,25 @@ void os_init(void) rtos_mem_init(); } +/* Seed the RTC on first power-on (mirrors the SDK app_rtc_init). */ + +void app_rtc_init(void) +{ + RTC_InitTypeDef rtc_initstruct; + RTC_TimeTypeDef rtc_timestruct; + + RTC_TimeStructInit(&rtc_timestruct); + rtc_timestruct.RTC_Year = 2021; + rtc_timestruct.RTC_Hours = 10; + rtc_timestruct.RTC_Minutes = 20; + rtc_timestruct.RTC_Seconds = 30; + + RTC_StructInit(&rtc_initstruct); + RTC_Enable(ENABLE); + RTC_Init(&rtc_initstruct); + RTC_SetTime(RTC_Format_BIN, &rtc_timestruct); +} + /* The image2 application entry point. */ void app_start(void) @@ -226,8 +245,6 @@ void app_start(void) } } - SYSTIMER_Init(); - /* Low-power pins do not need pinmap init again after wake from dslp. */ pinmap_init(); @@ -235,6 +252,36 @@ void app_start(void) mpu_init(); app_mpu_nocache_init(); + /* Green2's system timer is clocked from SDM32K and needs the RTC + * brought up first. The SDK does the first-power-on half of this + * asynchronously from + * the RTC_DET_IRQ handler (rtc_irq_init), but NuttX replaces the vector + * table immediately after app_start so that deferred handler would never + * run -- do the whole sequence synchronously here instead. + */ + + RTC_ClearDetINT(); + SDM32K_Enable(); + SYSTIMER_Init(); + RCC_PeriphClockCmd(NULL, APBPeriph_RTC_CLOCK, ENABLE); + + if ((Get_OSC131_STATE() & RTC_BIT_FIRST_PON) == 0) + { + app_rtc_init(); + Set_OSC131_STATE(Get_OSC131_STATE() | RTC_BIT_FIRST_PON); + + /* Only ASIC needs OSC131K calibration (cke_rtc enabled just above). */ + + if (SYSCFG_CHIPType_Get() == CHIP_TYPE_ASIC_POSTSIM) + { + OSC131K_Calibration(30000); + } + } + + /* SDM32K clock-source switch must be done after rtc_fen is enabled. */ + + RTC_ClkSource_Select(SDM32K); + main(); } diff --git a/arch/arm/src/rtl8721f/ameba_board.mk b/arch/arm/src/rtl8721f/ameba_board.mk index 3bb9f3ab98a62..3b60aaef5cc1c 100644 --- a/arch/arm/src/rtl8721f/ameba_board.mk +++ b/arch/arm/src/rtl8721f/ameba_board.mk @@ -114,6 +114,7 @@ AMEBA_FWLIB_SRCS = $(AMEBA_SOC)/fwlib/ram_common/ameba_arch.c \ # so the fwlib sources it pulls in are listed alongside it. AMEBA_FWLIB_SRCS += $(TOPDIR)/arch/arm/src/rtl8721f/ameba_app_start.c \ $(AMEBA_SOC)/fwlib/ram_common/ameba_mpu_ram.c \ + $(AMEBA_SOC)/fwlib/ram_common/ameba_rtc.c \ $(AMEBA_SOC)/fwlib/ram_km4tz/ameba_data_flashclk.c \ $(AMEBA_SOC)/fwlib/ram_km4tz/ameba_flashclk.c \ $(AMEBA_SOC)/fwlib/ram_km4tz/ameba_pinmap.c \ diff --git a/arch/arm/src/rtl8721f/ameba_ipc.c b/arch/arm/src/rtl8721f/ameba_ipc.c index ca6a98dcf3baf..a3cc7a6330664 100644 --- a/arch/arm/src/rtl8721f/ameba_ipc.c +++ b/arch/arm/src/rtl8721f/ameba_ipc.c @@ -70,7 +70,7 @@ * 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). - * RTL8721F_IRQ_IPC_KM4 maps to APIRQn IPC_KM4TZ_IRQ (external vector 3) -- + * RTL8721F_IRQ_IPC_KM4 maps to APIRQn IPC_CPU0_IRQ (external vector 5) -- * see arch/.../irq.h. */ diff --git a/arch/arm/src/rtl8721f/ameba_loguart.c b/arch/arm/src/rtl8721f/ameba_loguart.c index ca7eb26a675ad..8780f8116097a 100644 --- a/arch/arm/src/rtl8721f/ameba_loguart.c +++ b/arch/arm/src/rtl8721f/ameba_loguart.c @@ -77,16 +77,16 @@ #define AMEBA_ENABLE 1 #define AMEBA_DISABLE 0 -/* LOG-UART device base (UARTLOG_REG_BASE, from SDK RTL8721F - * hal_platform.h). NOTE: this is the RTL8721F address (0x401C6000) -- it - * differs from the RTL8721Dx LOG-UART (0x4100F000). Only - * LOGUART_INTConfig()/INTCoreConfig() take this base explicitly; the TX - * path (DiagPrintf/LOGUART_PutChar) is a ROM call with its own internal - * base, which is why TX worked even when this was wrong but configuring - * the RX interrupt bus-faulted. +/* LOG-UART device base (UARTLOG_REG_BASE, from SDK amebagreen2 + * hal_platform.h). Only LOGUART_INTConfig()/INTCoreConfig()/RxCmd() take + * this base explicitly; the TX path (DiagPrintf/LOGUART_PutChar) is a ROM + * call with its own internal base. Using the wrong base (e.g. the + * RTL8721Dx 0x401C6000) leaves TX working -- because PutChar ignores it -- + * while writing the RX interrupt-enable register bus-faults, since the + * bogus IER address decodes to no bus slave on green2. */ -#define LOGUART_DEV ((void *)0x401C6000) +#define LOGUART_DEV ((void *)0x40810000) /*************************************************************************** * External ROM/SDK Function Prototypes diff --git a/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig b/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig index 7cba1fd8b1242..4477ec6ecbe80 100644 --- a/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig +++ b/boards/arm/rtl8721f/rtl8721f_evb/configs/nsh/defconfig @@ -20,56 +20,19 @@ 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=262144 -CONFIG_RAM_START=0x30008000 +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 @@ -78,13 +41,8 @@ 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 diff --git a/boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs b/boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs index e1a2bed186c5b..e53fd7b9a4074 100644 --- a/boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs +++ b/boards/arm/rtl8721f/rtl8721f_evb/scripts/Make.defs @@ -29,5 +29,5 @@ include $(TOPDIR)/arch/arm/src/rtl8721f/ameba_board.mk # Flashing via the SDK AmebaFlash.py (make flash AMEBA_PORT=/dev/ttyUSB0) -AMEBA_FLASH_PROFILE = RTL8721F +AMEBA_FLASH_PROFILE = RTL8721F_NOR include $(TOPDIR)/tools/ameba/Config.mk diff --git a/tools/nxstyle.c b/tools/nxstyle.c index e471d0641270a..2e9ae212af8ae 100644 --- a/tools/nxstyle.c +++ b/tools/nxstyle.c @@ -259,7 +259,7 @@ static const char *g_white_prefix[] = "uxrCustom", /* uxrCustomTransport */ /* Ref: arch/arm/src/common/ameba, arch/arm/src/rtl8721dx, - * arch/arm/src/rtl8720f and the matching boards. + * arch/arm/src/rtl8720f, arch/arm/src/rtl8721f and the matching boards. * Realtek Ameba SDK ROM/HAL symbols and ARM CMSE intrinsics referenced * by the port; renaming them would break linkage against the vendor blob. */ @@ -271,8 +271,10 @@ static const char *g_white_prefix[] = "Cache_", "DCache_", "ChipInfo_", + "EFUSE_", "FLASH_", "GPIO_", + "Get_OSC131_", /* Get_OSC131_STATE — Ameba SDK RTC accessor */ "IPC_", "LOGUART_", "OSC2M_", @@ -281,7 +283,10 @@ static const char *g_white_prefix[] = "PAD_", "Pinmux_", "RCC_", + "RTC_", /* RTC_InitTypeDef, RTC_Enable, RTC_SetTime, etc. */ "RTCIO_", + "SDM32K_", /* SDM32K_Enable */ + "Set_OSC131_", /* Set_OSC131_STATE — Ameba SDK RTC accessor */ "SYSCFG_", "SYSTIMER_", "UART_", From 8300e09224afcf85e2ce0ce236cdb9b0197e0334 Mon Sep 17 00:00:00 2001 From: dechao_gong Date: Mon, 27 Jul 2026 19:07:20 +0800 Subject: [PATCH 3/4] 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 63c6e5659f25b..1afb0898885aa 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 3b60aaef5cc1c..c29d51e1a1ef8 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 a3cc7a6330664..be63696d42834 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 4477ec6ecbe80..abfacc8a80ef9 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 From e460ad9a1f0361044d6ed27c92fdb8b4be5b27a6 Mon Sep 17 00:00:00 2001 From: dechao_gong Date: Tue, 28 Jul 2026 17:59:17 +0800 Subject: [PATCH 4/4] Documentation/rtl8721f: add RTL8721F platform and EVB board pages Add platform documentation for the Realtek RTL8721F: a chip overview page and the rtl8721f_evb board page, modelled on the existing RTL8720F / RTL8721Dx docs. The platform index picks them up automatically via its */index glob. The pages cover the vendor-SDK/toolchain dependency, the make and CMake build/flash flow, and the hardware-verified features: NSH over the LOG-UART console, littlefs at /data on the on-chip NOR flash, Wi-Fi station and SoftAP via the wapi tool, and the DHCP client/server. Signed-off-by: dechao_gong Co-Authored-By: Claude --- .../rtl8721f/boards/rtl8721f_evb/index.rst | 85 +++++++++++ .../platforms/arm/rtl8721f/index.rst | 144 ++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 Documentation/platforms/arm/rtl8721f/boards/rtl8721f_evb/index.rst create mode 100644 Documentation/platforms/arm/rtl8721f/index.rst diff --git a/Documentation/platforms/arm/rtl8721f/boards/rtl8721f_evb/index.rst b/Documentation/platforms/arm/rtl8721f/boards/rtl8721f_evb/index.rst new file mode 100644 index 0000000000000..b1f348cd5f60a --- /dev/null +++ b/Documentation/platforms/arm/rtl8721f/boards/rtl8721f_evb/index.rst @@ -0,0 +1,85 @@ +============ +RTL8721F EVB +============ + +.. tags:: chip:rtl8721f, arch:arm, vendor:realtek + +.. todo:: + + Add a photo of the RTL8721F EVB board here as ``rtl8721f_evb.png`` in this + directory, referenced with a ``.. figure::`` directive. + +The RTL8721F EVB is a Realtek RTL8721F evaluation board. NuttX runs on the +KM4TZ application core — an Arm Cortex-M55-compatible core running at up to +320 MHz. See the :doc:`RTL8721F chip documentation <../../index>` for the +full SoC specifications and the vendor-SDK dependency. + +Features +======== + +* RTL8721F: Arm Cortex-M55-compatible KM4TZ core up to 320 MHz, + 512 KB SRAM, 4 MB NOR flash +* Wi-Fi 6 (802.11 a/b/g/n/ax), dual-band 2.4/5 GHz station and SoftAP +* SPI NOR flash (XIP) +* LOG-UART console + +Supported in this NuttX port: + +* NSH shell over the LOG-UART console +* littlefs persistent storage mounted at ``/data`` (a dedicated SPI NOR flash + partition) +* Wi-Fi station and SoftAP through the ``wapi`` tool +* DHCP client (STA) and DHCP server (SoftAP) + +Buttons and LEDs +================ + +This NuttX port does not wire any user buttons or LEDs. + +Configurations +============== + +Build and flash any of these per the :doc:`RTL8721F build instructions +<../../index>`; for the CMake build, source ``. tools/ameba/env.sh +rtl8721f_evb`` first (the make build needs no sourcing). + +.. code:: console + + $ ./tools/configure.sh rtl8721f_evb: + +nsh +--- + +Networking-enabled NSH with littlefs at ``/data`` and the ``wapi`` Wi-Fi tool. +The console is the LOG-UART at 1500000 8N1 (the rate is configured by the +bootloader and inherited by NuttX). The Wi-Fi examples below are available from +this configuration. + +Wi-Fi +===== + +Station (connect to an AP):: + + nsh> wapi psk wlan0 3 + nsh> wapi essid wlan0 1 + nsh> renew wlan0 + +SoftAP (become an access point, with a DHCP server for clients):: + + nsh> wapi mode wlan0 3 + nsh> wapi psk wlan0 3 + nsh> wapi essid wlan0 1 + nsh> ifconfig wlan0 192.168.4.1 netmask 255.255.255.0 + nsh> dhcpd_start wlan0 + +Stop the SoftAP with ``wapi essid wlan0 0``. + +License Exceptions +================== + +This board depends on Realtek vendor code that is not part of NuttX and is +subject to its own license: + +* The prebuilt Wi-Fi / Bluetooth firmware image and the Realtek ``ameba-rtos`` + SDK libraries/headers linked into the image. See the SDK's own license; the + SDK is auto-fetched and is not redistributed in the NuttX tree. diff --git a/Documentation/platforms/arm/rtl8721f/index.rst b/Documentation/platforms/arm/rtl8721f/index.rst new file mode 100644 index 0000000000000..945940e4d0bb8 --- /dev/null +++ b/Documentation/platforms/arm/rtl8721f/index.rst @@ -0,0 +1,144 @@ +================ +Realtek RTL8721F +================ + +The Realtek RTL8721F is a low-power multi-protocol wireless SoC from the +Realtek Ameba IoT family, combining dual-band (2.4/5 GHz) Wi-Fi 6 and +Bluetooth LE connectivity. + +NuttX runs on the **KM4TZ application core** — an Arm Cortex-M55-compatible +core (Real-M300, Armv8.1-M) running at up to **320 MHz**, with Arm +TrustZone-M. The image is built soft-float. + +Highlights +========== + +- **CPU:** Arm Cortex-M55-compatible KM4TZ application core, up to 320 MHz, + with TrustZone-M and instruction/data caches; the image is built soft-float. +- **Memory:** 512 KB on-chip SRAM; external QSPI NOR flash (up to 104 MHz) + and/or DDR PSRAM (up to 200 MHz), depending on the part number. +- **Wireless:** Wi-Fi 6 (802.11 a/b/g/n/ax), dual-band 2.4/5 GHz, up to + 114.7 Mbps, WPA/WPA2/WPA3; Bluetooth LE 5.x. +- **Peripherals:** UART, SPI, I2C, I2S, SDIO, ADC, IR, CAN, RTC and + watchdogs (count varies by package). +- **Security:** Secure Boot, TrustZone-M, AES/SHA and ECDSA/RSA crypto + engines, Flash decryption, OTP, and a true random number generator. +- **Package:** QFN48, QFN68 or QFN100 (varies by part number). + +Memory +====== + +============ ============= ======= +Block Start Address Length +============ ============= ======= +SRAM 0x2000_0000 512 KB +============ ============= ======= + +The on-chip SRAM holds the system heap and application. The flash is an SPI +NOR accessed through the SDK XIP path. The exact flash / PSRAM size depends on +the part number. + +Vendor SDK and Toolchain +======================== + +The build depends on Realtek's open ``ameba-rtos`` SDK and its matching +``arm-none-eabi`` toolchain (from the Realtek asdk release), neither of which is +part of the NuttX tree. The SDK provides the Wi-Fi / Bluetooth firmware and the +low-level chip libraries; NuttX links its own libc / libm and reuses the SDK's +``app_start()`` as the image entry point. + +Both are fetched automatically — there is nothing to install by hand: + +- **make** fetches them on the first ``make`` (from its ``PREBUILD`` step). +- **CMake** fetches them when you source ``. tools/ameba/env.sh ``, which + must run before ``cmake`` (CMake probes the compiler at configure time). The + make build resolves everything on demand, so it needs no sourcing. + +The SDK is a shallow ``git clone`` of the pinned revision of +``https://github.com/Ameba-AIoT/ameba-rtos.git`` into +``arch/arm/src/common/ameba/ameba-rtos`` (git-ignored) and is built unmodified; +export ``AMEBA_SDK`` to use a local checkout instead. The asdk version is +pinned **per IC** by the SDK, so different Ameba ICs may use different toolchain +versions — the build selects the matching one automatically. + +Building and Flashing +===================== + +Replace ```` below with an actual board (e.g. ``rtl8721f_evb``) and +```` with one of its configurations. The first build fetches the SDK +and toolchain (see `Vendor SDK and Toolchain`_). + +With make +--------- + +.. code:: console + + $ ./tools/configure.sh : + $ make + +With CMake +---------- + +CMake probes the compiler at configure time, so source the Ameba environment +once first, **passing the board** so the asdk version that IC pins is on +``PATH``: + +.. code:: console + + $ . tools/ameba/env.sh + $ cmake -B build -DBOARD_CONFIG=: -GNinja + $ cmake --build build + +make writes ``nuttx.bin`` to the top-level directory; CMake writes it under +``build/``. The bootloader ``boot.bin`` is a prebuilt binary under the board's +``prebuilt/`` directory; the flash step writes both at the offsets taken from +the generated flash layout, so none are entered by hand. + +Flashing +-------- + +**CLI (Linux/macOS)** — connect a USB-UART adapter and use the built-in flash +target (the baud defaults to 1500000; override with ``AMEBA_BAUD``):: + + $ make flash AMEBA_PORT=/dev/ttyUSB0 # make build + $ AMEBA_PORT=/dev/ttyUSB0 cmake --build build --target flash # CMake build + +**GUI (Windows)** — use the Realtek AmebaImageTool (``AmebaImageTool.exe`` under +``tools/ameba/ImageTool/`` in the SDK tree) to select ``boot.bin`` (from the +board's ``prebuilt/`` directory) and ``nuttx.bin``. See the `Realtek Ameba +ImageTool guide `_ +for the Windows GUI tool and download-mode entry (hold the download button / +power-cycle with the ``UART_LOG_TX`` line asserted). + +**Serial console** — after flashing, connect to the LOG-UART at 1500000 8N1:: + + $ picocom -b 1500000 /dev/ttyUSB0 + +Configuration +============= + +The build-time options are the same for make and CMake (both edit the one +Kconfig for the selected board); only the command that launches the menuconfig +UI differs: + +.. code:: console + + $ make menuconfig # make build + $ cmake --build build -t menuconfig # CMake build + +Supported Features +================== + +- NSH over the LOG-UART console +- littlefs persistent storage at ``/data`` on the SPI NOR flash +- Wi-Fi station (scan / connect) and SoftAP via the ``wapi`` tool +- Networking on NuttX's own TCP/IP stack, with DHCP client and DHCP server + +Boards +====== + +.. toctree:: + :glob: + :maxdepth: 1 + + boards/*/*