Skip to content

Commit bfae41e

Browse files
committed
boards/xtensa/esp32s3/esp32s3-xiao: add SD card support over SPI2
The XIAO ESP32-S3 Sense's onboard microSD slot (Seeed XIAOML Kit) is wired to SPI2 through the GPIO matrix: SCK=GPIO7, MOSI=GPIO9, MISO=GPIO8 (confirmed against espressif/arduino-esp32's XIAO_ESP32S3/pins_arduino.h) and CS=GPIO21 (confirmed against this project's own working xiaoml_bench_logger.ino, which tries CS candidates {21, 3} in that order -- GPIO3 is a documented fallback, not the real pin; a Seeed wiki page that names GPIO3 as CS turned out to be wrong and was the initial, unsuccessful attempt here). Wires up board_sdmmc_spi_initialize() (common esp32s3 board code, CONFIG_MMCSD_SPI) into this board's bringup, and adds the esp32s3_spi2_status() callback (SPI_STATUS_PRESENT for SPIDEV_MMCSD(0)) that esp32s3-devkit and other in-tree boards already provide -- the esp32s3-xiao board had no SPI board file at all before this. Validated on the bench: CMD0/CMD41/CMD58 handshake succeeds, SD ver2 card identified (SanDisk 32GB, 62333952 sectors), mounts as vfat, survives umount+remount with a written file intact. Needed board defconfig additions (not included in this NuttX-tree commit; see the 61680_FW project repo for the board config that turns this on): CONFIG_ESP32S3_SPI2=y CONFIG_ESP32S3_SPI2_CSPIN=21 CONFIG_ESP32S3_SPI2_CLKPIN=7 CONFIG_ESP32S3_SPI2_MOSIPIN=9 CONFIG_ESP32S3_SPI2_MISOPIN=8 CONFIG_MMCSD=y CONFIG_NSH_MMCSDSPIPORTNO=2 CONFIG_FS_FAT=y CONFIG_FAT_LFN=y CONFIG_FAT_LCNAMES=y Assisted-by: Claude <noreply@anthropic.com> Signed-off-by: Felipe Moura <mouraf@fiteclabs.org.br>
1 parent 5e92a05 commit bfae41e

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

boards/xtensa/esp32s3/esp32s3-xiao/src/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ ifeq ($(CONFIG_DEV_GPIO),y)
3636
CSRCS += esp32s3_gpio.c
3737
endif
3838

39+
ifeq ($(CONFIG_ESP32S3_SPI),y)
40+
CSRCS += esp32s3_board_spi.c
41+
endif
42+
3943
DEPPATH += --dep-path board
4044
VPATH += :board
4145
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/****************************************************************************
2+
* boards/xtensa/esp32s3/esp32s3-xiao/src/esp32s3_board_spi.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <nuttx/config.h>
28+
29+
#include <stdint.h>
30+
#include <stdbool.h>
31+
#include <nuttx/debug.h>
32+
33+
#include <nuttx/spi/spi.h>
34+
35+
/****************************************************************************
36+
* Public Functions
37+
****************************************************************************/
38+
39+
/****************************************************************************
40+
* Name: esp32s3_spi2_status
41+
****************************************************************************/
42+
43+
#ifdef CONFIG_ESP32S3_SPI2
44+
45+
uint8_t esp32s3_spi2_status(struct spi_dev_s *dev, uint32_t devid)
46+
{
47+
uint8_t status = 0;
48+
49+
if (devid == SPIDEV_MMCSD(0))
50+
{
51+
return SPI_STATUS_PRESENT;
52+
}
53+
54+
return status;
55+
}
56+
57+
#endif

boards/xtensa/esp32s3/esp32s3-xiao/src/esp32s3_bringup.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
# include "esp32s3_i2c.h"
5252
#endif
5353

54+
#if defined(CONFIG_ESP32S3_SDMMC) || defined(CONFIG_MMCSD_SPI)
55+
# include "esp32s3_board_sdmmc.h"
56+
#endif
57+
5458
#include "esp32s3-xiao.h"
5559

5660
#ifdef CONFIG_USERLED
@@ -123,6 +127,14 @@ int esp32s3_bringup(void)
123127
}
124128
#endif
125129

130+
#ifdef CONFIG_MMCSD_SPI
131+
ret = board_sdmmc_spi_initialize();
132+
if (ret < 0)
133+
{
134+
syslog(LOG_ERR, "ERROR: Failed to initialize SDMMC: %d\n", ret);
135+
}
136+
#endif
137+
126138
#ifdef CONFIG_I2C_DRIVER
127139
/* Configure I2C peripheral interfaces */
128140

0 commit comments

Comments
 (0)