boards/xtensa/esp32/esp32-core: Add support for an MMCSD card over SPI.
This commit is contained in:
parent
3560e16ac7
commit
41f432eb18
7 changed files with 236 additions and 0 deletions
|
|
@ -771,6 +771,17 @@ NOTES:
|
|||
crash in the waitpid() test. At the time of the crash, there is
|
||||
extensive memory corruption and a user exception occurs (cause=28).
|
||||
|
||||
mmcsdspi:
|
||||
|
||||
This config tests the SPI driver by connecting an SD Card reader over SPI.
|
||||
SPI2 is used and kept with the default IOMUX pins, i.e.:
|
||||
CS --> 15
|
||||
SCK --> 14
|
||||
MOSI --> 13
|
||||
MISO --> 12
|
||||
Once booted the following command is used to mount a FAT file system:
|
||||
mount -t vfat /dev/mmcsd0 /mnt
|
||||
|
||||
Things to Do
|
||||
============
|
||||
|
||||
|
|
|
|||
59
boards/xtensa/esp32/esp32-core/configs/mmcsdspi/defconfig
Normal file
59
boards/xtensa/esp32/esp32-core/configs/mmcsdspi/defconfig
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# 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_ESP32_SPI2_DMA is not set
|
||||
# CONFIG_MMCSD_HAVE_CARDDETECT is not set
|
||||
# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set
|
||||
# CONFIG_MMCSD_MMCSUPPORT is not set
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
# CONFIG_NSH_CMDPARMS is not set
|
||||
# CONFIG_SPI_EXCHANGE is not set
|
||||
CONFIG_ARCH="xtensa"
|
||||
CONFIG_ARCH_BOARD="esp32-core"
|
||||
CONFIG_ARCH_BOARD_ESP32CORE=y
|
||||
CONFIG_ARCH_CHIP="esp32"
|
||||
CONFIG_ARCH_CHIP_ESP32=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_XTENSA=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_ESP32_SPI2=y
|
||||
CONFIG_ESP32_UART0=y
|
||||
CONFIG_FAT_LCNAMES=y
|
||||
CONFIG_FAT_LFN=y
|
||||
CONFIG_FS_FAT=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MMCSD=y
|
||||
CONFIG_MMCSD_SPICLOCK=4000000
|
||||
CONFIG_MM_REGIONS=2
|
||||
CONFIG_NFILE_DESCRIPTORS=8
|
||||
CONFIG_NFILE_STREAMS=8
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_MMCSDSPIPORTNO=2
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=114688
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_START_DAY=6
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_START_YEAR=2011
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
|
|
@ -45,6 +45,14 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
|
|||
CSRCS += esp32_appinit.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ESP32_SPI),y)
|
||||
CSRCS += esp32_spi.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_MMCSD),y)
|
||||
CSRCS += esp32_mmcsd.c
|
||||
endif
|
||||
|
||||
SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32.template
|
||||
SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32_out.ld
|
||||
|
||||
|
|
|
|||
|
|
@ -78,5 +78,14 @@
|
|||
|
||||
int esp32_bringup(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_mmcsd_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize SPI-based SD card and card detect thread.
|
||||
****************************************************************************/
|
||||
|
||||
int esp32_mmcsd_initialize(int minor);
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARDS_XTENSA_ESP32_ESP32_CORE_SRC_ESP32_CORE_H */
|
||||
|
|
|
|||
|
|
@ -81,6 +81,15 @@ int esp32_bringup(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MMCSD
|
||||
ret = esp32_mmcsd_initialize(0);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize SD slot %d: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If we got here then perhaps not all initialization was successful, but
|
||||
* at least enough succeeded to bring-up NSH with perhaps reduced
|
||||
* capabilities.
|
||||
|
|
|
|||
84
boards/xtensa/esp32/esp32-core/src/esp32_mmcsd.c
Normal file
84
boards/xtensa/esp32/esp32-core/src/esp32_mmcsd.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/****************************************************************************
|
||||
* boards/xtensa/esp32/esp32-core/src/esp32_mmcsd.c
|
||||
*
|
||||
* 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-core.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;
|
||||
}
|
||||
56
boards/xtensa/esp32/esp32-core/src/esp32_spi.c
Normal file
56
boards/xtensa/esp32/esp32-core/src/esp32_spi.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/****************************************************************************
|
||||
* boards/xtensa/esp32/esp32-core/src/esp32_spi.c
|
||||
*
|
||||
* 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 <stdbool.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "esp32-core.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spi2_status
|
||||
****************************************************************************/
|
||||
|
||||
uint8_t esp32_spi2_status(FAR struct spi_dev_s *dev, uint32_t devid)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
|
||||
#ifdef CONFIG_MMCSD_SPI
|
||||
if (devid == SPIDEV_MMCSD(0))
|
||||
{
|
||||
status |= SPI_STATUS_PRESENT;
|
||||
}
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue