mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 06:42:32 +08:00
boards/risc-v: add support for SD Card over SPI on ESP32-C3|C6|H2
Add board support for SD Card over SPI for ESP32C3, ESP32C6 and ESP32H2. Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
This commit is contained in:
committed by
Alan C. Assis
parent
7352e8ebfa
commit
6f19c59d26
@@ -0,0 +1,76 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/risc-v/esp32c3/common/include/esp_board_mmcsd.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_RISCV_ESP32C3_COMMON_INCLUDE_ESP_BOARD_MMCSD_H
|
||||||
|
#define __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP_BOARD_MMCSD_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: esp_mmcsd_spi_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize SPI-based SD card.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_MMCSD_SPI
|
||||||
|
int esp_mmcsd_spi_initialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP_BOARD_MMCSD_H */
|
||||||
@@ -70,6 +70,10 @@ ifeq ($(CONFIG_SENSORS_BMP180),y)
|
|||||||
CSRCS += esp_board_bmp180.c
|
CSRCS += esp_board_bmp180.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_MMCSD_SPI),y)
|
||||||
|
CSRCS += esp_board_mmcsd.c
|
||||||
|
endif
|
||||||
|
|
||||||
DEPPATH += --dep-path src
|
DEPPATH += --dep-path src
|
||||||
VPATH += :src
|
VPATH += :src
|
||||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/risc-v/esp32c3/common/src/esp_board_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 "espressif/esp_spi.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp_mmcsd_spi_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize SPI-based SD card.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* minor - The MMC/SD minor device number. The MMC/SD device will be
|
||||||
|
* registered as /dev/mmcsdN where N is the minor number
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp_mmcsd_spi_initialize(void)
|
||||||
|
{
|
||||||
|
struct spi_dev_s *spi;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
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 = esp_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
|
||||||
|
|
||||||
|
if (spi == NULL)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to initialize SPI%d.\n",
|
||||||
|
CONFIG_NSH_MMCSDSPIPORTNO);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mounts to /dev/mmcsdN where N in the minor number */
|
||||||
|
|
||||||
|
ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR,
|
||||||
|
CONFIG_NSH_MMCSDSLOTNO, spi);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to bind SPI%d to SD slot %d\n",
|
||||||
|
CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
syslog(LOG_INFO, "INFO: MMCSD initialized\n");
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
@@ -52,6 +52,11 @@ uint8_t esp_spi2_status(struct spi_dev_s *dev, uint32_t devid)
|
|||||||
{
|
{
|
||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
|
|
||||||
|
if (devid == SPIDEV_MMCSD(0))
|
||||||
|
{
|
||||||
|
return SPI_STATUS_PRESENT;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,10 @@
|
|||||||
# include "espressif/esp_sha.h"
|
# include "espressif/esp_sha.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MMCSD_SPI
|
||||||
|
# include "esp_board_mmcsd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "esp32c3-generic.h"
|
#include "esp32c3-generic.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -261,6 +265,14 @@ int esp_bringup(void)
|
|||||||
# endif /* CONFIG_ESPRESSIF_SPI_BITBANG */
|
# endif /* CONFIG_ESPRESSIF_SPI_BITBANG */
|
||||||
#endif /* CONFIG_ESPRESSIF_SPI */
|
#endif /* CONFIG_ESPRESSIF_SPI */
|
||||||
|
|
||||||
|
#if defined(CONFIG_ESPRESSIF_SPI) && defined(CONFIG_MMCSD_SPI)
|
||||||
|
ret = esp_mmcsd_spi_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to init MMCSD SPI\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ESPRESSIF_SPIFLASH
|
#ifdef CONFIG_ESPRESSIF_SPIFLASH
|
||||||
ret = board_spiflash_init();
|
ret = board_spiflash_init();
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/risc-v/esp32c6/common/include/esp_board_mmcsd.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_RISCV_ESP32C6_COMMON_INCLUDE_ESP_BOARD_MMCSD_H
|
||||||
|
#define __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP_BOARD_MMCSD_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: esp_mmcsd_spi_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize SPI-based SD card.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_MMCSD_SPI
|
||||||
|
int esp_mmcsd_spi_initialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP_BOARD_MMCSD_H */
|
||||||
@@ -90,6 +90,10 @@ ifeq ($(CONFIG_NCV7410),y)
|
|||||||
CSRCS += esp_board_ncv7410.c
|
CSRCS += esp_board_ncv7410.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_MMCSD_SPI),y)
|
||||||
|
CSRCS += esp_board_mmcsd.c
|
||||||
|
endif
|
||||||
|
|
||||||
DEPPATH += --dep-path src
|
DEPPATH += --dep-path src
|
||||||
VPATH += :src
|
VPATH += :src
|
||||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/risc-v/esp32c6/common/src/esp_board_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 "espressif/esp_spi.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp_mmcsd_spi_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize SPI-based SD card.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* minor - The MMC/SD minor device number. The MMC/SD device will be
|
||||||
|
* registered as /dev/mmcsdN where N is the minor number
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp_mmcsd_spi_initialize(void)
|
||||||
|
{
|
||||||
|
struct spi_dev_s *spi;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
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 = esp_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
|
||||||
|
|
||||||
|
if (spi == NULL)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to initialize SPI%d.\n",
|
||||||
|
CONFIG_NSH_MMCSDSPIPORTNO);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mounts to /dev/mmcsdN where N in the minor number */
|
||||||
|
|
||||||
|
ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR,
|
||||||
|
CONFIG_NSH_MMCSDSLOTNO, spi);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to bind SPI%d to SD slot %d\n",
|
||||||
|
CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
syslog(LOG_INFO, "INFO: MMCSD initialized\n");
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
@@ -52,6 +52,11 @@ uint8_t esp_spi2_status(struct spi_dev_s *dev, uint32_t devid)
|
|||||||
{
|
{
|
||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
|
|
||||||
|
if (devid == SPIDEV_MMCSD(0))
|
||||||
|
{
|
||||||
|
return SPI_STATUS_PRESENT;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,10 @@
|
|||||||
# include "esp_board_ncv7410.h"
|
# include "esp_board_ncv7410.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MMCSD_SPI
|
||||||
|
# include "esp_board_mmcsd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "esp32c6-devkitc.h"
|
#include "esp32c6-devkitc.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -296,6 +300,14 @@ int esp_bringup(void)
|
|||||||
# endif /* CONFIG_ESPRESSIF_SPI_BITBANG */
|
# endif /* CONFIG_ESPRESSIF_SPI_BITBANG */
|
||||||
#endif /* CONFIG_ESPRESSIF_SPI */
|
#endif /* CONFIG_ESPRESSIF_SPI */
|
||||||
|
|
||||||
|
#if defined(CONFIG_ESPRESSIF_SPI) && defined(CONFIG_MMCSD_SPI)
|
||||||
|
ret = esp_mmcsd_spi_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to init MMCSD SPI\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ESPRESSIF_SPIFLASH
|
#ifdef CONFIG_ESPRESSIF_SPIFLASH
|
||||||
ret = board_spiflash_init();
|
ret = board_spiflash_init();
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/risc-v/esp32h2/common/include/esp_board_mmcsd.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_RISCV_ESP32H2_COMMON_INCLUDE_ESP_BOARD_MMCSD_H
|
||||||
|
#define __BOARDS_RISCV_ESP32H2_COMMON_INCLUDE_ESP_BOARD_MMCSD_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: esp_mmcsd_spi_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize SPI-based SD card.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_MMCSD_SPI
|
||||||
|
int esp_mmcsd_spi_initialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __BOARDS_RISCV_ESP32H2_COMMON_INCLUDE_ESP_BOARD_MMCSD_H */
|
||||||
@@ -74,6 +74,10 @@ ifeq ($(CONFIG_ESP_PCNT),y)
|
|||||||
CSRCS += esp_board_pcnt.c
|
CSRCS += esp_board_pcnt.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_MMCSD_SPI),y)
|
||||||
|
CSRCS += esp_board_mmcsd.c
|
||||||
|
endif
|
||||||
|
|
||||||
DEPPATH += --dep-path src
|
DEPPATH += --dep-path src
|
||||||
VPATH += :src
|
VPATH += :src
|
||||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/risc-v/esp32h2/common/src/esp_board_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 "espressif/esp_spi.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp_mmcsd_spi_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize SPI-based SD card.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* minor - The MMC/SD minor device number. The MMC/SD device will be
|
||||||
|
* registered as /dev/mmcsdN where N is the minor number
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp_mmcsd_spi_initialize(void)
|
||||||
|
{
|
||||||
|
struct spi_dev_s *spi;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
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 = esp_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO);
|
||||||
|
|
||||||
|
if (spi == NULL)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to initialize SPI%d.\n",
|
||||||
|
CONFIG_NSH_MMCSDSPIPORTNO);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mounts to /dev/mmcsdN where N in the minor number */
|
||||||
|
|
||||||
|
ret = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR,
|
||||||
|
CONFIG_NSH_MMCSDSLOTNO, spi);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to bind SPI%d to SD slot %d\n",
|
||||||
|
CONFIG_NSH_MMCSDSPIPORTNO, CONFIG_NSH_MMCSDSLOTNO);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
syslog(LOG_INFO, "INFO: MMCSD initialized\n");
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
@@ -52,6 +52,11 @@ uint8_t esp_spi2_status(struct spi_dev_s *dev, uint32_t devid)
|
|||||||
{
|
{
|
||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
|
|
||||||
|
if (devid == SPIDEV_MMCSD(0))
|
||||||
|
{
|
||||||
|
return SPI_STATUS_PRESENT;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,10 @@
|
|||||||
# include "espressif/esp_sha.h"
|
# include "espressif/esp_sha.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_MMCSD_SPI
|
||||||
|
# include "esp_board_mmcsd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "esp32h2-devkit.h"
|
#include "esp32h2-devkit.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -282,6 +286,14 @@ int esp_bringup(void)
|
|||||||
# endif /* CONFIG_ESPRESSIF_SPI_BITBANG */
|
# endif /* CONFIG_ESPRESSIF_SPI_BITBANG */
|
||||||
#endif /* CONFIG_ESPRESSIF_SPI */
|
#endif /* CONFIG_ESPRESSIF_SPI */
|
||||||
|
|
||||||
|
#if defined(CONFIG_ESPRESSIF_SPI) && defined(CONFIG_MMCSD_SPI)
|
||||||
|
ret = esp_mmcsd_spi_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: failed to init MMCSD SPI\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ESPRESSIF_SPIFLASH
|
#ifdef CONFIG_ESPRESSIF_SPIFLASH
|
||||||
ret = board_spiflash_init();
|
ret = board_spiflash_init();
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|||||||
Reference in New Issue
Block a user