This is an automated email from the ASF dual-hosted git repository. fdcavalcanti pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 2713c5e9dfd boards/esp32s3: Add SPI slave device support 2713c5e9dfd is described below commit 2713c5e9dfdc5baf25272425314a42dc4e215cbb Author: Thiago Finelon <thiago.pere...@agrosystem.com.br> AuthorDate: Tue Aug 19 10:31:38 2025 -0300 boards/esp32s3: Add SPI slave device support - Added esp32s3_board_spislavedev.c with board-level SPI slave logic - Added esp32s3_board_spislavedev.h public header in common/include - Updated Make.defs to include the new source when CONFIG_SPI_SLAVE_DRIVER=y - Adding spislv board config to esp32s3-devkit - Adding documentation of esp32s3 devkit spi slv - Fixing path include in esp32s3_board_spislavedev.c - Fixing relative path in the header of esp32s3_board_spislavedev.h - Removing neasted check in Make.defs, consistency reasons This provides initial support for SPI slave device initialization on ESP32-S3 boards, making the feature available under conditional build configuration. Signed-off-by: Thiago Finelon <thiago.sfine...@gmail.com> --- .../xtensa/esp32s3/boards/esp32s3-devkit/index.rst | 20 ++++++ .../common/include/esp32s3_board_spislavedev.h | 76 ++++++++++++++++++++ boards/xtensa/esp32s3/common/src/Make.defs | 4 ++ .../esp32s3/common/src/esp32s3_board_spislavedev.c | 82 ++++++++++++++++++++++ .../esp32s3-devkit/configs/spislv/defconfig | 51 ++++++++++++++ .../esp32s3/esp32s3-devkit/src/esp32s3_bringup.c | 29 +++++++- 6 files changed, 259 insertions(+), 3 deletions(-) diff --git a/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst b/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst index 8ca90082b26..061ab406d02 100644 --- a/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst +++ b/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst @@ -963,6 +963,26 @@ Once booted you can use the following commands to mount the file system:: Note that mksmartfs is only needed the first time. +spislv +------ + +This configuration enables the SPI2 peripheral in **slave mode** and +provides the ``spislv`` example application to test data exchange with an +external SPI master. + +After building and flashing the firmware, run the following command on the +board terminal:: + + nsh> spislv -x 5 1a2b3c4d5e + +This command enqueues the data sequence ``1a2b3c4d5e`` in the slave buffer. +On the next transfer, the external SPI master should receive this data back +from the slave. + +By default, SPI2 pins are used for the slave interface. The exact pin mapping +depends on the ESP32-S3 DevKit version and can be adjusted through +``menuconfig`` under *System type → SPI configuration*. + sta_softap ---------- diff --git a/boards/xtensa/esp32s3/common/include/esp32s3_board_spislavedev.h b/boards/xtensa/esp32s3/common/include/esp32s3_board_spislavedev.h new file mode 100644 index 00000000000..b79c8456321 --- /dev/null +++ b/boards/xtensa/esp32s3/common/include/esp32s3_board_spislavedev.h @@ -0,0 +1,76 @@ +/**************************************************************************** + * boards/xtensa/esp32s3/common/include/esp32s3_board_spislavedev.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32S3_COMMON_INCLUDE_ESP32S3_BOARD_SPISLAVEDEV_H +#define __BOARDS_XTENSA_ESP32S3_COMMON_INCLUDE_ESP32S3_BOARD_SPISLAVEDEV_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_spislavedev_initialize + * + * Description: + * Initialize SPI Slave driver and register the /dev/spislv device. + * + * Input Parameters: + * bus - The SPI bus number, used to build the device path as /dev/spislvN + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_SLAVE_DRIVER +int board_spislavedev_initialize(int bus); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_XTENSA_ESP32S3_COMMON_INCLUDE_ESP32S3_BOARD_SPISLAVEDEV_H */ diff --git a/boards/xtensa/esp32s3/common/src/Make.defs b/boards/xtensa/esp32s3/common/src/Make.defs index 14eab861b37..e41c76d7c7d 100644 --- a/boards/xtensa/esp32s3/common/src/Make.defs +++ b/boards/xtensa/esp32s3/common/src/Make.defs @@ -38,6 +38,10 @@ ifeq ($(CONFIG_SPI_DRIVER),y) CSRCS += esp32s3_board_spidev.c endif +ifeq ($(CONFIG_SPI_SLAVE_DRIVER),y) + CSRCS += esp32s3_board_spislavedev.c +endif + ifeq ($(CONFIG_ESPRESSIF_WIFI),y) CSRCS += esp32s3_board_wlan.c endif diff --git a/boards/xtensa/esp32s3/common/src/esp32s3_board_spislavedev.c b/boards/xtensa/esp32s3/common/src/esp32s3_board_spislavedev.c new file mode 100644 index 00000000000..cb590577440 --- /dev/null +++ b/boards/xtensa/esp32s3/common/src/esp32s3_board_spislavedev.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * boards/xtensa/esp32s3/common/src/esp32s3_board_spislavedev.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 <stdio.h> +#include <debug.h> +#include <errno.h> + +#include <nuttx/spi/slave.h> + +#include "esp32s3_spi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_spislavedev_initialize + * + * Description: + * Initialize SPI Slave driver and register the /dev/spislv device. + * + * Input Parameters: + * bus - The SPI bus number, used to build the device path as /dev/spislvN + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_spislavedev_initialize(int bus) +{ + int ret; + + struct spi_slave_ctrlr_s *ctrlr; + + spiinfo("Initializing /dev/spislv%d...\n", bus); + + /* Initialize SPI Slave controller device */ + + ctrlr = esp32s3_spislave_ctrlr_initialize(bus); + if (ctrlr == NULL) + { + spierr("Failed to initialize SPI%d as slave.\n", bus); + return -ENODEV; + } + + ret = spi_slave_register(ctrlr, bus); + if (ret < 0) + { + spierr("Failed to register /dev/spislv%d: %d\n", bus, ret); + + esp32s3_spislave_ctrlr_uninitialize(ctrlr); + } + + return ret; +} diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/spislv/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/spislv/defconfig new file mode 100644 index 00000000000..55e8fa742e7 --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/spislv/defconfig @@ -0,0 +1,51 @@ +# +# 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_ARCH_LEDS is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32s3-devkit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S3_DEVKIT=y +CONFIG_ARCH_CHIP="esp32s3" +CONFIG_ARCH_CHIP_ESP32S3=y +CONFIG_ARCH_CHIP_ESP32S3WROOM1N4=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_ESP32S3_SPI2=y +CONFIG_ESP32S3_UART0=y +CONFIG_EXAMPLES_SPISLV=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=3072 +CONFIG_INTELHEX_BINARY=y +CONFIG_LINE_MAX=64 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SPI_DRIVER=y +CONFIG_SPI_SLAVE=y +CONFIG_SPI_SLAVE_DRIVER=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSLOG_BUFFER=y +CONFIG_SYSTEM_NSH=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c index 56d12896519..d67a544c37a 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c +++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c @@ -116,6 +116,10 @@ # endif #endif +#ifdef CONFIG_SPI_SLAVE_DRIVER +#include "esp32s3_board_spislavedev.h" +#endif + #if defined(CONFIG_ESP32S3_SDMMC) || defined(CONFIG_MMCSD_SPI) #include "esp32s3_board_sdmmc.h" #endif @@ -188,15 +192,34 @@ int esp32s3_bringup(void) #endif #if defined(CONFIG_ESP32S3_SPI) && defined(CONFIG_SPI_DRIVER) - #ifdef CONFIG_ESP32S3_SPI2 + + #if defined(CONFIG_SPI_SLAVE_DRIVER) && defined(CONFIG_ESP32S3_SPI2) + ret = board_spislavedev_initialize(ESP32S3_SPI2); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize SPI%d Slave driver: %d\n", + ESP32S3_SPI2, ret); + } + #endif + + #if defined(CONFIG_SPI_SLAVE_DRIVER) && defined(CONFIG_ESP32S3_SPI3) + ret = board_spislavedev_initialize(ESP32S3_SPI3); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize SPI%d Slave driver: %d\n", + ESP32S3_SPI2, ret); + } + #endif + + #if defined(CONFIG_ESP32S3_SPI2) && !defined(CONFIG_SPI_SLAVE_DRIVER) ret = board_spidev_initialize(ESP32S3_SPI2); if (ret < 0) { - syslog(LOG_ERR, "ERROR: Failed to init spidev 2: %d\n", ret); + syslog(LOG_ERR, "ERROR: Failed to init spidev 3: %d\n", ret); } #endif - #ifdef CONFIG_ESP32S3_SPI3 + #if defined(CONFIG_ESP32S3_SPI3) && !defined(CONFIG_SPI_SLAVE_DRIVER) ret = board_spidev_initialize(ESP32S3_SPI3); if (ret < 0) {