SAMA5: Add logic to auto-mount a file system on AT25 SPI FLASH for NSH

This commit is contained in:
Gregory Nutt 2013-08-05 08:24:39 -06:00
parent 906506c61c
commit cbe8c5ed56
11 changed files with 317 additions and 75 deletions

View File

@ -5286,4 +5286,8 @@
and a register access debug option (2013-8-4).
* configs/sama5d3x-ek/src/sam_spi.c: At board support for the
AT25 serial flash (2013-8-4).
* configs/sama5d3x-ek/nsh/defconfig: FAT file system support is
now enabled by default (2013-8-5)
* confgis/sama5d3x-ek/src/sam_nsh.c: Automatically mount AT25
file system for NSH if so configured (2013-8-5).

View File

@ -411,7 +411,7 @@ static inline void spi_putreg(struct sam_spidev_s *spi, uint32_t value,
****************************************************************************/
#if defined(CONFIG_DEBUG_SPI) && defined(CONFIG_DEBUG_VERBOSE)
static void spi_dumpregs(const struct sam_spidev_s *spi, const char *msg)
static void spi_dumpregs(struct sam_spidev_s *spi, const char *msg)
{
spivdbg("%s:\n", msg);
spivdbg(" MR:%08x SR:%08x IMR:%08x\n",

View File

@ -42,4 +42,33 @@ config SAMA5_NOR_START
option: If SAMA5_NOR_START is defined, then it will not wait but
will, instead, immediately start the program in NOR FLASH.
config SAMA5_AT25_AUTOMOUNT
bool "AT25 auto-mount"
default n
depends on NSH_ARCHINIT && SAMA5_SPI0 && MTD_AT25
---help---
Automatically initialize the AT25 SPI FLASH driver when NSH starts.
choice
prompt "AT25 configuration"
default SAMA5_AT25_FTL
depends on SAMA5_AT25_AUTOMOUNT
config SAMA5_AT25_FTL
bool "Create AT25 block driver"
---help---
Create the MTD driver for the AT25 and "wrap" the AT25 is 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 SAMA5_AT25_NXFFS
bool "Create AT25 NXFFS file system"
depends on FS_NXFFS
---help---
Create the MTD driver for the AT25 and 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
endif

View File

@ -857,7 +857,11 @@ Configurations
4. This configuration has support for NSH built-in applications enabled.
However, no built-in applications are selected in the base configuration.
5. SDRAM support can be enabled by adding the following to your NuttX
5. This configuration has support for the FAT file system built in. However,
by default, there are no block drivers intialized. The FAT file system can
still be used to create RAM disks.
6. SDRAM support can be enabled by adding the following to your NuttX
configuration file:
System Type->ATSAMA5 Peripheral Support
@ -881,7 +885,7 @@ Configurations
Another thing you could do is to enable the RAM test built-in
application:
6. You can enable the NuttX RAM test that may be used to verify the
7. You can enable the NuttX RAM test that may be used to verify the
external SDAM. To do this, keep the SDRAM out of the heap so that
it can be tested without crashing programs using the memory:
@ -921,15 +925,7 @@ Configurations
RAMTest: Pattern test: 20000000 268435456 33333333 cccccccc
RAMTest: Address-in-address test: 20000000 268435456
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
PLL settings to get that speed.
If the CPU speed changes, then so must the NOR and SDRAM
initialization!
7. The Embest or Ronetix CPU module includes an Atmel AT25DF321A,
8. The Embest or Ronetix CPU module includes an Atmel AT25DF321A,
32-megabit, 2.7-volt SPI serial flash. Support for that serial
FLASH can be enabled by modifying the NuttX configuration as
follows:
@ -947,6 +943,24 @@ Configurations
CONFIG_AT25_SPIMODE=0 : Use SPI mode 0
CONFIG_AT25_SPIFREQUENCY=20000000 : Use SPI frequency 20MHz
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : NSH board-initialization
Board Selection
CONFIG_SAMA5_AT25_AUTOMOUNT=y : Mounts AT25 for NSH
CONFIG_SAMA5_AT25_FTL=y : Create block driver for FAT
NOTE that you must close JP1 on the Embest/Ronetix board in
order to enable the AT25 FLASH chip select.
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
PLL settings to get that speed.
If the CPU speed changes, then so must the NOR and SDRAM
initialization!
2013-7-31: I have been unable to execute this configuration from NOR
FLASH by closing the BMS jumper (J9). As far as I can tell, this
jumper does nothing on my board??? I have been using the norboot

View File

@ -164,6 +164,10 @@ CONFIG_SAMA5_USART1=y
# CONFIG_SAMA5_MPDDRC is not set
# CONFIG_PIO_IRQ is not set
#
# SPI device driver options
#
#
# External Memory Configuration
#
@ -392,8 +396,17 @@ CONFIG_USART1_2STOP=0
#
# File system configuration
#
CONFIG_DISABLE_MOUNTPOINT=y
# CONFIG_DISABLE_MOUNTPOINT is not set
# CONFIG_FS_RAMMAP is not set
CONFIG_FS_FAT=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FAT_MAXFNAME=32
# CONFIG_FS_FATTIME is not set
# CONFIG_FAT_DMAMEMORY is not set
# CONFIG_FS_NXFFS is not set
# CONFIG_FS_ROMFS is not set
# CONFIG_FS_SMARTFS is not set
# CONFIG_FS_BINFS is not set
#

View File

@ -66,6 +66,10 @@ ifeq ($(CONFIG_SAMA5_NOR_MAIN),y)
CSRCS += nor_main.c
endif
ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += sam_nsh.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else

View File

@ -0,0 +1,169 @@
/****************************************************************************
* config/sama5d3x-ek/src/sam_nsh.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
/* Use minor device number 0 is not is provided */
#ifndef CONFIG_NSH_MMCSDMINOR
# define CONFIG_NSH_MMCSDMINOR 0
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_archinitialize
*
* Description:
* Perform architecture specific initialization
*
****************************************************************************/
int nsh_archinitialize(void)
{
#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;
}

View File

@ -114,7 +114,7 @@
#define GPIO_AT25_NPCS0 (GPIO_OUTPUT | GPIO_CFG_PULLUP | GPIO_OUTPUT_SET | \
GPIO_PORT_PIOD | GPIO_PIN13)
#define AT25_CSNUM 0
#define AT25_PORT SPI0_CS0
/************************************************************************************
* Public Types

View File

@ -101,14 +101,6 @@ config AT25_SPIFREQUENCY
int "AT25 SPI Frequency"
default 20000000
config AT25_READONLY
bool "AT25 Read-Only FLASH"
default n
config AT25_SECTOR512
bool "Simulate 512 byte Erase Blocks"
default n
endif
config MTD_AT45DB

View File

@ -57,11 +57,16 @@
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/
/* Configuration ********************************************************************/
#ifndef CONFIG_AT25_SPIMODE
# define CONFIG_AT25_SPIMODE SPIDEV_MODE0
#endif
#ifndef CONFIG_AT25_SPIFREQUENCY
# define CONFIG_AT25_SPIFREQUENCY 20000000
#endif
/* AT25 Registers *******************************************************************/
/* Indentification register values */
@ -180,7 +185,7 @@ static void at25_lock(FAR struct spi_dev_s *dev)
SPI_SETMODE(dev, CONFIG_AT25_SPIMODE);
SPI_SETBITS(dev, 8);
(void)SPI_SETFREQUENCY(dev, 20000000);
(void)SPI_SETFREQUENCY(dev, CONFIG_AT25_SPIFREQUENCY);
}
/************************************************************************************

View File

@ -162,6 +162,8 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
/* MTD Support **************************************************************/
/****************************************************************************
* Name: mtd_partition
*
@ -198,6 +200,17 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd,
int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd);
/****************************************************************************
* Name: flash_eraseall
*
* Description:
* Call a block driver with the MDIOC_BULKERASE ioctl command. This will
* cause the MTD driver to erase all of the flash.
*
****************************************************************************/
int flash_eraseall(FAR const char *driver);
/****************************************************************************
* Name: smart_initialize
*
@ -217,16 +230,54 @@ int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd);
int smart_initialize(int minor, FAR struct mtd_dev_s *mtd,
FAR const char *partname);
/* MTD Driver Initialization ************************************************/
/* Create an initialized MTD device instance for a particular memory device.
* MTD devices are not registered in the file system as are other device
* driver but, but are created as instances that can be bound to other
* functions (such as a block or character driver front end).
*/
/****************************************************************************
* Name: flash_eraseall
* Name: at45db_initialize
*
* Description:
* Call a block driver with the MDIOC_BULKERASE ioctl command. This will
* cause the MTD driver to erase all of the flash.
* Initializes the driver for SPI-based AT45DB161D (16Mbit).
*
****************************************************************************/
int flash_eraseall(FAR const char *driver);
FAR struct mtd_dev_s *at45db_initialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: at24c_initialize
*
* Description:
* Initializes the driver for I2C-based at24cxx EEPROM(AT24C32, AT24C64,
* AT24C128, AT24C256)
*
****************************************************************************/
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev);
/****************************************************************************
* Name: at25_initialize
*
* Description:
* Initializes the driver for SPI-based AT25DF321 (32Mbit) flash.
*
****************************************************************************/
FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: m25p_initialize
*
* Description:
* Initializes the for SPI-based M25P1 (128Kbit), M25P64 (32Mbit), M25P64
* (64Mbit), and M25P128 (128Mbit) FLASH (and compatible).
*
****************************************************************************/
FAR struct mtd_dev_s *m25p_initialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: rammtd_initialize
@ -242,49 +293,14 @@ int flash_eraseall(FAR const char *driver);
FAR struct mtd_dev_s *rammtd_initialize(FAR uint8_t *start, size_t size);
/****************************************************************************
* Name: m25p_initialize
*
* Description:
* Create an initialized MTD device instance. MTD devices are not registered
* in the file system, but are created as instances that can be bound to
* other functions (such as a block or character driver front end).
*
****************************************************************************/
FAR struct mtd_dev_s *m25p_initialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: at45db_initialize
*
* Description:
* Create an initialized MTD device instance. MTD devices are not registered
* in the file system, but are created as instances that can be bound to
* other functions (such as a block or character driver front end).
*
****************************************************************************/
FAR struct mtd_dev_s *at45db_initialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: at24c_initialize
*
* Description:
* Create an initialized MTD device instance. MTD devices are not registered
* in the file system, but are created as instances that can be bound to
* other functions (such as a block or character driver front end).
*
****************************************************************************/
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev);
/****************************************************************************
* Name: sst25_initialize
*
* Description:
* Create an initialized MTD device instance. MTD devices are not registered
* in the file system, but are created as instances that can be bound to
* other functions (such as a block or character driver front end).
* Initializes the drvier for SPI-based SST25 FLASH
*
* Supports SST25VF512, SST25VF010, SST25VF520, SST25VF540, SST25VF080,
* and SST25VF016
*
****************************************************************************/
@ -295,10 +311,9 @@ FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev);
*
* Description:
* Create and initialize an MTD device instance assuming an SST39VF NOR
* FLASH device at the configured address in memory. MTD devices are not
* registered in the file system, but are created as instances that can
* be bound to other functions (such as a block or character driver front
* end).
* FLASH device at the configured address in memory.
*
* Supports SST39VF1601, SST39VF1602, SST39VF3201, SST39VF3202.
*
****************************************************************************/
@ -308,16 +323,13 @@ FAR struct mtd_dev_s *sst39vf_initialize(void);
* Name: w25_initialize
*
* Description:
* Create an initialized MTD device instance. MTD devices are not registered
* in the file system, but are created as instances that can be bound to
* other functions (such as a block or character driver front end).
* Initializes the driver for SPI-based W25x16, x32, and x64 and W25q16,
* q32, q64, and q128 FLASH
*
****************************************************************************/
FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev);
FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: up_flashinitialize
*