This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3197472ad42c1b156ceb531450850d81a66e1ff9 Author: dechao_gong <[email protected]> AuthorDate: Tue Aug 11 13:44:15 2026 +0800 arch/arm/rtl8720f: add single-port GPIO support RTL8720F drives all GPIO through a single 32-pin port A controller served by one NVIC vector, unlike RTL8721Dx (ports A/B) or RTL8721F (ports A/B/C). Add an ameba_gpio_chip.h that configures the shared common GPIO driver (arch/arm/src/common/ameba/ameba_gpio.c) for a single port: AMEBA_GPIO_NPORTS=1, AMEBA_GPIO_PORT_IRQS={GPIOA} and the APBPeriph_GPIO gate bits. GPIO_INTStatusGet/ClearEdge live in the RTL8720F ROM symbol table, so no fwlib ram_common object needs compiling in. Wire CONFIG_AMEBA_GPIO into Make.defs/CMakeLists/Kconfig, add the board pin table (PA22 out, PA23 in, PA24 interrupt) with bringup registration and a gpio config. Hardware-verified on rtl8720f_evb: output, input and (falling-edge) interrupt all confirmed via a PA22-to-PA24 loopback. Signed-off-by: dechao_gong <[email protected]> Assisted-by: Claude <[email protected]> --- .../arm/rtl8720f/boards/rtl8720f_evb/index.rst | 21 +++++ arch/arm/src/rtl8720f/CMakeLists.txt | 4 + arch/arm/src/rtl8720f/Kconfig | 5 + arch/arm/src/rtl8720f/Make.defs | 4 + arch/arm/src/rtl8720f/ameba_gpio_chip.h | 79 ++++++++++++++++ .../rtl8720f/rtl8720f_evb/configs/gpio/defconfig | 50 ++++++++++ .../arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt | 11 +++ boards/arm/rtl8720f/rtl8720f_evb/src/Makefile | 11 +++ .../rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c | 10 ++ .../{rtl8720f_rtl8720f_evb.h => rtl8720f_gpio.c} | 104 ++++++++++----------- .../rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h | 13 +++ 11 files changed, 260 insertions(+), 52 deletions(-) diff --git a/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst b/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst index aa5351d93fe..c81d12d9ae9 100644 --- a/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst +++ b/Documentation/platforms/arm/rtl8720f/boards/rtl8720f_evb/index.rst @@ -31,6 +31,8 @@ Supported in this NuttX port: partition), backing the Wi-Fi key-value store * Wi-Fi station and SoftAP through the ``wapi`` tool * DHCP client (STA) and DHCP server (SoftAP) +* GPIO pins exposed as ``/dev/gpioN`` character devices (input, output and + interrupt), driven directly on the SDK fwlib register layer Buttons and LEDs ================ @@ -48,6 +50,25 @@ rtl8720f_evb`` first (the make build needs no sourcing). $ ./tools/configure.sh rtl8720f_evb:<config-name> +gpio +---- + +Minimal NSH with the GPIO driver and the ``gpio`` example enabled (no Wi-Fi). +The board registers three pins from its pin table (see +``boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_gpio.c``): an output at +``/dev/gpio0``, an input at ``/dev/gpio1`` and an interrupt pin at +``/dev/gpio2``. Edit that table to match a board's wiring. Exercise them with +the example:: + + nsh> gpio -o 1 /dev/gpio0 # drive the output high + nsh> gpio /dev/gpio1 # read the input + nsh> gpio -w 1 /dev/gpio2 # wait for a falling-edge interrupt + +RTL8720F drives all GPIO through a single port A controller, so pins are +encoded with the ``AMEBA_PA()`` helper from +``arch/arm/src/common/ameba/ameba_gpio.h`` (pin 0-31), matching the Ameba SDK +``PinName`` layout. + nsh --- diff --git a/arch/arm/src/rtl8720f/CMakeLists.txt b/arch/arm/src/rtl8720f/CMakeLists.txt index 37bcfb83d0b..ab633deb2bc 100644 --- a/arch/arm/src/rtl8720f/CMakeLists.txt +++ b/arch/arm/src/rtl8720f/CMakeLists.txt @@ -46,6 +46,10 @@ if(CONFIG_RTL8720F_FLASH_FS) list(APPEND SRCS ${AMEBA_COMMON}/ameba_flash_mtd.c) endif() +if(CONFIG_AMEBA_GPIO) + list(APPEND SRCS ${AMEBA_COMMON}/ameba_gpio.c) +endif() + target_include_directories(arch PRIVATE ${AMEBA_COMMON}) target_sources(arch PRIVATE ${SRCS}) diff --git a/arch/arm/src/rtl8720f/Kconfig b/arch/arm/src/rtl8720f/Kconfig index 0b9d3d65baf..76e9c1d74bc 100644 --- a/arch/arm/src/rtl8720f/Kconfig +++ b/arch/arm/src/rtl8720f/Kconfig @@ -82,4 +82,9 @@ config RTL8720F_FLASH_FS endmenu # RTL8720F Storage +# Shared Ameba peripheral drivers (GPIO, ...) live in the common IC-agnostic +# tree and are configured through one Kconfig reused by every Ameba chip. + +source "arch/arm/src/common/ameba/Kconfig" + endif # ARCH_CHIP_RTL8720F diff --git a/arch/arm/src/rtl8720f/Make.defs b/arch/arm/src/rtl8720f/Make.defs index 30032d1ece4..637aeca30b8 100644 --- a/arch/arm/src/rtl8720f/Make.defs +++ b/arch/arm/src/rtl8720f/Make.defs @@ -56,6 +56,10 @@ ifeq ($(CONFIG_RTL8720F_FLASH_FS),y) CHIP_CSRCS += ameba_flash_mtd.c endif +ifeq ($(CONFIG_AMEBA_GPIO),y) +CHIP_CSRCS += ameba_gpio.c +endif + ############################################################################ # Realtek RTL8720F SDK integration # diff --git a/arch/arm/src/rtl8720f/ameba_gpio_chip.h b/arch/arm/src/rtl8720f/ameba_gpio_chip.h new file mode 100644 index 00000000000..3fb1d85f87d --- /dev/null +++ b/arch/arm/src/rtl8720f/ameba_gpio_chip.h @@ -0,0 +1,79 @@ +/**************************************************************************** + * arch/arm/src/rtl8720f/ameba_gpio_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_RTL8720F_AMEBA_GPIO_CHIP_H +#define __ARCH_ARM_SRC_RTL8720F_AMEBA_GPIO_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> + +#include <nuttx/irq.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Per-chip GPIO parameters for the shared driver + * (arch/arm/src/common/ameba/ameba_gpio.c). The driver logic, pin encoding + * and fwlib API are identical across every Ameba ARM chip, but the port + * count, the per-port NVIC vectors and the RCC gate bits are not. Each chip + * supplies its own <ameba_gpio_chip.h> on the include path (arch/.../chip); + * the common driver sizes its tables and wires its vectors from the macros + * below, so nothing IC-specific is left in common. + * + * RTL8720F (Ameba WHC, KM4) drives all of its GPIO through a single 32-pin + * controller (GPIO_PORTx[1] / GPIO_PORT_A) served by one NVIC vector + * (RTL8720F_IRQ_GPIOA). This is unlike RTL8721Dx (ports A and B, two + * vectors) or RTL8721F (ports A, B and C, three vectors): the SDK fwlib on + * this part exposes only GPIO_PORT_A (IS_GPIO_PORT_NUM() accepts port A + * only), so the shared driver is configured for a single port here. Board + * pin tables therefore use port A (AMEBA_PA()) pins. + * + * GPIO_INTStatusGet and GPIO_INTStatusClearEdge are in the RTL8720F ROM + * symbol table (ameba_rom_symbol_acut_s.ld), so fwlib + * ram_common/ameba_gpio.c does NOT need to be compiled in -- unlike + * RTL8721Dx where those symbols live in ram_common. + */ + +/* Number of GPIO ports (banks) this chip exposes. */ + +#define AMEBA_GPIO_NPORTS 1 + +/* NVIC vector for each port, as an initialiser indexed by port number + * (0 = A). Its width must match AMEBA_GPIO_NPORTS. + */ + +#define AMEBA_GPIO_PORT_IRQS { RTL8720F_IRQ_GPIOA } + +/* APBPeriph_GPIO / APBPeriph_GPIO_CLOCK (sysreg_lsys.h): the peripheral and + * clock bits RCC_PeriphClockCmd() gates for the GPIO block. On RTL8720F + * both are ((1 << 30) | (1 << 4)); same value as RTL8721Dx and RTL8721F. + */ + +#define AMEBA_APBPERIPH_GPIO (((uint32_t)1 << 30) | ((uint32_t)1 << 4)) + +#endif /* __ARCH_ARM_SRC_RTL8720F_AMEBA_GPIO_CHIP_H */ diff --git a/boards/arm/rtl8720f/rtl8720f_evb/configs/gpio/defconfig b/boards/arm/rtl8720f/rtl8720f_evb/configs/gpio/defconfig new file mode 100644 index 00000000000..8f263ad7ee5 --- /dev/null +++ b/boards/arm/rtl8720f/rtl8720f_evb/configs/gpio/defconfig @@ -0,0 +1,50 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_DEBUG_WARN is not set +CONFIG_AMEBA_GPIO=y +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="rtl8720f_evb" +CONFIG_ARCH_BOARD_RTL8720F_EVB=y +CONFIG_ARCH_CHIP="rtl8720f" +CONFIG_ARCH_CHIP_RTL8720F=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV8M_SYSTICK=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_EXAMPLES_GPIO=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_FS_PROCFS=y +CONFIG_FS_TMPFS=y +CONFIG_IDLETHREAD_STACKSIZE=4096 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_LIBC_MEMFD_ERROR=y +CONFIG_MM_DEFAULT_ALIGNMENT=32 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=262144 +CONFIG_RAM_START=0x30008000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SCHED_LPWORK=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=16 +CONFIG_START_MONTH=6 +CONFIG_START_YEAR=2026 +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=2500 +CONFIG_TIMER=y +CONFIG_TIMER_ARCH=y +CONFIG_USEC_PER_TICK=1000 diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt b/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt index 92afbd68e9b..ce8753b2761 100644 --- a/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt +++ b/boards/arm/rtl8720f/rtl8720f_evb/src/CMakeLists.txt @@ -22,7 +22,18 @@ set(SRCS rtl8720f_boot.c rtl8720f_bringup.c) +if(CONFIG_AMEBA_GPIO) + list(APPEND SRCS rtl8720f_gpio.c) +endif() + target_sources(board PRIVATE ${SRCS}) +if(CONFIG_AMEBA_GPIO) + # The board pin tables pull in the shared drivers' public headers from + # arch/arm/src/common/ameba/, not on the default board include path. + target_include_directories(board + PRIVATE ${NUTTX_DIR}/arch/arm/src/common/ameba) +endif() + # LD_SCRIPT is not set here: the Ameba image2 linker script is generated # (prebuilt/ld.script.gen) and published by the shared ameba_board.cmake. diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile b/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile index 66f8c7b9f15..a4e6ba74fce 100644 --- a/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile +++ b/boards/arm/rtl8720f/rtl8720f_evb/src/Makefile @@ -24,4 +24,15 @@ include $(TOPDIR)/Make.defs CSRCS = rtl8720f_boot.c rtl8720f_bringup.c +ifeq ($(CONFIG_AMEBA_GPIO),y) +CSRCS += rtl8720f_gpio.c +endif + +# The board pin tables pull in the shared drivers' public headers from +# arch/arm/src/common/ameba/, which is not on the default board include path. + +ifneq ($(CONFIG_AMEBA_GPIO),) +CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)common$(DELIM)ameba +endif + include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c index 6099467567d..066a90983d7 100644 --- a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c +++ b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_bringup.c @@ -120,6 +120,16 @@ int rtl8720f_bringup(void) } #endif +#ifdef CONFIG_AMEBA_GPIO + /* Register the board's GPIO pins at /dev/gpioN. */ + + ret = rtl8720f_gpio_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: rtl8720f_gpio_initialize failed: %d\n", ret); + } +#endif + /* Install the inter-core HW IPC-semaphore RTOS hooks LAST -- after all the * flash / WHC bring-up above, and just before this (board_late_initialize) * path returns and nx_start() hands off to the init task. diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_gpio.c similarity index 50% copy from boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h copy to boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_gpio.c index 5582da98f09..9656ab20f11 100644 --- a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h +++ b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_gpio.c @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h + * boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_gpio.c * * SPDX-License-Identifier: Apache-2.0 * @@ -20,81 +20,81 @@ * ****************************************************************************/ -#ifndef __BOARDS_ARM_RTL8720F_RTL8720F_EVB_SRC_RTL8720F_RTL8720F_EVB_H -#define __BOARDS_ARM_RTL8720F_RTL8720F_EVB_SRC_RTL8720F_RTL8720F_EVB_H - /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ +#include <sys/param.h> +#include <syslog.h> -#ifndef __ASSEMBLY__ +#include <nuttx/ioexpander/gpio.h> -/**************************************************************************** - * Name: rtl8720f_boardinitialize - * - * Description: - * Perform board-specific early initialization. - * - ****************************************************************************/ +#include "ameba_gpio.h" +#include "rtl8720f_rtl8720f_evb.h" -void rtl8720f_boardinitialize(void); +#ifdef CONFIG_AMEBA_GPIO /**************************************************************************** - * Name: rtl8720f_bringup - * - * Description: - * Bring up board features. - * + * Private Types ****************************************************************************/ -int rtl8720f_bringup(void); +/* One entry per GPIO pin exposed to NuttX. RTL8720F drives all GPIO through + * a single port A controller, so board pins use AMEBA_PA(). PA_22/23/24 are + * free validation pins with no special-function mux (the LOG-UART console is + * on PA_19/PA_20). They are registered in order as /dev/gpio0, /dev/gpio1, + * ... + */ + +struct rtl8720f_gpio_s +{ + uint8_t pin; /* AMEBA_PA() pin encoding */ + enum gpio_pintype_e pintype; /* Input, output or interrupt */ +}; -#ifdef CONFIG_RTL8720F_WIFI /**************************************************************************** - * Name: rtl8720f_wifi_initialize - * - * Description: - * Bring up the KM4 IPC transport and start the WHC host WiFi stack - * (arch/arm/src/rtl8720f/ameba_wifi_init.c). - * + * Private Data ****************************************************************************/ -int rtl8720f_wifi_initialize(void); -#endif +static const struct rtl8720f_gpio_s g_gpio_pins[] = +{ + { AMEBA_PA(22), GPIO_OUTPUT_PIN }, /* /dev/gpio0: output */ + { AMEBA_PA(23), GPIO_INPUT_PIN }, /* /dev/gpio1: input */ + { AMEBA_PA(24), GPIO_INTERRUPT_PIN }, /* /dev/gpio2: interrupt */ +}; -#if defined(CONFIG_RTL8720F_FLASH_FS) || defined(CONFIG_RTL8720F_WIFI) /**************************************************************************** - * Name: ameba_ipc_initialize - * - * Description: - * Bring up the km4tz<->km4ns IPC transport once (idempotent). Required by - * the SDK flash erase/program path (inter-core XIP pause) and by WiFi - * (arch/arm/src/rtl8720f/ameba_ipc.c). - * + * Public Functions ****************************************************************************/ -void ameba_ipc_initialize(void); -#endif - -#ifdef CONFIG_RTL8720F_FLASH_FS /**************************************************************************** - * Name: ameba_flash_fs_initialize + * Name: rtl8720f_gpio_initialize * * Description: - * Register the on-chip SPI NOR data partition as an MTD device and mount - * a littlefs filesystem on it at /data - * (arch/arm/src/rtl8720f/ameba_flash_mtd.c). + * Register the board's GPIO pins with the NuttX GPIO upper half. * ****************************************************************************/ -int ameba_flash_fs_initialize(void); -#endif - -#endif /* __ASSEMBLY__ */ -#endif /* __BOARDS_ARM_RTL8720F_RTL8720F_EVB_SRC_RTL8720F_RTL8720F_EVB_H */ +int rtl8720f_gpio_initialize(void) +{ + int ret; + size_t i; + + for (i = 0; i < nitems(g_gpio_pins); i++) + { + ret = ameba_gpio_register(i, g_gpio_pins[i].pin, + g_gpio_pins[i].pintype); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: ameba_gpio_register(/dev/gpio%zu) failed: %d\n", + i, ret); + return ret; + } + } + + return OK; +} + +#endif /* CONFIG_AMEBA_GPIO */ diff --git a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h index 5582da98f09..d675e6b17e1 100644 --- a/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h +++ b/boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_rtl8720f_evb.h @@ -96,5 +96,18 @@ void ameba_ipc_initialize(void); int ameba_flash_fs_initialize(void); #endif +#ifdef CONFIG_AMEBA_GPIO +/**************************************************************************** + * Name: rtl8720f_gpio_initialize + * + * Description: + * Register the board's GPIO pins with the NuttX GPIO upper half + * (boards/arm/rtl8720f/rtl8720f_evb/src/rtl8720f_gpio.c). + * + ****************************************************************************/ + +int rtl8720f_gpio_initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_ARM_RTL8720F_RTL8720F_EVB_SRC_RTL8720F_RTL8720F_EVB_H */
