This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit d6607df419f3474855f4d735ba0626a934a18ff5 Author: ViezeVingertjes <[email protected]> AuthorDate: Wed Nov 25 17:49:51 2026 +0100 boards/esp32s3-touch-amoled-216: Add microSD card support. The microSD slot is wired to SPI3 (GPIO2 SCLK, GPIO1 MOSI, GPIO3 MISO, GPIO41 CS) and has no card detect switch. * Add the SPI3 status hook, reporting the card as always present. * Bind the slot to /dev/mmcsd0 with the common MMC/SD-over-SPI helper. * Add an sdmmc configuration with FAT and document it. Tested on hardware with a 4GB card: mount, file write/read, 1MB dd write at ~1.3MB/s, delete, umount. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: ViezeVingertjes <[email protected]> --- .../boards/esp32s3-touch-amoled-216/index.rst | 18 ++++++ .../configs/sdmmc/defconfig | 64 ++++++++++++++++++++++ .../esp32s3-touch-amoled-216/src/CMakeLists.txt | 4 ++ .../esp32s3/esp32s3-touch-amoled-216/src/Make.defs | 4 ++ .../src/esp32s3_board_spi.c | 62 +++++++++++++++++++++ .../esp32s3-touch-amoled-216/src/esp32s3_bringup.c | 14 +++++ 6 files changed, 166 insertions(+) diff --git a/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-touch-amoled-216/index.rst b/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-touch-amoled-216/index.rst index 83948b1a71f..f0de4f27343 100644 --- a/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-touch-amoled-216/index.rst +++ b/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-touch-amoled-216/index.rst @@ -200,3 +200,21 @@ used to exercise it:: nsh> free total used free maxused maxfree nused nfree name 8775692 23020 8752672 23400 8388592 75 4 Umem + +sdmmc +----- + +This configuration binds the microSD card slot, on SPI3 (GPIO2 SCLK, GPIO1 +MOSI, GPIO3 MISO, GPIO41 CS), to ``/dev/mmcsd0`` and enables the FAT file +system. The slot has no card detect switch, so the card must be inserted +before the board boots:: + + nsh> mount -t vfat /dev/mmcsd0 /mnt + nsh> echo hello-from-nuttx > /mnt/nxtest.txt + nsh> cat /mnt/nxtest.txt + hello-from-nuttx + nsh> dd if=/dev/zero of=/mnt/big.bin bs=4096 count=256 + 1048576 bytes (256 blocks) copied, 800000 usec, 1280 KB/s + nsh> df -h + Filesystem Size Used Available Mounted on + vfat 3580M 1040K 3579M /mnt diff --git a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/configs/sdmmc/defconfig b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/configs/sdmmc/defconfig new file mode 100644 index 00000000000..aa663eff545 --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/configs/sdmmc/defconfig @@ -0,0 +1,64 @@ +# +# 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="xtensa" +CONFIG_ARCH_BOARD="esp32s3-touch-amoled-216" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S3_TOUCH_AMOLED_216=y +CONFIG_ARCH_CHIP="esp32s3" +CONFIG_ARCH_CHIP_ESP32S3=y +CONFIG_ARCH_CHIP_ESP32S3WROOM1N16R8=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_IRQ_TO_NDX=y +CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC=y +CONFIG_ARCH_NUSER_INTERRUPTS=2 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_ESP32S3_SPI3=y +CONFIG_ESP32S3_SPI3_CLKPIN=2 +CONFIG_ESP32S3_SPI3_CSPIN=41 +CONFIG_ESP32S3_SPI3_MISOPIN=3 +CONFIG_ESP32S3_SPI3_MOSIPIN=1 +CONFIG_ESP32S3_USBSERIAL=y +CONFIG_ETC_ROMFS=y +CONFIG_EXPERIMENTAL=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_ROMFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="init_main" +CONFIG_INIT_STACKSIZE=8192 +CONFIG_INTELHEX_BINARY=y +CONFIG_LIBC_EXECFUNCS=y +CONFIG_LINE_MAX=64 +CONFIG_MMCSD=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_MMCSDSPIPORTNO=3 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_CHILD_STATUS=y +CONFIG_SCHED_HAVE_PARENT=y +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSLOG_BUFFER=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=8192 +CONFIG_SYSTEM_NXINIT=y diff --git a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/CMakeLists.txt b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/CMakeLists.txt index 99122d8f555..da8caa0b339 100644 --- a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/CMakeLists.txt +++ b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/CMakeLists.txt @@ -10,6 +10,10 @@ if(CONFIG_BOARDCTL_RESET) list(APPEND SRCS esp32s3_reset.c) endif() +if(CONFIG_ESP32S3_SPI) + list(APPEND SRCS esp32s3_board_spi.c) +endif() + if(CONFIG_ARCH_BUTTONS) list(APPEND SRCS esp32s3_buttons.c) endif() diff --git a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/Make.defs b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/Make.defs index be70ab58589..f27c731136c 100644 --- a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/Make.defs +++ b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/Make.defs @@ -25,6 +25,10 @@ ifeq ($(CONFIG_BOARDCTL_RESET),y) CSRCS += esp32s3_reset.c endif +ifeq ($(CONFIG_ESP32S3_SPI),y) +CSRCS += esp32s3_board_spi.c +endif + ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += esp32s3_buttons.c endif diff --git a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_board_spi.c b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_board_spi.c new file mode 100644 index 00000000000..e4785d1b418 --- /dev/null +++ b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_board_spi.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_board_spi.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 <nuttx/spi/spi.h> + +#include "esp32s3_spi.h" + +#include "esp32s3-touch-amoled-216.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32s3_spi3_status + * + * Description: + * Report the status of the devices on SPI3. SPI3 is wired to the + * microSD card slot, which has no card detect switch, so the card is + * always reported as present and the MMC/SD driver finds out whether a + * card actually responds. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32S3_SPI3 +uint8_t esp32s3_spi3_status(struct spi_dev_s *dev, uint32_t devid) +{ + if (devid == SPIDEV_MMCSD(0)) + { + return SPI_STATUS_PRESENT; + } + + return 0; +} +#endif diff --git a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_bringup.c b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_bringup.c index 77027807c71..72884e0de9e 100644 --- a/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_bringup.c +++ b/boards/xtensa/esp32s3/esp32s3-touch-amoled-216/src/esp32s3_bringup.c @@ -61,6 +61,10 @@ # include <nuttx/input/buttons.h> #endif +#ifdef CONFIG_MMCSD_SPI +# include "esp32s3_board_sdmmc.h" +#endif + #ifdef CONFIG_ESPRESSIF_WIFI # include "esp32s3_board_wlan.h" #endif @@ -198,6 +202,16 @@ int esp32s3_bringup(void) } #endif +#ifdef CONFIG_MMCSD_SPI + /* Bind the microSD slot on SPI3 to /dev/mmcsd0 */ + + ret = board_sdmmc_spi_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize SD card: %d\n", ret); + } +#endif + #ifdef CONFIG_INPUT_BUTTONS /* Register the BOOT, IO18 and PWR keys as /dev/buttons */
