mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
SAM4E-EK: Add support for the SAM4E-EK AT25 serial flash
This commit is contained in:
@@ -340,7 +340,7 @@ config SAM34_EIC
|
|||||||
depends on ARCH_CHIP_SAM4L || ARCH_CHIP_SAM4E
|
depends on ARCH_CHIP_SAM4L || ARCH_CHIP_SAM4E
|
||||||
|
|
||||||
config SAM34_DMAC
|
config SAM34_DMAC
|
||||||
bool "DMA controller"
|
bool "DMA controller (DMAC)"
|
||||||
default n
|
default n
|
||||||
depends on ARCH_CHIP_SAM3U || ARCH_CHIP_SAM3X || ARCH_CHIP_SAM3A || ARCH_CHIP_SAM4E
|
depends on ARCH_CHIP_SAM3U || ARCH_CHIP_SAM3X || ARCH_CHIP_SAM3A || ARCH_CHIP_SAM4E
|
||||||
select ARCH_DMA
|
select ARCH_DMA
|
||||||
@@ -875,7 +875,7 @@ endmenu # AT91SAM3/4 GPIO Interrupt Configuration
|
|||||||
|
|
||||||
if SAM34_SPI0 || SAM34_SPI1
|
if SAM34_SPI0 || SAM34_SPI1
|
||||||
|
|
||||||
menu "SPI device driver options"
|
menu "AT91SAM3/4 SPI device driver options"
|
||||||
|
|
||||||
config SAM34_SPI_DMA
|
config SAM34_SPI_DMA
|
||||||
bool "SPI DMA"
|
bool "SPI DMA"
|
||||||
@@ -911,7 +911,7 @@ config SAM34_SPI_REGDEBUG
|
|||||||
Output detailed register-level SPI device debug information.
|
Output detailed register-level SPI device debug information.
|
||||||
Requires also DEBUG.
|
Requires also DEBUG.
|
||||||
|
|
||||||
endmenu # SPI device driver options
|
endmenu # AT91SAM3/4 SPI device driver options
|
||||||
endif # SAM34_SPI0 || SAM34_SPI1
|
endif # SAM34_SPI0 || SAM34_SPI1
|
||||||
|
|
||||||
if SAM34_EMAC
|
if SAM34_EMAC
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ typedef void (*select_t)(enum spi_dev_e devid, bool selected);
|
|||||||
struct sam_spidev_s
|
struct sam_spidev_s
|
||||||
{
|
{
|
||||||
uint32_t base; /* SPI controller register base address */
|
uint32_t base; /* SPI controller register base address */
|
||||||
sem_t spisem; /* Assures mutually exclusive acess to SPI */
|
sem_t spisem; /* Assures mutually exclusive access to SPI */
|
||||||
select_t select; /* SPI select callout */
|
select_t select; /* SPI select callout */
|
||||||
bool initialized; /* TRUE: Controller has been initialized */
|
bool initialized; /* TRUE: Controller has been initialized */
|
||||||
#ifdef CONFIG_SAM34_SPI_DMA
|
#ifdef CONFIG_SAM34_SPI_DMA
|
||||||
|
|||||||
@@ -16,4 +16,35 @@ config SAM4EEK_120MHZ
|
|||||||
bool "120 MHz"
|
bool "120 MHz"
|
||||||
|
|
||||||
endchoice # CPU Frequency
|
endchoice # CPU Frequency
|
||||||
|
|
||||||
|
config SAM4EEK_AT25_AUTOMOUNT
|
||||||
|
bool "AT25 serial FLASH auto-mount"
|
||||||
|
default n
|
||||||
|
depends on NSH_ARCHINIT && SAM34_SPI0 && MTD_AT25
|
||||||
|
---help---
|
||||||
|
Automatically initialize the AT25 SPI FLASH driver when NSH starts.
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "AT25 serial FLASH configuration"
|
||||||
|
default SAM4EEK_AT25_FTL
|
||||||
|
depends on SAM4EEK_AT25_AUTOMOUNT
|
||||||
|
|
||||||
|
config SAM4EEK_AT25_FTL
|
||||||
|
bool "Create AT25 Serial FLASH block driver"
|
||||||
|
---help---
|
||||||
|
Create the MTD driver for the AT25 and "wrap" the AT25 as a standard
|
||||||
|
block driver that could then, for example, be mounted using FAT or
|
||||||
|
any other file system. Any file system may be used, but there will
|
||||||
|
be no wear-leveling.
|
||||||
|
|
||||||
|
config SAM4EEK_AT25_NXFFS
|
||||||
|
bool "Create AT25 serial FLASH NXFFS file system"
|
||||||
|
depends on FS_NXFFS
|
||||||
|
---help---
|
||||||
|
Create the MTD driver for the AT25 and mount the AT25 device as
|
||||||
|
a wear-leveling, NuttX FLASH file system (NXFFS). The downside of
|
||||||
|
NXFFS is that it can be very slow.
|
||||||
|
|
||||||
|
endchoice # AT25 serial FLASH configuration
|
||||||
|
|
||||||
endif # ARCH_BOARD_SAM4EEK
|
endif # ARCH_BOARD_SAM4EEK
|
||||||
|
|||||||
@@ -55,11 +55,14 @@ CSRCS += sam_nsh.c
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_SAM34_HSMCI),y)
|
ifeq ($(CONFIG_SAM34_HSMCI),y)
|
||||||
CSRCS += sam_mmcsd.c
|
CSRCS += sam_hsmci.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_SAM34_SPI0),y)
|
ifeq ($(CONFIG_SAM34_SPI0),y)
|
||||||
CSRCS += sam_spi.c
|
CSRCS += sam_spi.c
|
||||||
|
ifeq ($(CONFIG_MTD_AT25),y)
|
||||||
|
CSRCS += sam_at25.c
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_USBMSC),y)
|
ifeq ($(CONFIG_USBMSC),y)
|
||||||
|
|||||||
+142
-28
@@ -51,19 +51,77 @@
|
|||||||
#include "chip/sam_pinmap.h"
|
#include "chip/sam_pinmap.h"
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Definitions
|
* Pre-processor Definitions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
/* Configuration ********************************************************************/
|
||||||
|
|
||||||
/* External Memory Usage ************************************************************/
|
#define HAVE_HSMCI 1
|
||||||
/* LCD on CS2 */
|
#define HAVE_AT25 1
|
||||||
|
|
||||||
#define LCD_BASE SAM_EXTCS2_BASE
|
/* HSMCI */
|
||||||
|
/* Can't support MMC/SD if the card interface is not enabled */
|
||||||
|
|
||||||
|
#if !defined(CONFIG_SAM34_HSMCI)
|
||||||
|
# undef HAVE_HSMCI
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Can't support MMC/SD features if mountpoints are disabled */
|
||||||
|
|
||||||
|
#if defined(HAVE_HSMCI) && defined(CONFIG_DISABLE_MOUNTPOINT)
|
||||||
|
# warning Mountpoints disabled. No MMC/SD support
|
||||||
|
# undef HAVE_HSMCI
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* We need PIO interrupts on PIOA to support card detect interrupts */
|
||||||
|
|
||||||
|
#if defined(HAVE_HSMCI) && !defined(CONFIG_SAM34_PIOA_IRQ)
|
||||||
|
# warning PIOA interrupts not enabled. No MMC/SD support.
|
||||||
|
# undef HAVE_HSMCI
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* AT25 Serial FLASH */
|
||||||
|
/* Can't support the AT25 device if it SPI0 or AT25 support are not enabled */
|
||||||
|
|
||||||
|
#if !defined(CONFIG_SAM34_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_SAM4EEK_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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONFIG_FS_NXFFS
|
||||||
|
# undef CONFIG_SAM4EEK_AT25_NXFFS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CONFIG_SAM4EEK_AT25_FTL) && !defined(CONFIG_SAM4EEK_AT25_NXFFS)
|
||||||
|
# undef HAVE_AT25
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_SAM4EEK_AT25_FTL) && defined(CONFIG_SAM4EEK_AT25_NXFFS)
|
||||||
|
# warning Both CONFIG_SAM4EEK_AT25_FTL and CONFIG_SAM4EEK_AT25_NXFFS are set
|
||||||
|
# warning Ignoring CONFIG_SAM4EEK_AT25_NXFFS
|
||||||
|
# undef CONFIG_SAM4EEK_AT25_NXFFS
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Touchscreen controller (TSC) */
|
/* Touchscreen controller (TSC) */
|
||||||
|
|
||||||
#define CONFIG_TSC_ADS7843 1 /* ADS7843 present on board */
|
#define CONFIG_TSC_ADS7843 1 /* ADS7843 present on board */
|
||||||
#define CONFIG_TSC_SPI 0 /* On SPI0 */
|
#define CONFIG_TSC_SPI 0 /* On SPI0 */
|
||||||
|
|
||||||
|
/* External Memory Usage ************************************************************/
|
||||||
|
/* LCD on CS2 */
|
||||||
|
|
||||||
|
#define LCD_BASE SAM_EXTCS2_BASE
|
||||||
|
|
||||||
/* SAM4E-EK GPIO Pin Definitions ****************************************************/
|
/* SAM4E-EK GPIO Pin Definitions ****************************************************/
|
||||||
|
|
||||||
/* LCD:
|
/* LCD:
|
||||||
@@ -167,7 +225,7 @@
|
|||||||
* ------ -------
|
* ------ -------
|
||||||
* GPIO PIN
|
* GPIO PIN
|
||||||
* ------ -------
|
* ------ -------
|
||||||
* PA11 /CS
|
* PA11 /CS (pulled high)
|
||||||
* PA12 DOUT
|
* PA12 DOUT
|
||||||
* PA13 DIN
|
* PA13 DIN
|
||||||
* PA14 DCLK
|
* PA14 DCLK
|
||||||
@@ -253,13 +311,36 @@
|
|||||||
#define GPIO_RS485_ENABLE (GPIO_OUTPUT | GPIO_CFG_DEFAULT | \
|
#define GPIO_RS485_ENABLE (GPIO_OUTPUT | GPIO_CFG_DEFAULT | \
|
||||||
GPIO_OUTPUT_SET | GPIO_PORT_PIOA | GPIO_PIN21)
|
GPIO_OUTPUT_SET | GPIO_PORT_PIOA | GPIO_PIN21)
|
||||||
|
|
||||||
/* SD Card Detect */
|
/* HSMCI SD Card Detect
|
||||||
|
*
|
||||||
|
* PA26 DAT2
|
||||||
|
* PA27 DAT3
|
||||||
|
* PA28 CMD
|
||||||
|
* PA29 CLK
|
||||||
|
* PA30 DAT0
|
||||||
|
* PA31 DAT1
|
||||||
|
* PA6 CD Pulled high
|
||||||
|
*/
|
||||||
|
|
||||||
#define GPIO_MCI_CD (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_PORT_PIOA | GPIO_PIN25)
|
#define GPIO_MCI_CD (GPIO_INPUT | GPIO_CFG_PULLUP | GPIO_PORT_PIOA | GPIO_PIN6)
|
||||||
|
#define MCI_CD_IRQ SAM_IRQ_PA6
|
||||||
|
|
||||||
/* SPI Chip Selects */
|
/* SPI Chip Selects */
|
||||||
|
|
||||||
/* Chip select pin connected to the touchscreen controller and to the ZigBee module
|
/* Touchscreen Controller:
|
||||||
|
*
|
||||||
|
* ------ -------
|
||||||
|
* GPIO PIN
|
||||||
|
* ------ -------
|
||||||
|
* PA11 /CS (pulled high externally)
|
||||||
|
* PA12 DOUT
|
||||||
|
* PA13 DIN
|
||||||
|
* PA14 DCLK
|
||||||
|
* PA16 /PENIRQ
|
||||||
|
* PA17 BUSY
|
||||||
|
* ------ -------
|
||||||
|
*
|
||||||
|
* Chip select pin connected to the touchscreen controller and to the ZigBee module
|
||||||
* connector. Notice that the touchscreen chip select is implemented as a GPIO
|
* connector. Notice that the touchscreen chip select is implemented as a GPIO
|
||||||
* OUTPUT that must be controlled by board-specific. This is because the ADS7843E
|
* OUTPUT that must be controlled by board-specific. This is because the ADS7843E
|
||||||
* driver must be able to sample the device BUSY GPIO input between SPI transfers.
|
* driver must be able to sample the device BUSY GPIO input between SPI transfers.
|
||||||
@@ -268,10 +349,26 @@
|
|||||||
* it low throughout the SPI transfer.
|
* it low throughout the SPI transfer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define GPIO_TSC_CS (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \
|
#define GPIO_TSC_CS (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_SET | \
|
||||||
GPIO_PORT_PIOA | GPIO_PIN11)
|
GPIO_PORT_PIOA | GPIO_PIN11)
|
||||||
#define TSC_CSNUM 0
|
#define TSC_CSNUM 0
|
||||||
|
|
||||||
|
/* Serial FLASH (AT25DF321A)
|
||||||
|
*
|
||||||
|
* ------ ------- ---------------
|
||||||
|
* GPIO PIN SAM4E FUNCTION
|
||||||
|
* ------ ------- ---------------
|
||||||
|
* PA13 SI MOSI
|
||||||
|
* PA12 SO MIS0
|
||||||
|
* PA14 SCK SPCK
|
||||||
|
* PA5 /CS NPCS3 (pulled high externally)
|
||||||
|
* ------ ------- ---------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define GPIO_FLASH_CS (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_SET | \
|
||||||
|
GPIO_PORT_PIOA | GPIO_PIN5)
|
||||||
|
#define FLASH_CSNUM 3
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@@ -307,25 +404,17 @@ void weak_function sam_spiinitialize(void);
|
|||||||
void weak_function sam_usbinitialize(void);
|
void weak_function sam_usbinitialize(void);
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Name: sam_hsmciinit
|
* Name: sam_hsmci_initialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize HSMCI support
|
* Initialize HSMCI support
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_SAM34_HSMCI
|
#ifdef HAVE_HSMCI
|
||||||
int weak_function sam_hsmciinit(void);
|
int weak_function sam_hsmci_initialize(void);
|
||||||
#else
|
#else
|
||||||
# define sam_hsmciinit()
|
# define sam_hsmci_initialize()
|
||||||
#endif
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
* Name: board_led_initialize
|
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_LEDS
|
|
||||||
void board_led_initialize(void);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
@@ -336,24 +425,49 @@ void board_led_initialize(void);
|
|||||||
*
|
*
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_SAM34_HSMCI
|
#ifdef HAVE_HSMCI
|
||||||
bool sam_cardinserted(unsigned char slot);
|
bool sam_cardinserted(int slotno);
|
||||||
#else
|
#else
|
||||||
# define sam_cardinserted(slot) (false)
|
# define sam_cardinserted(slotno) (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Name: sam_writeprotected
|
* Name: sam_writeprotected
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Check if a card is inserted into the selected HSMCI slot
|
* Check if the card in the MMCSD slot is write protected
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_SAM34_HSMCI
|
#ifdef HAVE_HSMCI
|
||||||
bool sam_writeprotected(unsigned char slot);
|
bool sam_writeprotected(int slotno);
|
||||||
#else
|
#else
|
||||||
# define sam_writeprotected(slot) (false)
|
# define sam_writeprotected(slotno) (false)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sam_at25_automount
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize, configure, and mount the AT25 serial FLASH. The FLASH will
|
||||||
|
* be mounted at /dev/at25.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_AT25
|
||||||
|
int sam_at25_automount(int minor);
|
||||||
|
#else
|
||||||
|
# define sam_at25_automount(minor) (-ENOSYS)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: board_led_initialize
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_ARCH_LEDS
|
||||||
|
void board_led_initialize(void);
|
||||||
|
#else
|
||||||
|
# define board_led_initialize()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* config/sam4e-ek/src/sam_at25.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014 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>
|
||||||
|
|
||||||
|
#include <nuttx/spi/spi.h>
|
||||||
|
#include <nuttx/mtd/mtd.h>
|
||||||
|
#include <nuttx/fs/nxffs.h>
|
||||||
|
|
||||||
|
#include "sam_spi.h"
|
||||||
|
#include "sam4e-ek.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_AT25
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-Processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sam_at25_automount
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize, configure, and mount the AT25 serial FLASH. The FLASH will
|
||||||
|
* be mounted at /dev/at25.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int sam_at25_automount(int minor)
|
||||||
|
{
|
||||||
|
FAR struct spi_dev_s *spi;
|
||||||
|
FAR struct mtd_dev_s *mtd;
|
||||||
|
static bool initialized = false;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Have we already initialized? */
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
/* No.. Get the SPI port driver */
|
||||||
|
|
||||||
|
spi = up_spiinitialize(FLASH_CSNUM);
|
||||||
|
if (!spi)
|
||||||
|
{
|
||||||
|
fdbg("ERROR: Failed to initialize SPI port %d\n", FLASH_CSNUM);
|
||||||
|
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_SAM4EEK_AT25_FTL)
|
||||||
|
/* And finally, use the FTL layer to wrap the MTD driver as a block
|
||||||
|
* driver at /dev/mtdblockN, where N=minor device number.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret = ftl_initialize(minor, mtd);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fdbg("ERROR: Failed to initialize the FTL layer: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(CONFIG_SAM4EEK_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
|
||||||
|
/* Now we are initialized */
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_AT25 */
|
||||||
@@ -115,7 +115,7 @@ void sam_boardinitialize(void)
|
|||||||
* into the build.
|
* into the build.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(CONFIG_USBDEV) && defined(CONFIG_SAM34_USB)
|
#if defined(CONFIG_USBDEV) && defined(CONFIG_SAM34_UDP)
|
||||||
if (sam_usbinitialize)
|
if (sam_usbinitialize)
|
||||||
{
|
{
|
||||||
sam_usbinitialize();
|
sam_usbinitialize();
|
||||||
@@ -127,15 +127,31 @@ void sam_boardinitialize(void)
|
|||||||
#ifdef CONFIG_ARCH_LEDS
|
#ifdef CONFIG_ARCH_LEDS
|
||||||
board_led_initialize();
|
board_led_initialize();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* Setup SD card-related PIOs if 1) HSMCI is selected and 2) the weak
|
/****************************************************************************
|
||||||
* function sam_hsmciinit() has been brought into the build.
|
* Name: board_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* If CONFIG_BOARD_INITIALIZE is selected, then an additional
|
||||||
|
* initialization call will be performed in the boot-up sequence to a
|
||||||
|
* function called board_initialize(). board_initialize() will be
|
||||||
|
* called immediately after up_intiialize() is called and just before the
|
||||||
|
* initial application is started. This additional initialization phase
|
||||||
|
* may be used, for example, to initialize board-specific device drivers.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_BOARD_INITIALIZE
|
||||||
|
void board_initialize(void)
|
||||||
|
{
|
||||||
|
/* Perform NSH initialization here instead of from the NSH. This
|
||||||
|
* alternative NSH initialization is necessary when NSH is ran in user-space
|
||||||
|
* but the initialization function must run in kernel space.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_SAM34_HSMCI
|
#if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_NSH_ARCHINIT)
|
||||||
if (sam_hsmciinit)
|
(void)nsh_archinitialize();
|
||||||
{
|
|
||||||
sam_hsmciinit();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_BOARD_INITIALIZE */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* configs/sam4e-ek/src/sam_mmcsd.c
|
* config/sam4e-ek/src/sam_hsmci.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -31,119 +31,176 @@
|
|||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/sdio.h>
|
||||||
|
#include <nuttx/mmcsd.h>
|
||||||
|
|
||||||
#include "sam_gpio.h"
|
#include "sam_gpio.h"
|
||||||
|
#include "sam_hsmci.h"
|
||||||
|
|
||||||
#include "sam4e-ek.h"
|
#include "sam4e-ek.h"
|
||||||
|
|
||||||
#ifdef CONFIG_SAM34_HSMCI
|
#ifdef HAVE_HSMCI
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* 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,
|
* Private Types
|
||||||
* this function must call sio_mediachange() to handle that event. See
|
****************************************************************************/
|
||||||
* arch/arm/src/sam34/sam_hsmci.h for more information.
|
/* This structure holds static information unique to one HSMCI peripheral */
|
||||||
*
|
|
||||||
* Also see the SAMA5D3x-EK implementation of this same logic. The card detect
|
|
||||||
* interrupt handling should be a drop-in.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef GPIO_MCI_CD
|
struct sam_hsmci_state_s
|
||||||
# warning "Card detect interrupt handling needed"
|
{
|
||||||
#endif
|
struct sdio_dev_s *hsmci; /* R/W device handle */
|
||||||
|
bool inserted; /* TRUE: card is inserted */
|
||||||
|
};
|
||||||
|
|
||||||
/* Usually defined in NuttX header files */
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef OK
|
/* HSCMI device state */
|
||||||
# define OK 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/************************************************************************************
|
static struct sam_hsmci_state_s g_hsmci;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Name: sam_hsmci_cardetect
|
||||||
************************************************************************************/
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
* Name: sam_hsmciinit
|
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize HSMCI support. This function is called very early in board
|
* Card detect interrupt handler
|
||||||
* initialization.
|
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int sam_hsmciinit(void)
|
static int sam_hsmci_cardetect(int irq, void *regs)
|
||||||
{
|
{
|
||||||
#ifdef GPIO_MCI_CD
|
bool inserted;
|
||||||
sam_configgpio(GPIO_MCI_CD);
|
|
||||||
#endif
|
/* Get the state of the GPIO pin */
|
||||||
#ifdef GPIO_MCI_WP
|
|
||||||
sam_configgpio(GPIO_MCI_WP);
|
inserted = sam_cardinserted(0);
|
||||||
#endif
|
|
||||||
|
/* Has the card detect state changed? */
|
||||||
|
|
||||||
|
if (inserted == g_hsmci.inserted)
|
||||||
|
{
|
||||||
|
/* Yes... remember that new state and inform the HSMCI driver */
|
||||||
|
|
||||||
|
g_hsmci.inserted = inserted;
|
||||||
|
|
||||||
|
/* Report the new state to the SDIO driver */
|
||||||
|
|
||||||
|
sdio_mediachange(g_hsmci.hsmci, inserted);
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sam_hsmci_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Perform architecture specific initialization
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int sam_hsmci_initialize(int minor)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Initialize card-detect GPIO. There is no write-protection GPIO. */
|
||||||
|
|
||||||
|
sam_configpio(GPIO_MCI_CD);
|
||||||
|
|
||||||
|
/* Mount the SDIO-based MMC/SD block driver */
|
||||||
|
/* First, get an instance of the SDIO interface */
|
||||||
|
|
||||||
|
g_hsmci.hsmci = sdio_initialize(0);
|
||||||
|
if (!g_hsmci.hsmci)
|
||||||
|
{
|
||||||
|
fdbg("Failed to initialize SDIO\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now bind the SDIO interface to the MMC/SD driver */
|
||||||
|
|
||||||
|
ret = mmcsd_slotinitialize(minor, g_hsmci.hsmci);
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
fdbg("Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Configure card detect interrupts */
|
||||||
|
|
||||||
|
sam_pioirq(GPIO_MCI_CD);
|
||||||
|
(void)irq_attach(MCI_CD_IRQ, sam_hsmci_cardetect);
|
||||||
|
|
||||||
|
/* Then inform the HSMCI driver if there is or is not a card in the slot. */
|
||||||
|
|
||||||
|
g_hsmci.inserted = sam_cardinserted(0);
|
||||||
|
sdio_mediachange(g_hsmci.hsmci, g_hsmci.inserted);
|
||||||
|
|
||||||
|
/* Enable card detect interrupts */
|
||||||
|
|
||||||
|
sam_pioirqenable(MCI_CD_IRQ);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
* Name: sam_cardinserted
|
* Name: sam_cardinserted
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Check if a card is inserted into the selected HSMCI slot
|
* Check if a card is inserted into the selected HSMCI slot
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
bool sam_cardinserted(unsigned char slot)
|
bool sam_cardinserted(int slotno)
|
||||||
{
|
{
|
||||||
if (slot == 0)
|
bool removed;
|
||||||
{
|
|
||||||
#ifdef GPIO_MCI_CD
|
/* Get the state of the GPIO pin */
|
||||||
bool inserted = sam_gpioread(GPIO_MCI_CD);
|
|
||||||
fvdbg("inserted: %s\n", inserted ? "NO" : "YES");
|
removed = sam_pioread(GPIO_MCI_CD);
|
||||||
return !inserted;
|
fllvdbg("Slot %d inserted: %s\n", slotno, removed ? "NO" : "YES");
|
||||||
#else
|
|
||||||
return true;
|
return !removed;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
/****************************************************************************
|
||||||
}
|
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
* Name: sam_writeprotected
|
* Name: sam_writeprotected
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Check if a card is inserted into the selected HSMCI slot
|
* Check if a card is inserted into the selected HSMCI slot
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
bool sam_writeprotected(unsigned char slot)
|
bool sam_writeprotected(int slotno)
|
||||||
{
|
{
|
||||||
if (slot == 0)
|
/* There are no write protect pins */
|
||||||
{
|
|
||||||
#ifdef GPIO_MCI_WP
|
|
||||||
bool protected = sam_gpioread(GPIO_MCI_WP);
|
|
||||||
fvdbg("protected: %s\n", inserted ? "YES" : "NO");
|
|
||||||
return protected;
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_SAM34_HSMCI */
|
#endif /* HAVE_HSMCI */
|
||||||
@@ -39,63 +39,23 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/mount.h>
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <debug.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/sdio.h>
|
#ifdef CONFIG_SYSTEM_USBMONITOR
|
||||||
#include <nuttx/mmcsd.h>
|
# include <apps/usbmonitor.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sam_hsmci.h"
|
|
||||||
#include "sam4e-ek.h"
|
#include "sam4e-ek.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-Processor Definitions
|
* Pre-Processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Configuration ************************************************************/
|
|
||||||
|
|
||||||
/* PORT and SLOT number probably depend on the board configuration */
|
|
||||||
|
|
||||||
#define NSH_HAVE_USBDEV 1
|
|
||||||
#define NSH_HAVE_MMCSD 1
|
|
||||||
|
|
||||||
/* Can't support MMC/SD if the card interface is not enable */
|
|
||||||
|
|
||||||
#ifndef CONFIG_SAM34_HSMCI
|
|
||||||
# undef NSH_HAVE_MMCSD
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Can't support MMC/SD features if mountpoints are disabled or if SDIO support
|
|
||||||
* is not enabled.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_SAM34_HSMCI)
|
|
||||||
# undef NSH_HAVE_MMCSD
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef NSH_HAVE_MMCSD
|
|
||||||
# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0
|
|
||||||
# error "Only one MMC/SD slot"
|
|
||||||
# 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
|
|
||||||
|
|
||||||
/* Can't support USB features if USB is not enabled */
|
|
||||||
|
|
||||||
#ifndef CONFIG_USBDEV
|
|
||||||
# undef NSH_HAVE_USBDEV
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Debug ********************************************************************/
|
/* Debug ********************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||||
@@ -126,41 +86,40 @@
|
|||||||
|
|
||||||
int nsh_archinitialize(void)
|
int nsh_archinitialize(void)
|
||||||
{
|
{
|
||||||
#ifdef NSH_HAVE_MMCSD
|
#if defined(HAVE_AT25) || defined(HAVE_HSMCI) || defined(HAVE_USBMONITOR)
|
||||||
FAR struct sdio_dev_s *sdio;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Mount the SDIO-based MMC/SD block driver */
|
#ifdef HAVE_AT25
|
||||||
/* First, get an instance of the SDIO interface */
|
/* Initialize the AT25 driver */
|
||||||
|
|
||||||
message("nsh_archinitialize: Initializing SDIO slot %d\n",
|
ret = sam_at25_automount(0);
|
||||||
CONFIG_NSH_MMCSDSLOTNO);
|
if (ret < 0)
|
||||||
|
|
||||||
sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
|
|
||||||
if (!sdio)
|
|
||||||
{
|
{
|
||||||
message("nsh_archinitialize: Failed to initialize SDIO slot %d\n",
|
message("ERROR: sam_at25_automount() failed: %d\n", ret);
|
||||||
CONFIG_NSH_MMCSDSLOTNO);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now bind the SDIO interface to the MMC/SD driver */
|
|
||||||
|
|
||||||
message("nsh_archinitialize: Bind SDIO to the MMC/SD driver, minor=%d\n",
|
|
||||||
CONFIG_NSH_MMCSDMINOR);
|
|
||||||
|
|
||||||
ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio);
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
message("nsh_archinitialize: Successfully bound SDIO to the MMC/SD driver\n");
|
#ifdef HAVE_HSMCI
|
||||||
|
/* Initialize the HSMCI driver */
|
||||||
|
|
||||||
/* Then inform the HSMCI driver if there is or is not a card in the slot. */
|
ret = sam_hsmci_initialize(0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
message("ERROR: sam_hsmci_initialize(0) failed: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
sdio_mediachange(sdio, sam_cardinserted(0));
|
#ifdef HAVE_USBMONITOR
|
||||||
|
/* Start the USB Monitor */
|
||||||
|
|
||||||
|
ret = usbmonitor_start(0, NULL);
|
||||||
|
if (ret != OK)
|
||||||
|
{
|
||||||
|
message("nsh_archinitialize: Start USB monitor: %d\n", ret);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
|||||||
@@ -95,15 +95,17 @@
|
|||||||
|
|
||||||
void weak_function sam_spiinitialize(void)
|
void weak_function sam_spiinitialize(void)
|
||||||
{
|
{
|
||||||
/* The ZigBee module connects used NPCS0. However, there is not yet any
|
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E)
|
||||||
* ZigBee support.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The touchscreen connects using NPCS0 (PA11). */
|
/* The touchscreen connects using NPCS0 (PA11). */
|
||||||
|
|
||||||
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E)
|
|
||||||
sam_configgpio(GPIO_TSC_CS);
|
sam_configgpio(GPIO_TSC_CS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_MTD_AT25)
|
||||||
|
/* The AT25 Serial FLASH connects using NPCS3 (PA5). */
|
||||||
|
|
||||||
|
sam_configgpio(GPIO_FLASH_CS);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -166,6 +168,9 @@ void weak_function sam_spiinitialize(void)
|
|||||||
|
|
||||||
void sam_spi0select(enum spi_dev_e devid, bool selected)
|
void sam_spi0select(enum spi_dev_e devid, bool selected)
|
||||||
{
|
{
|
||||||
|
switch (devid)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E)
|
||||||
/* The touchscreen chip select is implemented as a GPIO OUTPUT that must
|
/* The touchscreen chip select is implemented as a GPIO OUTPUT that must
|
||||||
* be controlled by this function. This is because the ADS7843E driver
|
* be controlled by this function. This is because the ADS7843E driver
|
||||||
* must be able to sample the device BUSY GPIO input between SPI transfers.
|
* must be able to sample the device BUSY GPIO input between SPI transfers.
|
||||||
@@ -174,12 +179,22 @@ void sam_spi0select(enum spi_dev_e devid, bool selected)
|
|||||||
* manually and hold it low throughout the SPI transfer.
|
* manually and hold it low throughout the SPI transfer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_ADS7843E)
|
case SPIDEV_TOUCHSCREEN:
|
||||||
if (devid == SPIDEV_TOUCHSCREEN)
|
|
||||||
{
|
|
||||||
sam_gpiowrite(GPIO_TSC_CS, !selected);
|
sam_gpiowrite(GPIO_TSC_CS, !selected);
|
||||||
}
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_MTD_AT25)
|
||||||
|
/* The AT25 Serial FLASH connects using NPCS3 (PA5). */
|
||||||
|
|
||||||
|
case SPIDEV_FLASH:
|
||||||
|
sam_gpiowrite(GPIO_FLASH_CS, !selected);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -238,7 +238,7 @@
|
|||||||
# define AT24_MINOR _AT24_MINOR
|
# define AT24_MINOR _AT24_MINOR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* MMC/SD minor numbers: The NSH device minor extended is extened to support
|
/* MMC/SD minor numbers: The NSH device minor extended is extended to support
|
||||||
* two devices. If CONFIG_NSH_MMCSDMINOR is zero, these will be: /dev/mmcsd0
|
* two devices. If CONFIG_NSH_MMCSDMINOR is zero, these will be: /dev/mmcsd0
|
||||||
* and /dev/mmcsd1.
|
* and /dev/mmcsd1.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+12
-6
@@ -100,9 +100,15 @@
|
|||||||
|
|
||||||
/* Status register bit definitions */
|
/* Status register bit definitions */
|
||||||
|
|
||||||
#define AT25_SR_WIP (1 << 0) /* Bit 0: Write in progress bit */
|
#define AT25_SR_BUSY (1 << 0) /* Bit 0: Ready/Busy Status */
|
||||||
#define AT25_SR_WEL (1 << 1) /* Bit 1: Write enable latch bit */
|
#define AT25_SR_WEL (1 << 1) /* Bit 1: Write enable latch bit */
|
||||||
|
#define AT25_SR_SWP_SHIFT (2) /* Bits 2-3: Software protection */
|
||||||
|
#define AT25_SR_SWP_MASK (3 << AT25_SR_SWP_SHIFT)
|
||||||
|
#define AT25_SR_WPP (1 << 4) /* Bit 4: Write Protect (/WP) Pin Status */
|
||||||
#define AT25_SR_EPE (1 << 5) /* Bit 5: Erase/program error */
|
#define AT25_SR_EPE (1 << 5) /* Bit 5: Erase/program error */
|
||||||
|
/* Bit 6: Reserved */
|
||||||
|
#define AT25_SR_SPRL (1 << 7) /* Bit 7: Sector Protection Registers Locked */
|
||||||
|
|
||||||
#define AT25_SR_UNPROT 0x00 /* Global unprotect command */
|
#define AT25_SR_UNPROT 0x00 /* Global unprotect command */
|
||||||
|
|
||||||
#define AT25_DUMMY 0xa5
|
#define AT25_DUMMY 0xa5
|
||||||
@@ -269,7 +275,7 @@ static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
|||||||
|
|
||||||
status = SPI_SEND(priv->dev, AT25_DUMMY);
|
status = SPI_SEND(priv->dev, AT25_DUMMY);
|
||||||
}
|
}
|
||||||
while ((status & AT25_SR_WIP) != 0);
|
while ((status & AT25_SR_BUSY) != 0);
|
||||||
|
|
||||||
/* Deselect the FLASH */
|
/* Deselect the FLASH */
|
||||||
|
|
||||||
@@ -302,19 +308,19 @@ static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
|||||||
* other peripherals to access the SPI bus.
|
* other peripherals to access the SPI bus.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((status & AT25_SR_WIP) != 0)
|
if ((status & AT25_SR_BUSY) != 0)
|
||||||
{
|
{
|
||||||
at25_unlock(priv->dev);
|
at25_unlock(priv->dev);
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
at25_lock(priv->dev);
|
at25_lock(priv->dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ((status & AT25_SR_WIP) != 0);
|
while ((status & AT25_SR_BUSY) != 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (status & AT25_SR_EPE)
|
if (status & AT25_SR_EPE)
|
||||||
{
|
{
|
||||||
fdbg("Write error, status: 0x%02x\n", status);
|
fdbg("ERROR: Write error, status: 0x%02x\n", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
fvdbg("Complete, status: 0x%02x\n", status);
|
fvdbg("Complete, status: 0x%02x\n", status);
|
||||||
@@ -693,7 +699,7 @@ FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev)
|
|||||||
{
|
{
|
||||||
/* Unrecognized! Discard all of that work we just did and return NULL */
|
/* Unrecognized! Discard all of that work we just did and return NULL */
|
||||||
|
|
||||||
fdbg("Unrecognized\n");
|
fdbg("ERROR: Unrecognized\n");
|
||||||
kfree(priv);
|
kfree(priv);
|
||||||
priv = NULL;
|
priv = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user