mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
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 <dechao_gong@realsil.com.cn>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
7e2cca2fe9
commit
d584142cf4
33 changed files with 3790 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
53
arch/arm/include/rtl8721f/chip.h
Normal file
53
arch/arm/include/rtl8721f/chip.h
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
147
arch/arm/include/rtl8721f/irq.h
Normal file
147
arch/arm/include/rtl8721f/irq.h
Normal file
|
|
@ -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 <nuttx/irq.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
182
arch/arm/src/rtl8721f/CMakeLists.txt
Normal file
182
arch/arm/src/rtl8721f/CMakeLists.txt
Normal file
|
|
@ -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)
|
||||
85
arch/arm/src/rtl8721f/Kconfig
Normal file
85
arch/arm/src/rtl8721f/Kconfig
Normal file
|
|
@ -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
|
||||
217
arch/arm/src/rtl8721f/Make.defs
Normal file
217
arch/arm/src/rtl8721f/Make.defs
Normal file
|
|
@ -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.
|
||||
141
arch/arm/src/rtl8721f/ameba_allocateheap.c
Normal file
141
arch/arm/src/rtl8721f/ameba_allocateheap.c
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
#include <nuttx/nuttx.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <nuttx/debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/userspace.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#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
|
||||
256
arch/arm/src/rtl8721f/ameba_app_start.c
Normal file
256
arch/arm/src/rtl8721f/ameba_app_start.c
Normal file
|
|
@ -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
|
||||
};
|
||||
448
arch/arm/src/rtl8721f/ameba_board.mk
Normal file
448
arch/arm/src/rtl8721f/ameba_board.mk
Normal file
|
|
@ -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 <lwip_netconf.h> 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
|
||||
150
arch/arm/src/rtl8721f/ameba_ipc.c
Normal file
150
arch/arm/src/rtl8721f/ameba_ipc.c
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
51
arch/arm/src/rtl8721f/ameba_ipc.h
Normal file
51
arch/arm/src/rtl8721f/ameba_ipc.h
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
|
||||
#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 */
|
||||
382
arch/arm/src/rtl8721f/ameba_irq.c
Normal file
382
arch/arm/src/rtl8721f/ameba_irq.c
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/debug.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
}
|
||||
76
arch/arm/src/rtl8721f/ameba_irq.h
Normal file
76
arch/arm/src/rtl8721f/ameba_irq.h
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <arch/rtl8721f/irq.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
413
arch/arm/src/rtl8721f/ameba_loguart.c
Normal file
413
arch/arm/src/rtl8721f/ameba_loguart.c
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/serial/serial.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
172
arch/arm/src/rtl8721f/ameba_start.c
Normal file
172
arch/arm/src/rtl8721f/ameba_start.c
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/init.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#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"
|
||||
);
|
||||
}
|
||||
72
arch/arm/src/rtl8721f/ameba_timerisr.c
Normal file
72
arch/arm/src/rtl8721f/ameba_timerisr.c
Normal file
|
|
@ -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 <stdint.h>
|
||||
|
||||
#include <arch/board/board.h>
|
||||
#include <nuttx/timers/arch_timer.h>
|
||||
|
||||
#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));
|
||||
}
|
||||
122
arch/arm/src/rtl8721f/ameba_wifi_init.c
Normal file
122
arch/arm/src/rtl8721f/ameba_wifi_init.c
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sched.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/kthread.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
39
arch/arm/src/rtl8721f/chip.h
Normal file
39
arch/arm/src/rtl8721f/chip.h
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
#include <arch/rtl8721f/irq.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ARMV8M_PERIPHERAL_INTERRUPTS NR_IRQS
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_RTL8721F_CHIP_H */
|
||||
62
arch/arm/src/rtl8721f/hardware/ameba_memorymap.h
Normal file
62
arch/arm/src/rtl8721f/hardware/ameba_memorymap.h
Normal file
|
|
@ -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 <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue