SAMA5D3x-EK: Add support for USB MSC device on AT25 serial flash

This commit is contained in:
Gregory Nutt 2013-09-06 13:07:29 -06:00
parent 4f9b277dac
commit 15ecbb9ab4
9 changed files with 347 additions and 85 deletions

View File

@ -62,15 +62,10 @@
# define CONFIG_EXAMPLES_USBMSC_DEVMINOR1 0
#endif
/* SLOT number(s) could depend on the board configuration */
/* SLOT number(s) depends on the board configuration */
#ifdef CONFIG_ARCH_BOARD_SAM3U10E_EVAL
# undef SAM_MMCSDSLOTNO
# define SAM_MMCSDSLOTNO 0
#else
/* Add configuration for new SAM3U boards here */
# error "Unrecognized SAM3U board"
#endif
#undef SAM_MMCSDSLOTNO
#define SAM_MMCSDSLOTNO 0
/* Debug ********************************************************************/

View File

@ -975,20 +975,105 @@ Configurations
order to enable the AT25 FLASH chip select.
You can then format the AT25 FLASH for a FAT file system and mount
the file system at /mnt/sdcard using these NSH commands:
the file system at /mnt/at25 using these NSH commands:
nsh> mkfatfs /dev/mtdblock0
nsh> mount -t vfat /dev/mtdblock0 /mnt/sdcard
nsh> mount -t vfat /dev/mtdblock0 /mnt/at25
Then you an use the FLASH as a normal FAT file system:
nsh> echo "This is a test" >/mnt/sdcard/atest.txt
nsh> ls -l /mnt/sdcard
/mnt/sdcard:
nsh> echo "This is a test" >/mnt/at25/atest.txt
nsh> ls -l /mnt/at25
/mnt/at25:
-rw-rw-rw- 16 atest.txt
nsh> cat /mnt/sdcard/atest.txt
nsh> cat /mnt/at25/atest.txt
This is a test
6. Support the USB high-speed EHCI device (UDPHS) driver is enabled.
These are the relevant NuttX configuration settings:
Device Drivers -> USB Device Driver Support
CONFIG_USBDEV=y : Enable USB device support
CONFIG_USBDEV_DUALSPEED=y : Device support High and Full Speed
CONFIG_USBDEV_DMA=y : Device uses DMA
System Type -> ATSAMA5 Peripheral Support
CONFIG_SAMA5_UDPHS=y : Enable UDPHS High Speed USB device
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : NSH board-initialization
The Mass Storage Class (MSC) class driver is seleced for use with
UDPHS:
Device Drivers -> USB Device Driver Support
CONFIG_USBMSC=y : Enable the USB MSC class driver
CONFIG_USBMSC_EPBULKOUT=1 : Use EP1 for the BULK OUT endpoint
CONFIG_USBMSC_EPBULKIN=2 : Use EP2 for the BULK IN endpoint
The following setting enables an example that can can be used to
control the CDC/ACM device. It will add two new NSH commands:
a. msconn will connect the USB serial device and export the AT25
to the the host, and
b. msdis which will disconnect the USB serial device.
Application Configuration -> Examples:
CONFIG_EXAMPLES_USBMSC=y : Enable the USBMSC example
CONFIG_EXAMPLES_USBMSC_NLUNS=1 : One LUN
CONFIG_EXAMPLES_USBMSC_DEVMINOR1=0 : Minor device zero
CONFIG_EXAMPLES_USBMSC_DEVPATH1="/dev/mmcsd0"
: Use a single, LUN: The AT25
: block driver.
NOTE: To prevent file system corruption, make sure that the AT25
is un-mounted *before* exporting the mass storage device to the host:
nsh> umount /mnt
nsh> mscon
The AT25 can be re-mount after the mass storage class is disconnected:
nsh> msdis
nsh> mount -t vfat /dev/mtdblock0 /mnt/at25
The following features are *not* enabled in the demo configuration but
might be of some use to you:
7. Debugging USB Device. There is normal console debug output available
that can be enabled with CONFIG_DEBUG + CONFIG_DEBUG_USB. However,
USB device operation is very time critical and enabling this debug
output WILL interfere with the operation of the UDPHS. USB device
tracing is a less invasive way to get debug information: If tracing
is enabled, the USB device will save encoded trace output in in-memory
buffer; if the USB monitor is also enabled, that trace buffer will be
periodically emptied and dumped to the system logging device (the
serial console in this configuration):
Device Drivers -> "USB Device Driver Support:
CONFIG_USBDEV_TRACE=y : Enable USB trace feature
CONFIG_USBDEV_TRACE_NRECORDS=256 : Buffer 256 records in memory
Application Configuration -> NSH LIbrary:
CONFIG_NSH_USBDEV_TRACE=n : No builtin tracing from NSH
CONFIG_NSH_ARCHINIT=y : Automatically start the USB monitor
Application Configuration -> System NSH Add-Ons:
CONFIG_SYSTEM_USBMONITOR=y : Enable the USB monitor daemon
CONFIG_SYSTEM_USBMONITOR_STACKSIZE=2048 : USB monitor daemon stack size
CONFIG_SYSTEM_USBMONITOR_PRIORITY=50 : USB monitor daemon priority
CONFIG_SYSTEM_USBMONITOR_INTERVAL=1 : Dump trace data every second
CONFIG_SYSTEM_USBMONITOR_TRACEINIT=y : Enable TRACE output
CONFIG_SYSTEM_USBMONITOR_TRACECLASS=y
CONFIG_SYSTEM_USBMONITOR_TRACETRANSFERS=y
CONFIG_SYSTEM_USBMONITOR_TRACECONTROLLER=y
CONFIG_SYSTEM_USBMONITOR_TRACEINTERRUPTS=y
NOTE: If USB debug output is also enabled, both outpus will appear
on the serial console. However, the debug output will be
asynchronous with the trace output and, hence, difficult to
interpret.
hello:
This configuration directory, performs the (almost) simplest of all
possible examples: examples/hello. This just comes up, says hello
@ -1287,7 +1372,7 @@ Configurations
volume when it is removed. But those callbacks are not used in
this configuration.
10) Support the USB low/full-speed OHCI host driver can be enabled by changing
10. Support the USB low/full-speed OHCI host driver can be enabled by changing
the NuttX configuration file as follows:
System Type -> ATSAMA5 Peripheral Support
@ -1314,7 +1399,7 @@ Configurations
multiple of the 48MHz needed for OHCI. The delay loop calibration
values that are used will be off slightly because of this.
10) Support the USB high-speed EHCI host driver can be enabled by changing
11. Support the USB high-speed EHCI host driver can be enabled by changing
the NuttX configuration file as follows. If EHCI is enabled by itself,
then only high-speed devices can be supported. If OHCI is also enabled,
then all low-, full-, and high speed devices should work.
@ -1341,8 +1426,8 @@ Configurations
Application Configuration -> NSH Library
CONFIG_NSH_ARCHINIT=y : NSH board-initialization
10) Support the USB high-speed EHCI host driver can be enabled by changing
the NuttX configuration file as follows. If EHCI is enabled by itself,
12. Support the USB high-speed EHCI device driver (UDPHS) can be enabled
by changing the NuttX configuration file as follows:
Device Drivers -> USB Device Driver Support
CONFIG_USBDEV=y : Enable USB device support

View File

@ -147,7 +147,7 @@ CONFIG_SAMA5_SPI0=y
CONFIG_SAMA5_DMAC0=y
# CONFIG_SAMA5_DMAC1 is not set
# CONFIG_SAMA5_UHPHS is not set
# CONFIG_SAMA5_UDPHS is not set
CONFIG_SAMA5_UDPHS=y
# CONFIG_SAMA5_GMAC is not set
# CONFIG_SAMA5_EMAC is not set
# CONFIG_SAMA5_LCDC is not set
@ -171,6 +171,11 @@ CONFIG_SAMA5_MPDDRC=y
CONFIG_SAMA5_SPI_DMA=y
CONFIG_SAMA5_SPI_DMATHRESHOLD=4
#
# USB High Speed Device Controller driver (DCD) options
#
# CONFIG_UDPHS_SCATTERGATHER is not set
#
# External Memory Configuration
#
@ -410,7 +415,40 @@ CONFIG_USART1_2STOP=0
# CONFIG_USART1_OFLOWCONTROL is not set
# CONFIG_SERIAL_IFLOWCONTROL is not set
# CONFIG_SERIAL_OFLOWCONTROL is not set
# CONFIG_USBDEV is not set
CONFIG_USBDEV=y
#
# USB Device Controller Driver Options
#
# CONFIG_USBDEV_ISOCHRONOUS is not set
CONFIG_USBDEV_DUALSPEED=y
CONFIG_USBDEV_SELFPOWERED=y
# CONFIG_USBDEV_BUSPOWERED is not set
CONFIG_USBDEV_MAXPOWER=100
CONFIG_USBDEV_DMA=y
# CONFIG_USBDEV_DMAMEMORY is not set
# CONFIG_USBDEV_TRACE is not set
#
# USB Device Class Driver Options
#
# CONFIG_USBDEV_COMPOSITE is not set
# CONFIG_PL2303 is not set
# CONFIG_CDCACM is not set
CONFIG_USBMSC=y
CONFIG_USBMSC_EP0MAXPACKET=64
CONFIG_USBMSC_EPBULKOUT=1
CONFIG_USBMSC_EPBULKIN=2
CONFIG_USBMSC_NWRREQS=4
CONFIG_USBMSC_NRDREQS=4
CONFIG_USBMSC_BULKINREQLEN=512
CONFIG_USBMSC_BULKOUTREQLEN=512
CONFIG_USBMSC_VENDORID=0x00
CONFIG_USBMSC_VENDORSTR="Nuttx"
CONFIG_USBMSC_PRODUCTID=0x00
CONFIG_USBMSC_PRODUCTSTR="Mass Storage"
CONFIG_USBMSC_VERSIONNO=0x399
# CONFIG_USBMSC_REMOVABLE is not set
# CONFIG_USBHOST is not set
# CONFIG_WIRELESS is not set
@ -593,7 +631,15 @@ CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
# CONFIG_EXAMPLES_UDP is not set
# CONFIG_EXAMPLES_UIP is not set
# CONFIG_EXAMPLES_USBSERIAL is not set
# CONFIG_EXAMPLES_USBMSC is not set
CONFIG_EXAMPLES_USBMSC=y
CONFIG_EXAMPLES_USBMSC_NLUNS=1
CONFIG_EXAMPLES_USBMSC_DEVMINOR1=0
CONFIG_EXAMPLES_USBMSC_DEVPATH1="/dev/mtdblock0"
CONFIG_EXAMPLES_USBMSC_DEVMINOR2=1
CONFIG_EXAMPLES_USBMSC_DEVPATH2="/dev/mmcsd1"
CONFIG_EXAMPLES_USBMSC_DEVMINOR3=2
CONFIG_EXAMPLES_USBMSC_DEVPATH3="/dev/mmcsd2"
# CONFIG_EXAMPLES_USBMSC_DEBUGMM is not set
# CONFIG_EXAMPLES_USBTERM is not set
# CONFIG_EXAMPLES_WATCHDOG is not set
@ -696,6 +742,7 @@ CONFIG_NSH_NESTDEPTH=3
# CONFIG_NSH_DISABLESCRIPT is not set
# CONFIG_NSH_DISABLEBG is not set
CONFIG_NSH_CONSOLE=y
# CONFIG_NSH_USBCONSOLE is not set
#
# USB Trace Support

View File

@ -90,6 +90,10 @@ ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += sam_nsh.c
endif
ifeq ($(CONFIG_USBMSC),y)
CSRCS += sam_usbmsc.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += sam_autoleds.c
else

View File

@ -78,56 +78,64 @@ int sam_at25_initialize(int minor)
{
FAR struct spi_dev_s *spi;
FAR struct mtd_dev_s *mtd;
static bool initialized = false;
int ret;
/* Get the SPI port driver */
/* Have we already initialized? */
spi = up_spiinitialize(AT25_PORT);
if (!spi)
if (!initialized)
{
fdbg("ERROR: Failed to initialize SPI port %d\n", AT25_PORT);
return -ENODEV;
}
/* No.. Get the SPI port driver */
/* Now bind the SPI interface to the AT25 SPI FLASH driver */
spi = up_spiinitialize(AT25_PORT);
if (!spi)
{
fdbg("ERROR: Failed to initialize SPI port %d\n", AT25_PORT);
return -ENODEV;
}
mtd = at25_initialize(spi);
if (!mtd)
{
fdbg("ERROR: Failed to bind SPI port %d to the AT25 FLASH driver\n");
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 */
/* 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;
}
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 */
/* 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;
}
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;
}
/* 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 intialized */
initialized = true;
}
return OK;
}

View File

@ -56,34 +56,6 @@
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* 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_HSMCI_MTD
# 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
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS

View File

@ -0,0 +1,125 @@
/****************************************************************************
* configs/sama5d3x-ek/src/up_usbmsc.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Configure and register the SAM3U MMC/SD SDIO block driver.
*
* 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 <stdio.h>
#include <debug.h>
#include <errno.h>
#include "sama5d3x-ek.h"
#ifdef CONFIG_USBMSC
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef HAVE_AT25_MTD
# error AT25 Serial FLASH not supported
#endif
#ifndef CONFIG_SAMA5_AT25_FTL
# error AT25 FTL support required (CONFIG_SAMA5_AT25_FTL)
# undef HAVE_AT25_MTD
#endif
#ifndef CONFIG_EXAMPLES_USBMSC_DEVMINOR1
# define CONFIG_EXAMPLES_USBMSC_DEVMINOR1 0
#endif
#if CONFIG_EXAMPLES_USBMSC_DEVMINOR1 != AT25_MINOR
# error Confusion in the assignment of minor device numbers
# undef HAVE_AT25_MTD
#endif
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lowsyslog(__VA_ARGS__)
# define msgflush()
# else
# define message(...) printf(__VA_ARGS__)
# define msgflush() fflush(stdout)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lowsyslog
# define msgflush()
# else
# define message printf
# define msgflush() fflush(stdout)
# endif
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: usbmsc_archinitialize
*
* Description:
* Perform architecture specific initialization
*
****************************************************************************/
int usbmsc_archinitialize(void)
{
/* Initialize the AT25 MTD driver */
#ifdef HAVE_AT25_MTD
int ret = sam_at25_initialize(AT25_MINOR);
if (ret < 0)
{
message("ERROR: sam_at25_initialize failed: %d\n", ret);
}
return ret;
#else
return -ENODEV;
#endif
}
#endif /* CONFIG_USBMSC */

View File

@ -111,6 +111,32 @@
# undef CONFIG_SAMA5_AT25_NXFFS
#endif
/* Assign minor device numbers. We basically ignore most 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_HSMCI_MTD
# 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
/* USB Host / USB Device */
/* Either CONFIG_SAMA5_UHPHS or CONFIG_SAMA5_UDPHS must be defined, or there is
* no USB of any kind.

View File

@ -743,7 +743,7 @@ Where <subdir> is one of the following:
CONFIG_USBMSC=y : Enables the USB MSC class
Application Configuration->Examples:
CONFIG_EXAMPLES_USBSTORAGE=y : Enhables apps/examples/usbmsc
CONFIG_EXAMPLES_USBMSC=y : Enhables apps/examples/usbmsc
3. SD Card Support.