summaryrefslogtreecommitdiff
path: root/nuttx/configs
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-08-05 16:21:24 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-08-05 16:21:24 -0600
commitf959801dada491a15db46b48bc9d86408e31e915 (patch)
treed8d71040a786ba20edc9329a459972adacc276a4 /nuttx/configs
parent5bf5e918c77fb5ba2e5cf6f5c2f2c472d806c854 (diff)
downloadpx4-nuttx-f959801dada491a15db46b48bc9d86408e31e915.tar.gz
px4-nuttx-f959801dada491a15db46b48bc9d86408e31e915.tar.bz2
px4-nuttx-f959801dada491a15db46b48bc9d86408e31e915.zip
SAMA5: Add HSMCI memory card driver support
Diffstat (limited to 'nuttx/configs')
-rw-r--r--nuttx/configs/sama5d3x-ek/README.txt62
-rw-r--r--nuttx/configs/sama5d3x-ek/src/Makefile12
-rw-r--r--nuttx/configs/sama5d3x-ek/src/sam_at25.c166
-rw-r--r--nuttx/configs/sama5d3x-ek/src/sam_hsmci.c296
-rw-r--r--nuttx/configs/sama5d3x-ek/src/sam_nsh.c100
-rw-r--r--nuttx/configs/sama5d3x-ek/src/sama5d3x-ek.h91
6 files changed, 685 insertions, 42 deletions
diff --git a/nuttx/configs/sama5d3x-ek/README.txt b/nuttx/configs/sama5d3x-ek/README.txt
index 52b505a94..37b186aad 100644
--- a/nuttx/configs/sama5d3x-ek/README.txt
+++ b/nuttx/configs/sama5d3x-ek/README.txt
@@ -74,6 +74,7 @@ Contents
- Buttons and LEDs
- Serial Consoles
- Serial FLASH
+ - HSMCI Card Slots
- SAMA5D3x-EK Configuration Options
- Configurations
@@ -527,6 +528,42 @@ Serial FLASH
PD13; on the Ronetix schematic, JP11 seems only to bypass a resistor (may
not be populated?). I think closing JP1 is correct in either case.
+HSMCI Card Slots
+================
+
+ The SAMA5D3x-EK provides a two SD memory card slots: (1) a full size SD
+ card slot (J7 labeled MCI0), and (2) a microSD memory card slot (J6
+ labeled MCI1).
+
+ The full size SD card slot connects via HSMCI0. The card detect discrete
+ is available on PB17 (pulled high). The write protect descrete is tied to
+ ground (via PP6) and not available to software. The slot supports 8-bit
+ wide transfer mode, but the NuttX driver currently uses only the 4-bit
+ wide transfer mode
+
+ PD17 MCI0_CD
+ PD1 MCI0_DA0
+ PD2 MCI0_DA1
+ PD3 MCI0_DA2
+ PD4 MCI0_DA3
+ PD5 MCI0_DA4
+ PD6 MCI0_DA5
+ PD7 MCI0_DA6
+ PD8 MCI0_DA7
+ PD9 MCI0_CK
+ PD0 MCI0_CDA
+
+ The microSD connects vi HSMCI1. The card detect discrete is available on
+ PB18 (pulled high):
+
+ PD18 MCI1_CD
+ PB20 MCI1_DA0
+ PB21 MCI1_DA1
+ PB22 MCI1_DA2
+ PB23 MCI1_DA3
+ PB24 MCI1_CK
+ PB19 MCI1_CDA
+
SAMA5D3x-EK Configuration Options
=================================
@@ -968,6 +1005,31 @@ Configurations
nsh> cat /mnt/sdcard/atest.txt
This is a test
+ 9. Enabling HSMCI support. The SAMA5D3x-EK provides a two SD memory card
+ slots: (1) a full size SD card slot (J7 labeled MCI0), and (2) a
+ microSD memory card slot (J6 labeled MCI1). The full size SD card
+ slot connects via HSMCI0; the microSD connects vi HSMCI1. Support
+ for both SD slots can be enabled with the following settings:
+
+ System Type->ATSAMA5 Peripheral Support
+ CONFIG_SAMA5_HSMCI0=y : Enable HSMCI0 support
+ CONFIG_SAMA5_HSMCI1=y : Enable HSMCI1 support
+ CONFIG_SAMA5_DMAC0=y : DMAC0 is needed by HSMCI0
+ CONFIG_SAMA5_DMAC1=y : DMAC1 is needed by HSMCI1
+
+ Device Drivers ->
+ CONFIG_MMCSD=y : Enable MMC/SD support
+ CONFIG_MMSCD_NSLOTS=1 : One slot per driver instance
+ CONFIG_MMCSD_SDIO=y : SDIO-based MMC/SD support
+ CONFIG_SDIO_DMA=y : Use SDIO DMA
+ CONFIG_SDIO_BLOCKSETUP=y : Needs to know block sizes
+
+ Library Routines
+ CONFIG_SCHED_WORKQUEUE=y : Driver needs work queue support
+
+ Application Configuration -> NSH Library
+ CONFIG_NSH_ARCHINIT=y : NSH board-initialization
+
STATUS:
2013-7-19: This configuration (as do the others) run at 396MHz.
The SAMA5D3 can run at 536MHz. I still need to figure out the
diff --git a/nuttx/configs/sama5d3x-ek/src/Makefile b/nuttx/configs/sama5d3x-ek/src/Makefile
index 7d8ee2595..420568701 100644
--- a/nuttx/configs/sama5d3x-ek/src/Makefile
+++ b/nuttx/configs/sama5d3x-ek/src/Makefile
@@ -66,6 +66,18 @@ ifeq ($(CONFIG_SAMA5_NOR_MAIN),y)
CSRCS += nor_main.c
endif
+ifeq ($(CONFIG_MTD_AT25),y)
+CSRCS += sam_at25.c
+endif
+
+ifeq ($(CONFIG_SAMA5_HSMCI0),y)
+CSRCS += sam_hsmci.c
+else
+ifeq ($(CONFIG_SAMA5_HSMCI1),y)
+CSRCS += sam_hsmci.c
+endif
+endif
+
ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += sam_nsh.c
endif
diff --git a/nuttx/configs/sama5d3x-ek/src/sam_at25.c b/nuttx/configs/sama5d3x-ek/src/sam_at25.c
new file mode 100644
index 000000000..4f4d19cf0
--- /dev/null
+++ b/nuttx/configs/sama5d3x-ek/src/sam_at25.c
@@ -0,0 +1,166 @@
+/****************************************************************************
+ * config/sama5d3x-ek/src/sam_at25.c
+ *
+ * Copyright (C) 2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/mount.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <errno.h>
+#include <debug.h>
+
+#ifdef CONFIG_SAMA5_SPI0
+# include <nuttx/spi/spi.h>
+# include <nuttx/mtd.h>
+# include <nuttx/fs/nxffs.h>
+
+# include "sam_spi.h"
+#endif
+
+#include "sama5d3x-ek.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+/* Can't support the AT25 device if it SPI0 or AT25 support are not enabled */
+
+#define HAVE_AT25 1
+#if !defined(CONFIG_SAMA5_SPI0) || !defined(CONFIG_MTD_AT25)
+# undef HAVE_AT25
+#endif
+
+/* Can't support AT25 features if mountpoints are disabled or if we were not
+ * asked to mount the AT25 part
+ */
+
+#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_SAMA5_AT25_AUTOMOUNT)
+# undef HAVE_AT25
+#endif
+
+/* If we are going to mount the AT25, then they user must also have told
+ * us what to do with it by setting one of these.
+ */
+
+#if !defined(CONFIG_SAMA5_AT25_FTL) && !defined(CONFIG_SAMA5_AT25_NXFFS)
+# undef HAVE_AT25
+#endif
+
+#if defined(CONFIG_SAMA5_AT25_FTL) && defined(CONFIG_SAMA5_AT25_NXFFS)
+# warning Both CONFIG_SAMA5_AT25_FTL and CONFIG_SAMA5_AT25_NXFFS are set
+# warning Ignoring CONFIG_SAMA5_AT25_NXFFS
+# undef CONFIG_SAMA5_AT25_NXFFS
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sam_at25_initialize
+ *
+ * Description:
+ * Initialize and configure the AT25 SPI Flash
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MTD_AT25
+int sam_at25_initialize(int minor)
+{
+#ifdef HAVE_AT25
+ FAR struct spi_dev_s *spi;
+ FAR struct mtd_dev_s *mtd;
+ int ret;
+
+ /* Get the SPI port driver */
+
+ spi = up_spiinitialize(AT25_PORT);
+ if (!spi)
+ {
+ fdbg("ERROR: Failed to initialize SPI port %d\n", AT25_PORT);
+ return -ENODEV;
+ }
+
+ /* Now bind the SPI interface to the AT25 SPI FLASH driver */
+
+ mtd = at25_initialize(spi);
+ if (!mtd)
+ {
+ fdbg("ERROR: Failed to bind SPI port %d to the AT25 FLASH driver\n");
+ return -ENODEV;
+ }
+
+#if defined(CONFIG_SAMA5_AT25_FTL)
+ /* And finally, use the FTL layer to wrap the MTD driver as a block driver */
+
+ ret = ftl_initialize(CONFIG_NSH_MMCSDMINOR, mtd);
+ if (ret < 0)
+ {
+ fdbg("ERROR: Initialize the FTL layer\n");
+ return ret;
+ }
+
+#elif defined(CONFIG_SAMA5_AT25_NXFFS)
+ /* Initialize to provide NXFFS on the MTD interface */
+
+ ret = nxffs_initialize(mtd);
+ if (ret < 0)
+ {
+ fdbg("ERROR: NXFFS initialization failed: %d\n", -ret);
+ return ret;
+ }
+
+ /* Mount the file system at /mnt/at25 */
+
+ ret = mount(NULL, "/mnt/at25", "nxffs", 0, NULL);
+ if (ret < 0)
+ {
+ fdbg("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
+ return ret;
+ }
+
+#endif
+#endif
+
+ return OK;
+}
+
+#endif
diff --git a/nuttx/configs/sama5d3x-ek/src/sam_hsmci.c b/nuttx/configs/sama5d3x-ek/src/sam_hsmci.c
new file mode 100644
index 000000000..635bcfeda
--- /dev/null
+++ b/nuttx/configs/sama5d3x-ek/src/sam_hsmci.c
@@ -0,0 +1,296 @@
+/****************************************************************************
+ * config/sama5d3x-ek/src/sam_hsmci.c
+ *
+ * Copyright (C) 2013 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+/* The SAMA5D3x-EK provides a two SD memory card slots: (1) a full size SD card
+ * slot (J7 labeled MCI0), and (2) a microSD memory card slot (J6 labeled MCI1).
+ *
+ * The full size SD card slot connects via HSMCI0. The card detect discrete
+ * is available on PB17 (pulled high). The write protect descrete is tied to
+ * ground (via PP6) and not available to software. The slot supports 8-bit
+ * wide transfer mode, but the NuttX driver currently uses only the 4-bit
+ * wide transfer mode
+ *
+ * PD17 MCI0_CD
+ * PD1 MCI0_DA0
+ * PD2 MCI0_DA1
+ * PD3 MCI0_DA2
+ * PD4 MCI0_DA3
+ * PD5 MCI0_DA4
+ * PD6 MCI0_DA5
+ * PD7 MCI0_DA6
+ * PD8 MCI0_DA7
+ * PD9 MCI0_CK
+ * PD0 MCI0_CDA
+ *
+ * The microSD connects vi HSMCI1. The card detect discrete is available on
+ * PB18 (pulled high):
+ *
+ * PD18 MCI1_CD
+ * PB20 MCI1_DA0
+ * PB21 MCI1_DA1
+ * PB22 MCI1_DA2
+ * PB23 MCI1_DA3
+ * PB24 MCI1_CK
+ * PB19 MCI1_CDA
+ */
+
+
+/* SPI Chip Selects *****************************************************************/
+/* Both the Ronetix and Embest versions of the SAMAD3x CPU modules include an
+ * Atmel AT25DF321A, 32-megabit, 2.7-volt SPI serial flash. The SPI
+ * connection is as follows:
+ *
+ * AT25DF321A SAMA5
+ * --------------- -----------------------------------------------
+ * SI PD11 SPI0_MOSI
+ * SO PD10 SPI0_MIS0
+ * SCK PD12 SPI0_SPCK
+ * /CS PD13 via NL17SZ126 if JP1 is closed (See below)
+ *
+ * JP1 and JP2 seem to related to /CS on the Ronetix board, but the usage is
+ * less clear. For the Embest module, JP1 must be closed to connect /CS to
+ * PD13; on the Ronetix schematic, JP11 seems only to bypass a resistor (may
+ * not be populated?). I think closing JP1 is correct in either case.
+ */
+
+#define GPIO_AT25_NPCS0 (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \
+ GPIO_PORT_PIOD | GPIO_PIN13)
+#define AT25_PORT SPI0_CS0
+
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/sdio.h>
+#include <nuttx/mmcsd.h>
+
+#include "sam_hsmci.h"
+#include "sama5d3x-ek.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+/* This needs to be extended. The card detect GPIO must be configured as an
+ * interrupt. When the interrupt indicating that a card has been inserted
+ * or removed is received, this function must call sio_mediachange() to
+ * handle that event.
+ */
+
+#warning "Card detect interrupt handling needed"
+
+/* Configuration ************************************************************/
+
+#define HAVE_MMCSD 1
+
+/* Can't support MMC/SD if the card interface(s) are not enable */
+
+#if !defined(CONFIG_SAMA5_HSMCI0) && !defined(CONFIG_SAMA5_HSMCI0)
+# undef HAVE_MMCSD
+#endif
+
+/* Can't support MMC/SD features if mountpoints are disabled */
+
+#if defined(CONFIG_DISABLE_MOUNTPOINT)
+# undef HAVE_MMCSD
+#endif
+
+#ifdef HAVE_MMCSD
+# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0
+# undef CONFIG_NSH_MMCSDSLOTNO
+# endif
+
+# ifndef CONFIG_NSH_MMCSDMINOR
+# define CONFIG_NSH_MMCSDMINOR 0
+# endif
+
+# ifndef CONFIG_NSH_MMCSDSLOTNO
+# define CONFIG_NSH_MMCSDSLOTNO 0
+# endif
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+/************************************************************************************
+ * Name: sam_hsmci_gpioinit
+ *
+ * Description:
+ * Initialize HSMCI support. This function is called very early in board
+ * initialization.
+ *
+ ************************************************************************************/
+
+#ifdef HAVE_MMCSD
+static void sam_hsmci_gpioinit(int slotno)
+{
+#ifdef CONFIG_SAMA5_HSMCI0
+#ifdef CONFIG_SAMA5_HSMCI1
+ if (slotno == 0)
+#endif
+ {
+ sam_configgpio(GPIO_MCI0_CD);
+ }
+#ifdef CONFIG_SAMA5_HSMCI1
+ else
+#endif
+#endif
+
+#ifdef CONFIG_SAMA5_HSMCI1
+ {
+ sam_configgpio(GPIO_MCI1_CD);
+ }
+#endif
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sam_hsmci_initialize
+ *
+ * Description:
+ * Perform architecture specific initialization
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_SAMA5_HSMCI0) || defined(CONFIG_SAMA5_HSMCI1)
+int sam_hsmci_initialize(int slotno, int minor)
+{
+#ifdef HAVE_MMCSD
+ FAR struct sdio_dev_s *sdio;
+ int ret;
+
+ /* Initialize card-detect and write-protect GPIOs */
+
+ sam_hsmci_gpioinit(slotno);
+
+ /* Mount the SDIO-based MMC/SD block driver */
+ /* First, get an instance of the SDIO interface */
+
+ sdio = sdio_initialize(slotno);
+ if (!sdio)
+ {
+ fdbg("Failed to initialize SDIO slot %d\n", slotno);
+ return -ENODEV;
+ }
+
+ /* Now bind the SDIO interface to the MMC/SD driver */
+
+ ret = mmcsd_slotinitialize(minor, sdio);
+ if (ret != OK)
+ {
+ fdbg("Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
+ return ret;
+ }
+
+ /* Then inform the HSMCI driver if there is or is not a card in the slot. */
+
+ sdio_mediachange(sdio, sam_cardinserted(slotno));
+#endif
+
+ return OK;
+}
+
+/************************************************************************************
+ * Name: sam_cardinserted
+ *
+ * Description:
+ * Check if a card is inserted into the selected HSMCI slot
+ *
+ ************************************************************************************/
+
+#if defined(CONFIG_SAMA5_HSMCI0) || defined(CONFIG_SAMA5_HSMCI1)
+bool sam_cardinserted(int slotno)
+{
+#ifdef HAVE_MMCSD
+
+#ifdef CONFIG_SAMA5_HSMCI0
+#ifdef CONFIG_SAMA5_HSMCI1
+ if (slotno == 0)
+#endif /* CONFIG_SAMA5_HSMCI1 */
+ {
+ bool inserted = sam_gpioread(GPIO_MCI0_CD);
+ fvdbg("Slot 0 inserted: %s\n", inserted ? "NO" : "YES");
+ return !inserted;
+ }
+
+#ifdef CONFIG_SAMA5_HSMCI1
+ else
+#endif /* CONFIG_SAMA5_HSMCI1 */
+#endif /* CONFIG_SAMA5_HSMCI0 */
+
+#ifdef CONFIG_SAMA5_HSMCI1
+ {
+ bool inserted = sam_gpioread(GPIO_MCI1_CD);
+ fvdbg("Slot 1 inserted: %s\n", inserted ? "NO" : "YES");
+ return !inserted;
+ }
+
+#endif /* CONFIG_SAMA5_HSMCI1 */
+#else /* HAVE_MMCSD */
+
+ return false;
+
+#endif /* HAVE_MMCSD */
+}
+#endif /* CONFIG_SAMA5_HSMCIO || CONFIG_SAMA5_HSMCI1 */
+
+/************************************************************************************
+ * Name: sam_writeprotected
+ *
+ * Description:
+ * Check if a card is inserted into the selected HSMCI slot
+ *
+ ************************************************************************************/
+
+#if defined(CONFIG_SAMA5_HSMCI0) || defined(CONFIG_SAMA5_HSMCI1)
+bool sam_writeprotected(int slotno)
+{
+ /* There are no write protect pins */
+
+ return false;
+}
+#endif
+
+#endif /* CONFIG_SAMA5_HSMCI0 || CONFIG_SAMA5_HSMCI1 */
diff --git a/nuttx/configs/sama5d3x-ek/src/sam_nsh.c b/nuttx/configs/sama5d3x-ek/src/sam_nsh.c
index 401ad482f..3ffe32788 100644
--- a/nuttx/configs/sama5d3x-ek/src/sam_nsh.c
+++ b/nuttx/configs/sama5d3x-ek/src/sam_nsh.c
@@ -61,9 +61,12 @@
****************************************************************************/
/* Configuration ************************************************************/
-/* Can't support the AT25 device if it SPI0 or AT25 support are not enabled */
#define HAVE_AT25 1
+#define HAVE_MMCSD 1
+
+/* Can't support the AT25 device if it SPI0 or AT25 support are not enabled */
+
#if !defined(CONFIG_SAMA5_SPI0) || !defined(CONFIG_MTD_AT25)
# undef HAVE_AT25
#endif
@@ -84,18 +87,50 @@
# undef HAVE_AT25
#endif
-#if defined(CONFIG_SAMA5_AT25_FTL) && defined(CONFIG_SAMA5_AT25_NXFFS)
-# warning Both CONFIG_SAMA5_AT25_FTL and CONFIG_SAMA5_AT25_NXFFS are set
-# warning Ignoring CONFIG_SAMA5_AT25_NXFFS
-# undef CONFIG_SAMA5_AT25_NXFFS
+/* Use minor device number 0 is not is provided */
+
+#ifndef CONFIG_NSH_MMCSDMINOR
+# define CONFIG_NSH_MMCSDMINOR 0
#endif
-/* Use minor device number 0 is not is provided */
+/* Can't support MMC/SD if the card interface(s) are not enable */
+
+#if !defined(CONFIG_SAMA5_HSMCI0) && !defined(CONFIG_SAMA5_HSMCI0)
+# undef HAVE_MMCSD
+#endif
+
+/* Can't support MMC/SD features if mountpoints are disabled */
+
+#if defined(CONFIG_DISABLE_MOUNTPOINT)
+# undef HAVE_MMCSD
+#endif
+
+/* Assign minor device numbers. We basically ignore more of the NSH
+ * configuration here (NSH SLOTNO ignored completely; NSH minor extended
+ * to handle more devices.
+ */
#ifndef CONFIG_NSH_MMCSDMINOR
# define CONFIG_NSH_MMCSDMINOR 0
#endif
+#ifdef HAVE_MMCSD
+
+# define HSMCI0_SLOTNO 0
+# define HSMCI1_SLOTNO 1
+
+# ifdef CONFIG_SAMA5_HSMCI0
+# define HSMCI0_MINOR CONFIG_NSH_MMCSDMINOR
+# define HSMCI1_MINOR (CONFIG_NSH_MMCSDMINOR+1)
+# define AT25_MINOR (CONFIG_NSH_MMCSDMINOR+2)
+# else
+# define HSMCI1_MINOR CONFIG_NSH_MMCSDMINOR
+# define AT25_MINOR (CONFIG_NSH_MMCSDMINOR+1)
+# endif
+#else
+# define AT25_MINOR CONFIG_NSH_MMCSDMINOR
+#endif
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -110,58 +145,39 @@
int nsh_archinitialize(void)
{
-#ifdef HAVE_AT25
- FAR struct spi_dev_s *spi;
- FAR struct mtd_dev_s *mtd;
+#if defined(HAVE_AT25) || defined(HAVE_MMCSD)
int ret;
+#endif
- /* Get the SPI port driver */
-
- spi = up_spiinitialize(AT25_PORT);
- if (!spi)
- {
- fdbg("ERROR: Failed to initialize SPI port %d\n", AT25_PORT);
- return -ENODEV;
- }
-
- /* Now bind the SPI interface to the AT25 SPI FLASH driver */
-
- mtd = at25_initialize(spi);
- if (!mtd)
- {
- fdbg("ERROR: Failed to bind SPI port %d to the AT25 FLASH driver\n");
- return -ENODEV;
- }
-
-#if defined(CONFIG_SAMA5_AT25_FTL)
- /* And finally, use the FTL layer to wrap the MTD driver as a block driver */
+ /* Initialize the AT25 driver */
- ret = ftl_initialize(CONFIG_NSH_MMCSDMINOR, mtd);
+#ifdef HAVE_AT25
+ ret = sam_at25_initialize(AT25_MINOR);
if (ret < 0)
{
- fdbg("ERROR: Initialize the FTL layer\n");
+ fdbg("ERROR: sam_at25_initialize failed: %d\n", ret);
return ret;
- }
-
-#elif defined(CONFIG_SAMA5_AT25_NXFFS)
- /* Initialize to provide NXFFS on the MTD interface */
+#endif
- ret = nxffs_initialize(mtd);
+#ifdef HAVE_MMCSD
+#ifdef CONFIG_SAMA5_HSMCI0
+ ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR);
if (ret < 0)
{
- fdbg("ERROR: NXFFS initialization failed: %d\n", -ret);
+ fdbg("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
+ HSMCI0_SLOTNO, HSMCI0_MINOR, ret);
return ret;
}
+#endif
- /* Mount the file system at /mnt/at25 */
-
- ret = mount(NULL, "/mnt/at25", "nxffs", 0, NULL);
+#ifdef CONFIG_SAMA5_HSMCI0
+ ret = sam_hsmci_initialize(HSMCI1_SLOTNO, HSMCI1_MINOR);
if (ret < 0)
{
- fdbg("ERROR: Failed to mount the NXFFS volume: %d\n", errno);
+ fdbg("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
+ HSMCI1_SLOTNO, HSMCI1_MINOR, ret);
return ret;
}
-
#endif
#endif
diff --git a/nuttx/configs/sama5d3x-ek/src/sama5d3x-ek.h b/nuttx/configs/sama5d3x-ek/src/sama5d3x-ek.h
index 8835bbaac..65793cb77 100644
--- a/nuttx/configs/sama5d3x-ek/src/sama5d3x-ek.h
+++ b/nuttx/configs/sama5d3x-ek/src/sama5d3x-ek.h
@@ -94,6 +94,49 @@
GPIO_INT_BOTHEDGES | GPIO_PORT_PIOE | GPIO_PIN27)
#define IRQ_USER1 SAM_IRQ_PE27
+/* HSMCI Card Slots *****************************************************************/
+/* The SAMA5D3x-EK provides a two SD memory card slots: (1) a full size SD card
+ * slot (J7 labeled MCI0), and (2) a microSD memory card slot (J6 labeled MCI1).
+ *
+ * The full size SD card slot connects via HSMCI0. The card detect discrete
+ * is available on PB17 (pulled high). The write protect descrete is tied to
+ * ground (via PP6) and not available to software. The slot supports 8-bit
+ * wide transfer mode, but the NuttX driver currently uses only the 4-bit
+ * wide transfer mode
+ *
+ * PD17 MCI0_CD
+ * PD1 MCI0_DA0
+ * PD2 MCI0_DA1
+ * PD3 MCI0_DA2
+ * PD4 MCI0_DA3
+ * PD5 MCI0_DA4
+ * PD6 MCI0_DA5
+ * PD7 MCI0_DA6
+ * PD8 MCI0_DA7
+ * PD9 MCI0_CK
+ * PD0 MCI0_CDA
+ */
+
+#define GPIO_MCI0_CD (GPIO_INPUT | GPIO_CFG_DEFAULT | GPIO_CFG_DEGLITCH | \
+ GPIO_INT_BOTHEDGES | GPIO_PORT_PIOD | GPIO_PIN17)
+#define IRQ_MCI0_CD SAM_IRQ_PD17
+
+/* The microSD connects vi HSMCI1. The card detect discrete is available on
+ * PB18 (pulled high):
+ *
+ * PD18 MCI1_CD
+ * PB20 MCI1_DA0
+ * PB21 MCI1_DA1
+ * PB22 MCI1_DA2
+ * PB23 MCI1_DA3
+ * PB24 MCI1_CK
+ * PB19 MCI1_CDA
+ */
+
+#define GPIO_MCI1_CD (GPIO_INPUT | GPIO_CFG_DEFAULT | GPIO_CFG_DEGLITCH | \
+ GPIO_INT_BOTHEDGES | GPIO_PORT_PIOD | GPIO_PIN18)
+#define IRQ_MCI1_CD SAM_IRQ_PD18
+
/* SPI Chip Selects *****************************************************************/
/* Both the Ronetix and Embest versions of the SAMAD3x CPU modules include an
* Atmel AT25DF321A, 32-megabit, 2.7-volt SPI serial flash. The SPI
@@ -178,6 +221,54 @@ void sam_sdram_config(void);
# define board_sdram_config(t)
#endif
+/****************************************************************************
+ * Name: sam_at25_initialize
+ *
+ * Description:
+ * Initialize and configure the AT25 SPI Flash
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_MTD_AT25
+int sam_at25_initialize(int minor);
+#endif
+
+/****************************************************************************
+ * Name: sam_hsmci_initialize
+ *
+ * Description:
+ * Initialize and configure one HSMCI slot
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_SAMA5_HSMCI0) || defined(CONFIG_SAMA5_HSMCI1)
+int sam_hsmci_initialize(int slotno, int minor);
+#endif
+
+/************************************************************************************
+ * Name: sam_cardinserted
+ *
+ * Description:
+ * Check if a card is inserted into the selected HSMCI slot
+ *
+ ************************************************************************************/
+
+#if defined(CONFIG_SAMA5_HSMCI0) || defined(CONFIG_SAMA5_HSMCI1)
+bool sam_cardinserted(int slotno);
+#endif
+
+/************************************************************************************
+ * Name: sam_writeprotected
+ *
+ * Description:
+ * Check if a card is inserted into the selected HSMCI slot
+ *
+ ************************************************************************************/
+
+#ifdef HAVE_MMCSD
+bool sam_writeprotected(int slotno);
+#endif
+
/************************************************************************************
* Name: up_ledinit
************************************************************************************/