This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit aedce4c6483ded814dd765edf72e487a60099ee2
Author: Filipe Cavalcanti <filipe.cavalca...@espressif.com>
AuthorDate: Fri May 30 17:08:32 2025 -0300

    boards/xtensa/esp32: use common board source for SDMMC
    
    Deletes board specific sdmmc implementation in favor of a common source and 
header file.
    
    Signed-off-by: Filipe Cavalcanti <filipe.cavalca...@espressif.com>
---
 .../include/esp32_board_sdmmc.h}                   | 71 +++++++-----------
 boards/xtensa/esp32/common/src/Make.defs           |  4 +
 .../src/esp32_board_sdmmc.c}                       | 43 ++++++-----
 boards/xtensa/esp32/esp32-audio-kit/src/Make.defs  |  5 --
 .../esp32/esp32-audio-kit/src/esp32-audio-kit.h    | 10 ---
 .../esp32/esp32-audio-kit/src/esp32_bringup.c      |  8 +-
 .../xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c | 86 ----------------------
 boards/xtensa/esp32/esp32-devkitc/src/Make.defs    |  4 -
 .../xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h |  9 ---
 .../xtensa/esp32/esp32-devkitc/src/esp32_bringup.c |  8 +-
 .../xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c   | 86 ----------------------
 .../xtensa/esp32/esp32-ethernet-kit/src/Make.defs  |  5 --
 .../esp32-ethernet-kit/src/esp32-ethernet-kit.h    |  9 ---
 .../esp32/esp32-ethernet-kit/src/esp32_bringup.c   |  8 +-
 .../esp32/esp32-ethernet-kit/src/esp32_mmcsd.c     | 86 ----------------------
 boards/xtensa/esp32/esp32-lyrat/src/Make.defs      |  5 --
 boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h  | 10 ---
 .../xtensa/esp32/esp32-lyrat/src/esp32_bringup.c   |  8 +-
 .../xtensa/esp32/esp32-sparrow-kit/src/Make.defs   |  4 -
 .../esp32-sparrow-kit/src/esp32-sparrow-kit.h      | 10 ---
 .../esp32/esp32-sparrow-kit/src/esp32_bringup.c    |  8 +-
 .../esp32/esp32-sparrow-kit/src/esp32_mmcsd.c      | 86 ----------------------
 boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs |  5 --
 .../esp32/esp32-wrover-kit/src/esp32-wrover-kit.h  | 10 ---
 .../esp32/esp32-wrover-kit/src/esp32_bringup.c     |  8 +-
 .../esp32/esp32-wrover-kit/src/esp32_mmcsd.c       | 86 ----------------------
 boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs    |  5 --
 .../xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c |  8 +-
 .../xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h |  9 ---
 .../esp32/ttgo_t_display_esp32/src/Make.defs       |  5 --
 .../esp32/ttgo_t_display_esp32/src/esp32_bringup.c |  8 +-
 .../esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c   | 86 ----------------------
 .../src/ttgo_t_display_esp32.h                     |  9 ---
 33 files changed, 105 insertions(+), 707 deletions(-)

diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/common/include/esp32_board_sdmmc.h
similarity index 58%
rename from boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c
rename to boards/xtensa/esp32/common/include/esp32_board_sdmmc.h
index e1c2c09890..73117940dd 100644
--- a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c
+++ b/boards/xtensa/esp32/common/include/esp32_board_sdmmc.h
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_mmcsd.c
+ * boards/xtensa/esp32/common/include/esp32_board_sdmmc.h
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -20,67 +20,52 @@
  *
  ****************************************************************************/
 
+#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SDMMC_H
+#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SDMMC_H
+
 /****************************************************************************
  * Included Files
  ****************************************************************************/
 
-#include <debug.h>
 #include <nuttx/config.h>
-#include <nuttx/mmcsd.h>
-#include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "esp32_spi.h"
-#include "ttgo_eink5_v2.h"
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
+#ifndef __ASSEMBLY__
 
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
 
 /****************************************************************************
- * Public Functions
+ * Public Function Prototypes
  ****************************************************************************/
 
 /****************************************************************************
- * Name: esp32_mmcsd_initialize
+ * Name: board_sdmmc_initialize
  *
  * Description:
- *   Initialize SPI-based SD card and card detect thread.
+ *   Configure a SPI subsystem peripheral to communicate with SD card.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned
+ *   to indicate the nature of any failure.
+ *
  ****************************************************************************/
 
-int esp32_mmcsd_initialize(int minor)
-{
-  struct spi_dev_s *spi;
-  int rv;
-
-  mcinfo("INFO: Initializing mmcsd card\n");
+int board_sdmmc_initialize(void);
 
-  spi = esp32_spibus_initialize(2);
-  if (spi == NULL)
-    {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
-      return -ENODEV;
-    }
-
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
-    {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
-    }
-
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
-  return OK;
+#undef EXTERN
+#if defined(__cplusplus)
 }
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SDMMC_H */
diff --git a/boards/xtensa/esp32/common/src/Make.defs 
b/boards/xtensa/esp32/common/src/Make.defs
index 3bf716925e..a49cbf93d7 100644
--- a/boards/xtensa/esp32/common/src/Make.defs
+++ b/boards/xtensa/esp32/common/src/Make.defs
@@ -170,6 +170,10 @@ ifeq ($(CONFIG_ESP_MCPWM),y)
   CSRCS += esp32_board_mcpwm.c
 endif
 
+ifeq ($(CONFIG_MMCSD_SPI),y)
+  CSRCS += esp32_board_sdmmc.c
+endif
+
 DEPPATH += --dep-path src
 VPATH += :src
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
diff --git a/boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/common/src/esp32_board_sdmmc.c
similarity index 70%
rename from boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c
rename to boards/xtensa/esp32/common/src/esp32_board_sdmmc.c
index 5a2fbfff8a..1badb1fa59 100644
--- a/boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c
+++ b/boards/xtensa/esp32/common/src/esp32_board_sdmmc.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/xtensa/esp32/esp32-lyrat/src/esp32_mmcsd.c
+ * boards/xtensa/esp32/common/src/esp32_board_sdmmc.c
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -24,17 +24,12 @@
  * Included Files
  ****************************************************************************/
 
-#include <debug.h>
 #include <nuttx/config.h>
+#include <syslog.h>
 #include <nuttx/mmcsd.h>
 #include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
 
 #include "esp32_spi.h"
-#include "esp32-lyrat.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -56,31 +51,43 @@
  * Name: esp32_mmcsd_initialize
  *
  * Description:
- *   Initialize SPI-based SD card and card detect thread.
+ *   Configure a SPI subsystem peripheral to communicate with SD card.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; A negated errno value is returned
+ *   to indicate the nature of any failure.
+ *
  ****************************************************************************/
 
-int esp32_mmcsd_initialize(int minor)
+int board_sdmmc_initialize(void)
 {
   struct spi_dev_s *spi;
-  int rv;
+  int ret;
 
-  mcinfo("INFO: Initializing mmcsd card\n");
+  syslog(LOG_INFO, "INFO: init MMC/SD slot %d on SPI%d: /dev/mmcsd%d\n",
+         CONFIG_NSH_MMCSDSLOTNO, CONFIG_NSH_MMCSDSPIPORTNO,
+         CONFIG_NSH_MMCSDMINOR);
 
   spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
+
   if (spi == NULL)
     {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
+      syslog(LOG_ERR, "ERROR: failed to initialize SPI%d.\n",
+             CONFIG_NSH_MMCSDSPIPORTNO);
       return -ENODEV;
     }
 
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
+  /* Mounts to /dev/mmcsdN where N in the minor number */
+
+  ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR,
+                                CONFIG_NSH_MMCSDSLOTNO, spi);
+  if (ret < 0)
     {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
+      syslog(LOG_ERR, "ERROR: failed to bind SPI%d to SD slot %d\n",
+            CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
+      return ret;
     }
 
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
+  syslog(LOG_INFO, "INFO: MMCSD initialized\n");
   return OK;
 }
diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs 
b/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs
index e5f9f0f1a4..08b0e170c4 100644
--- a/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs
+++ b/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs
@@ -33,10 +33,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += esp32_gpio.c
 endif
@@ -48,4 +44,3 @@ endif
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
-
diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h 
b/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h
index 1ecd025e3a..a042aa708d 100644
--- a/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h
+++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h
@@ -152,16 +152,6 @@ int esp32_es8388_initialize(int i2c_port, uint8_t 
i2c_addr, int i2c_freq,
 int board_i2sdev_initialize(int port);
 #endif
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- *
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_spiflash_init
  *
diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c 
b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c
index 4f5b71ddca..50b11c22bb 100644
--- a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c
@@ -108,6 +108,10 @@
 #  include "esp32_lcd_backpack.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "esp32-audio-kit.h"
 
 /****************************************************************************
@@ -172,8 +176,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c
deleted file mode 100644
index 93705cee8f..0000000000
--- a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
- * boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.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 <debug.h>
-#include <nuttx/config.h>
-#include <nuttx/mmcsd.h>
-#include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "esp32_spi.h"
-#include "esp32-audio-kit.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor)
-{
-  struct spi_dev_s *spi;
-  int rv;
-
-  mcinfo("INFO: Initializing mmcsd card\n");
-
-  spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
-  if (spi == NULL)
-    {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
-      return -ENODEV;
-    }
-
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
-    {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
-    }
-
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
-  return OK;
-}
diff --git a/boards/xtensa/esp32/esp32-devkitc/src/Make.defs 
b/boards/xtensa/esp32/esp32-devkitc/src/Make.defs
index 1c9f6f8cd7..16b4cddaa6 100644
--- a/boards/xtensa/esp32/esp32-devkitc/src/Make.defs
+++ b/boards/xtensa/esp32/esp32-devkitc/src/Make.defs
@@ -29,10 +29,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += esp32_gpio.c
 endif
diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h 
b/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h
index aa4399f0cf..cb3aa58609 100644
--- a/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h
+++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32-devkitc.h
@@ -111,15 +111,6 @@
 
 int esp32_bringup(void);
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_gpio_init
  ****************************************************************************/
diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c 
b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c
index bc6b774164..a2baea659d 100644
--- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c
@@ -191,6 +191,10 @@
 #  include "esp32_board_adc.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "esp32-devkitc.h"
 
 /****************************************************************************
@@ -272,8 +276,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c
deleted file mode 100644
index 8feb2dda3a..0000000000
--- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
- * boards/xtensa/esp32/esp32-devkitc/src/esp32_mmcsd.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 <debug.h>
-#include <nuttx/config.h>
-#include <nuttx/mmcsd.h>
-#include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "esp32_spi.h"
-#include "esp32-devkitc.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor)
-{
-  struct spi_dev_s *spi;
-  int rv;
-
-  mcinfo("INFO: Initializing mmcsd card\n");
-
-  spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
-  if (spi == NULL)
-    {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
-      return -ENODEV;
-    }
-
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
-    {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
-    }
-
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
-  return OK;
-}
diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs 
b/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs
index ffaac61c1d..863d57f96c 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs
@@ -29,10 +29,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_ARCH_BUTTONS),y)
 CSRCS += esp32_buttons.c
 endif
@@ -40,4 +36,3 @@ endif
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
-
diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h 
b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h
index 0a880131ca..2889146772 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32-ethernet-kit.h
@@ -83,15 +83,6 @@
 
 int esp32_bringup(void);
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_spiflash_init
  *
diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c 
b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c
index fea11679de..96511de395 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_bringup.c
@@ -79,6 +79,10 @@
 #  include "esp32_rtc_lowerhalf.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "esp32-ethernet-kit.h"
 
 /****************************************************************************
@@ -133,8 +137,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.c
deleted file mode 100644
index 32732db91c..0000000000
--- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
- * boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_mmcsd.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 <debug.h>
-#include <nuttx/config.h>
-#include <nuttx/mmcsd.h>
-#include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "esp32_spi.h"
-#include "esp32-ethernet-kit.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor)
-{
-  struct spi_dev_s *spi;
-  int rv;
-
-  mcinfo("INFO: Initializing mmcsd card\n");
-
-  spi = esp32_spibus_initialize(2);
-  if (spi == NULL)
-    {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
-      return -ENODEV;
-    }
-
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
-    {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
-    }
-
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
-  return OK;
-}
diff --git a/boards/xtensa/esp32/esp32-lyrat/src/Make.defs 
b/boards/xtensa/esp32/esp32-lyrat/src/Make.defs
index addad5fd72..151ba475de 100644
--- a/boards/xtensa/esp32/esp32-lyrat/src/Make.defs
+++ b/boards/xtensa/esp32/esp32-lyrat/src/Make.defs
@@ -33,10 +33,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += esp32_gpio.c
 endif
@@ -48,4 +44,3 @@ endif
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
-
diff --git a/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h 
b/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h
index ff95d9ba26..dad3cc92e2 100644
--- a/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h
+++ b/boards/xtensa/esp32/esp32-lyrat/src/esp32-lyrat.h
@@ -148,16 +148,6 @@ int esp32_es8388_initialize(int i2c_port, uint8_t 
i2c_addr, int i2c_freq,
 int board_i2sdev_initialize(int port);
 #endif
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- *
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_spiflash_init
  *
diff --git a/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c 
b/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c
index 4efe5397ec..42e3bee999 100644
--- a/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-lyrat/src/esp32_bringup.c
@@ -109,6 +109,10 @@
 #  include "esp32_lcd_backpack.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "esp32-lyrat.h"
 
 /****************************************************************************
@@ -173,8 +177,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs 
b/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs
index 1b1dcfafd5..ebcaac6be4 100644
--- a/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs
+++ b/boards/xtensa/esp32/esp32-sparrow-kit/src/Make.defs
@@ -35,10 +35,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += esp32_gpio.c
 endif
diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h 
b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h
index 61ab018c68..c73afcf32d 100644
--- a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h
+++ b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32-sparrow-kit.h
@@ -89,16 +89,6 @@
 
 int esp32_bringup(void);
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- *
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_spiflash_init
  *
diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c 
b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c
index a7a404f356..593ba16795 100644
--- a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_bringup.c
@@ -120,6 +120,10 @@
 #  include "esp32_lcd_backpack.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "esp32-sparrow-kit.h"
 
 /****************************************************************************
@@ -184,8 +188,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.c
deleted file mode 100644
index 47f224f663..0000000000
--- a/boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
- * boards/xtensa/esp32/esp32-sparrow-kit/src/esp32_mmcsd.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 <debug.h>
-#include <nuttx/config.h>
-#include <nuttx/mmcsd.h>
-#include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "esp32_spi.h"
-#include "esp32-sparrow-kit.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor)
-{
-  struct spi_dev_s *spi;
-  int rv;
-
-  mcinfo("INFO: Initializing mmcsd card\n");
-
-  spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
-  if (spi == NULL)
-    {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
-      return -ENODEV;
-    }
-
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
-    {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
-    }
-
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
-  return OK;
-}
diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs 
b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs
index ab2bf6444e..1b50c05b12 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs
+++ b/boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs
@@ -35,10 +35,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += esp32_gpio.c
 endif
@@ -50,4 +46,3 @@ endif
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
-
diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h 
b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h
index aea94dc404..862cf630fe 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h
+++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32-wrover-kit.h
@@ -92,16 +92,6 @@
 
 int esp32_bringup(void);
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- *
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_spiflash_init
  *
diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c 
b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c
index 844284493e..65d84ec9b4 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c
@@ -108,6 +108,10 @@
 #   include "esp32_zerocross.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "esp32-wrover-kit.h"
 
 /****************************************************************************
@@ -172,8 +176,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.c
deleted file mode 100644
index c561908e50..0000000000
--- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
- * boards/xtensa/esp32/esp32-wrover-kit/src/esp32_mmcsd.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 <debug.h>
-#include <nuttx/config.h>
-#include <nuttx/mmcsd.h>
-#include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "esp32_spi.h"
-#include "esp32-wrover-kit.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor)
-{
-  struct spi_dev_s *spi;
-  int rv;
-
-  mcinfo("INFO: Initializing mmcsd card\n");
-
-  spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
-  if (spi == NULL)
-    {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
-      return -ENODEV;
-    }
-
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
-    {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
-    }
-
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
-  return OK;
-}
diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs 
b/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs
index 15527116f0..967db5dfa7 100644
--- a/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs
+++ b/boards/xtensa/esp32/ttgo_eink5_v2/src/Make.defs
@@ -29,10 +29,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += esp32_gpio.c
 endif
@@ -56,4 +52,3 @@ endif
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
-
diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c 
b/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c
index d72fdfbd01..747840629a 100644
--- a/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/ttgo_eink5_v2/src/esp32_bringup.c
@@ -135,6 +135,10 @@
 #  include "esp32_lcd_backpack.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "ttgo_eink5_v2.h"
 
 /****************************************************************************
@@ -222,8 +226,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h 
b/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h
index c3eeb27942..b8033d050f 100644
--- a/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h
+++ b/boards/xtensa/esp32/ttgo_eink5_v2/src/ttgo_eink5_v2.h
@@ -100,15 +100,6 @@
 
 int esp32_bringup(void);
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_gpio_init
  ****************************************************************************/
diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs 
b/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs
index e5f3d24f8b..722539876d 100644
--- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs
+++ b/boards/xtensa/esp32/ttgo_t_display_esp32/src/Make.defs
@@ -29,10 +29,6 @@ CSRCS += esp32_reset.c
 endif
 endif
 
-ifeq ($(CONFIG_MMCSD),y)
-CSRCS += esp32_mmcsd.c
-endif
-
 ifeq ($(CONFIG_DEV_GPIO),y)
 CSRCS += esp32_gpio.c
 endif
@@ -56,4 +52,3 @@ endif
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
-
diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c 
b/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c
index b986a6ce97..48a0272e21 100644
--- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_bringup.c
@@ -144,6 +144,10 @@
 #  include "esp32_lcd_backpack.h"
 #endif
 
+#ifdef CONFIG_MMCSD_SPI
+#  include "esp32_board_sdmmc.h"
+#endif
+
 #include "ttgo_t_display_esp32.h"
 
 /****************************************************************************
@@ -225,8 +229,8 @@ int esp32_bringup(void)
     }
 #endif
 
-#ifdef CONFIG_MMCSD
-  ret = esp32_mmcsd_initialize(0);
+#ifdef CONFIG_MMCSD_SPI
+  ret = board_sdmmc_initialize();
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret);
diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c 
b/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c
deleted file mode 100644
index 39683322cf..0000000000
--- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
- * boards/xtensa/esp32/ttgo_t_display_esp32/src/esp32_mmcsd.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 <debug.h>
-#include <nuttx/config.h>
-#include <nuttx/mmcsd.h>
-#include <nuttx/spi/spi.h>
-#include <pthread.h>
-#include <sched.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "esp32_spi.h"
-#include "ttgo_t_display_esp32.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor)
-{
-  struct spi_dev_s *spi;
-  int rv;
-
-  mcinfo("INFO: Initializing mmcsd card\n");
-
-  spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
-  if (spi == NULL)
-    {
-      mcerr("ERROR: Failed to initialize SPI port %d\n", 2);
-      return -ENODEV;
-    }
-
-  rv = mmcsd_spislotinitialize(minor, 0, spi);
-  if (rv < 0)
-    {
-      mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n",
-            2, 0);
-      return rv;
-    }
-
-  spiinfo("INFO: mmcsd card has been initialized successfully\n");
-  return OK;
-}
diff --git 
a/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h 
b/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h
index 78736d2b1f..f9b6a675c9 100644
--- a/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h
+++ b/boards/xtensa/esp32/ttgo_t_display_esp32/src/ttgo_t_display_esp32.h
@@ -94,15 +94,6 @@
 
 int esp32_bringup(void);
 
-/****************************************************************************
- * Name: esp32_mmcsd_initialize
- *
- * Description:
- *   Initialize SPI-based SD card and card detect thread.
- ****************************************************************************/
-
-int esp32_mmcsd_initialize(int minor);
-
 /****************************************************************************
  * Name: esp32_gpio_init
  ****************************************************************************/


Reply via email to