diff --git a/arch/arm/src/lpc313x/lpc313x_usbdev.c b/arch/arm/src/lpc313x/lpc313x_usbdev.c
new file mode 100755
index 0000000000000000000000000000000000000000..30e007e9592008c3e6e2208730e65803b7086da4
--- /dev/null
+++ b/arch/arm/src/lpc313x/lpc313x_usbdev.c
@@ -0,0 +1,2671 @@
+/*******************************************************************************
+ * arch/arm/src/lpc313x/lpc313x_usbdev.c
+ *
+ *   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/usb.h>
+#include <nuttx/usbdev.h>
+#include <nuttx/usbdev_trace.h>
+
+#include <arch/irq.h>
+#include <arch/board/board.h>
+
+#include "chip.h"
+#include "up_arch.h"
+#include "up_internal.h"
+
+#include "lpc313x_usbotg.h"
+#include "lpc313x_evntrtr.h"
+#include "lpc313x_syscreg.h"
+
+/*******************************************************************************
+ * Definitions
+ *******************************************************************************/
+
+/* Configuration ***************************************************************/
+
+#ifndef CONFIG_USBDEV_EP0_MAXSIZE
+#  define CONFIG_USBDEV_EP0_MAXSIZE 64
+#endif
+
+#ifndef  CONFIG_USBDEV_MAXPOWER
+#  define CONFIG_USBDEV_MAXPOWER 100  /* mA */
+#endif
+
+/* Extremely detailed register debug that you would normally never want
+ * enabled.
+ */
+
+#undef CONFIG_LPC313X_USBDEV_REGDEBUG
+
+/* Enable reading SOF from interrupt handler vs. simply reading on demand.  Probably
+ * a bad idea... Unless there is some issue with sampling the SOF from hardware
+ * asynchronously.
+ */
+
+#ifdef CONFIG_LPC313X_USBDEV_FRAME_INTERRUPT
+#  define USB_FRAME_INT USBDEV_USBINTR_SRE
+#else
+#  define USB_FRAME_INT 0
+#endif
+
+#ifdef CONFIG_DEBUG
+#  define USB_ERROR_INT USBDEV_USBINTR_UEE
+#else
+#  define USB_ERROR_INT 0
+#endif
+
+/* Debug ***********************************************************************/
+
+/* Trace error codes */
+
+#define LPC313X_TRACEERR_ALLOCFAIL            0x0001
+#define LPC313X_TRACEERR_BADCLEARFEATURE      0x0002
+#define LPC313X_TRACEERR_BADDEVGETSTATUS      0x0003
+#define LPC313X_TRACEERR_BADEPNO              0x0004
+#define LPC313X_TRACEERR_BADEPGETSTATUS       0x0005
+#define LPC313X_TRACEERR_BADEPTYPE            0x0006
+#define LPC313X_TRACEERR_BADGETCONFIG         0x0007
+#define LPC313X_TRACEERR_BADGETSETDESC        0x0008
+#define LPC313X_TRACEERR_BADGETSTATUS         0x0009
+#define LPC313X_TRACEERR_BADSETADDRESS        0x000a
+#define LPC313X_TRACEERR_BADSETCONFIG         0x000b
+#define LPC313X_TRACEERR_BADSETFEATURE        0x000c
+#define LPC313X_TRACEERR_BINDFAILED           0x000d
+#define LPC313X_TRACEERR_DISPATCHSTALL        0x000e
+#define LPC313X_TRACEERR_DRIVER               0x000f
+#define LPC313X_TRACEERR_DRIVERREGISTERED     0x0010
+#define LPC313X_TRACEERR_EP0SETUPSTALLED      0x0011
+#define LPC313X_TRACEERR_EPINNULLPACKET       0x0012
+#define LPC313X_TRACEERR_EPOUTNULLPACKET      0x0013
+#define LPC313X_TRACEERR_INVALIDCTRLREQ       0x0014
+#define LPC313X_TRACEERR_INVALIDPARMS         0x0015
+#define LPC313X_TRACEERR_IRQREGISTRATION      0x0016
+#define LPC313X_TRACEERR_NOEP                 0x0017
+#define LPC313X_TRACEERR_NOTCONFIGURED        0x0018
+#define LPC313X_TRACEERR_REQABORTED           0x0019
+
+/* Trace interrupt codes */
+
+#define LPC313X_TRACEINTID_USB                0x0001
+#define LPC313X_TRACEINTID_CLEARFEATURE       0x0002
+#define LPC313X_TRACEINTID_DEVGETSTATUS       0x0003
+#define LPC313X_TRACEINTID_DEVRESET           0x0004
+#define LPC313X_TRACEINTID_DISPATCH           0x0005
+#define LPC313X_TRACEINTID_EP0COMPLETE        0x0006
+#define LPC313X_TRACEINTID_EP0NAK             0x0007
+#define LPC313X_TRACEINTID_EP0SETUP           0x0008
+#define LPC313X_TRACEINTID_EPGETSTATUS        0x0009
+#define LPC313X_TRACEINTID_EPIN               0x000a
+#define LPC313X_TRACEINTID_EPINQEMPTY         0x000b
+#define LPC313X_TRACEINTID_EP0INSETADDRESS    0x000c
+#define LPC313X_TRACEINTID_EPOUT              0x000d
+#define LPC313X_TRACEINTID_EPOUTQEMPTY        0x000e
+#define LPC313X_TRACEINTID_EP0SETUPSETADDRESS 0x000f
+#define LPC313X_TRACEINTID_FRAME              0x0010
+#define LPC313X_TRACEINTID_GETCONFIG          0x0011
+#define LPC313X_TRACEINTID_GETSETDESC         0x0012
+#define LPC313X_TRACEINTID_GETSETIF           0x0013
+#define LPC313X_TRACEINTID_GETSTATUS          0x0014
+#define LPC313X_TRACEINTID_IFGETSTATUS        0x0015
+#define LPC313X_TRACEINTID_SETCONFIG          0x0016
+#define LPC313X_TRACEINTID_SETFEATURE         0x0017
+#define LPC313X_TRACEINTID_SUSPENDCHG         0x0018
+#define LPC313X_TRACEINTID_SYNCHFRAME         0x0019
+
+/* Hardware interface **********************************************************/
+
+/* This represents a Endpoint Transfer Descriptor - note these must be 32 byte aligned */
+struct lpc313x_dtd_s
+{
+  volatile uint32_t       nextdesc;      /* Address of the next DMA descripto in RAM */
+  volatile uint32_t       config;        /* Misc. bit encoded configuration information */
+  uint32_t                buffer0;       /* Buffer start address */
+  uint32_t                buffer1;       /* Buffer start address */
+  uint32_t                buffer2;       /* Buffer start address */
+  uint32_t                buffer3;       /* Buffer start address */
+  uint32_t                buffer4;       /* Buffer start address */
+  uint32_t                xfer_len;      /* Software only - transfer len that was queued */
+};
+
+/* DTD nextdesc field*/
+#define DTD_NEXTDESC_INVALID		(1 << 0)	/* Bit 0     : Next Descriptor Invalid */
+
+/* DTD config field */
+#define DTD_CONFIG_LENGTH(n)		((n) << 16)	/* Bits 16-31 : Total bytes to transfer */
+#define DTD_CONFIG_IOC			(1 << 15)	/* Bit 15     : Interrupt on Completion */
+#define DTD_CONFIG_MULT_VARIABLE	(0 << 10)	/* Bits 10-11 : Number of packets executed per transacation descriptor (override) */
+#define DTD_CONFIG_MULT_NUM(n)		((n) << 10)
+#define DTD_CONFIG_ACTIVE		(1 << 7)	/* Bit 7      : Status Active */
+#define DTD_CONFIG_HALTED		(1 << 6)	/* Bit 6      : Status Halted */
+#define DTD_CONFIG_BUFFER_ERROR		(1 << 5)	/* Bit 6      : Status Buffer Error */
+#define DTD_CONFIG_TRANSACTION_ERROR	(1 << 3)	/* Bit 3      : Status Transaction Error */
+
+/* This represents a queue head  - not these must be aligned to a 2048 byte boundary */
+struct lpc313x_dqh_s
+{
+  uint32_t                capability;	/* Endpoint capability */
+  uint32_t                currdesc;	/* Current dTD pointer */
+  struct lpc313x_dtd_s    overlay;	/* DTD overlay */
+  volatile uint32_t       setup[2];	/* Set-up buffer */
+  uint32_t                gap[4];	/* align to 64 bytes */
+};
+
+/* DQH capability field */
+#define DQH_CAPABILITY_MULT_VARIABLE	(0 << 30)	/* Bits 30-31 : Number of packets executed per transaction descriptor */
+#define DQH_CAPABILITY_MULT_NUM(n)	((n) << 30)
+#define DQH_CAPABILITY_ZLT		(1 << 29)	/* Bit 29     : Zero Length Termination Select */
+#define DQH_CAPABILITY_MAX_PACKET(n)	((n) << 16)	/* Bits 16-29 : Maximum packet size of associated endpoint (<1024) */
+#define DQH_CAPABILITY_IOS		(1 << 15)	/* Bit 15     : Interrupt on Setup */
+
+/* Endpoints ******************************************************************/
+
+/* Number of endpoints */
+#define LPC313X_NLOGENDPOINTS        (4)          /* ep0-3 */
+#define LPC313X_NPHYSENDPOINTS       (8)          /* x2 for IN and OUT */
+
+/* Odd physical endpoint numbers are IN; even are OUT */
+#define LPC313X_EPPHYIN(epphy)       (((epphy)&1)!=0)
+#define LPC313X_EPPHYOUT(epphy)      (((epphy)&1)==0)
+
+#define LPC313X_EPPHYIN2LOG(epphy)   (((uint8_t)(epphy)>>1)|USB_DIR_IN)
+#define LPC313X_EPPHYOUT2LOG(epphy)  (((uint8_t)(epphy)>>1)|USB_DIR_OUT)
+
+/* Endpoint 0 is special... */
+#define LPC313X_EP0_OUT		        (0)
+#define LPC313X_EP0_IN		        (1)
+
+/* Each endpoint has somewhat different characteristics */
+#define LPC313X_EPALLSET                (0xff)        /* All endpoints */
+#define LPC313X_EPOUTSET                (0x55)        /* Even phy endpoint numbers are OUT EPs */
+#define LPC313X_EPINSET                 (0xaa)        /* Odd endpoint numbers are IN EPs */
+#define LPC313X_EPCTRLSET               (0x03)        /* EP0 IN/OUT are control endpoints */
+#define LPC313X_EPINTRSET               (0xa8)        /* Interrupt endpoints */
+#define LPC313X_EPBULKSET               (0xfc)        /* Bulk endpoints */
+#define LPC313X_EPISOCSET               (0xfc)        /* Isochronous endpoints */
+
+/* Maximum packet sizes for endpoints */
+#define LPC313X_EP0MAXPACKET            (64)          /* EP0 max packet size (1-64) */
+#define LPC313X_BULKMAXPACKET           (512)         /* Bulk endpoint max packet (8/16/32/64/512) */
+#define LPC313X_INTRMAXPACKET           (1024)        /* Interrupt endpoint max packet (1 to 1024) */
+#define LPC313X_ISOCMAXPACKET           (512)         /* Acutally 1..1023 */
+
+/* The address of the endpoint control register */
+#define LPC313X_USBDEV_ENDPTCTRL(epphy) (LPC313X_USBDEV_ENDPTCTRL0 + ((epphy)>>1)*4)
+
+/* Endpoint bit position in SETUPSTAT, PRIME, FLUSH, STAT, COMPLETE registers */
+#define LPC313X_ENDPTSHIFT(epphy)      (LPC313X_EPPHYIN(epphy) ? (16 + ((epphy) >> 1)) : ((epphy) >> 1))
+#define LPC313X_ENDPTMASK(epphy)       (1 << LPC313X_ENDPTSHIFT(epphy))
+#define LPC313X_ENDPTMASK_ALL	        0x000f000f
+
+/* Request queue operations ****************************************************/
+
+#define lpc313x_rqempty(ep)          ((ep)->head == NULL)
+#define lpc313x_rqpeek(ep)           ((ep)->head)
+
+/*******************************************************************************
+ * Private Types
+ *******************************************************************************/
+
+/* A container for a request so that the request may be retained in a list */
+
+struct lpc313x_req_s
+{
+  struct usbdev_req_s    req;           /* Standard USB request */
+  struct lpc313x_req_s  *flink;         /* Supports a singly linked list */
+};
+
+/* This is the internal representation of an endpoint */
+
+struct lpc313x_ep_s
+{
+  /* Common endpoint fields.  This must be the first thing defined in the
+   * structure so that it is possible to simply cast from struct usbdev_ep_s
+   * to struct lpc313x_ep_s.
+   */
+
+  struct usbdev_ep_s      ep;            /* Standard endpoint structure */
+
+  /* LPC313X-specific fields */
+
+  struct lpc313x_usbdev_s *dev;          /* Reference to private driver data */
+  struct lpc313x_req_s    *head;         /* Request list for this endpoint */
+  struct lpc313x_req_s    *tail;
+  uint8_t                 epphy;         /* Physical EP address */
+  uint8_t                 stalled:1;     /* 1: Endpoint is stalled */
+  uint8_t                 halted:1;      /* 1: Endpoint feature halted */
+};
+
+/* This structure retains the state of the USB device controller */
+
+struct lpc313x_usbdev_s
+{
+  /* Common device fields.  This must be the first thing defined in the
+   * structure so that it is possible to simply cast from struct usbdev_s
+   * to struct lpc313x_usbdev_s.
+   */
+
+  struct usbdev_s         usbdev;
+
+  /* The bound device class driver */
+
+  struct usbdevclass_driver_s *driver;
+
+  /* LPC313X-specific fields */
+
+  uint8_t                 ep0state;      /* State of certain EP0 operations */
+  uint8_t                 ep0buf[64];	 /* buffer for EP0 short transfers */
+  uint8_t                 paddr;         /* Address assigned by SETADDRESS */
+  uint8_t                 stalled:1;     /* 1: Protocol stalled */
+  uint8_t                 selfpowered:1; /* 1: Device is self powered */
+  uint8_t                 paddrset:1;    /* 1: Peripheral addr has been set */
+  uint8_t                 attached:1;    /* 1: Host attached */
+  uint32_t                softprio;      /* Bitset of high priority interrupts */
+  uint32_t                epavail;       /* Bitset of available endpoints */
+#ifdef CONFIG_LPC313X_USBDEV_FRAME_INTERRUPT
+  uint32_t                sof;           /* Last start-of-frame */
+#endif
+
+  /* The endpoint list */
+  struct lpc313x_ep_s     eplist[LPC313X_NPHYSENDPOINTS];
+};
+
+#define EP0STATE_IDLE			0		/* Idle State, leave on receiving a setup packet or epsubmit */
+#define EP0STATE_SETUP_OUT		1		/* Setup Packet received - SET/CLEAR */
+#define EP0STATE_SETUP_IN		2		/* Setup Packet received - GET */
+#define EP0STATE_SHORTWRITE		3		/* Short write without a usb_request */
+#define EP0STATE_WAIT_NAK_OUT		4		/* Waiting for Host to illicit status phase (GET) */
+#define EP0STATE_WAIT_NAK_IN		5		/* Waiting for Host to illicit status phase (SET/CLEAR) */
+#define EP0STATE_WAIT_STATUS_OUT	6		/* Wait for status phase to complete */
+#define EP0STATE_WAIT_STATUS_IN		7		/* Wait for status phase to complete */
+#define EP0STATE_DATA_IN		8
+#define EP0STATE_DATA_OUT		9
+
+/*******************************************************************************
+ * Private Function Prototypes
+ *******************************************************************************/
+
+/* Register operations ********************************************************/
+
+#if defined(CONFIG_LPC313X_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG)
+static uint32_t lpc313x_getreg(uint32_t addr);
+static void lpc313x_putreg(uint32_t val, uint32_t addr);
+#else
+# define lpc313x_getreg(addr)     getreg32(addr)
+# define lpc313x_putreg(val,addr) putreg32(val,addr)
+#endif
+
+static inline void lpc313x_clrbits(uint32_t mask, uint32_t addr);
+static inline void lpc313x_setbits(uint32_t mask, uint32_t addr);
+static inline void lpc313x_chgbits(uint32_t mask, uint32_t val, uint32_t addr);
+
+/* Request queue operations ****************************************************/
+
+static FAR struct lpc313x_req_s *lpc313x_rqdequeue(FAR struct lpc313x_ep_s *privep);
+static bool                      lpc313x_rqenqueue(FAR struct lpc313x_ep_s *privep,
+						   FAR struct lpc313x_req_s *req);
+
+/* Low level data transfers and request operations *****************************/
+
+static inline void lpc313x_writedtd(struct lpc313x_dtd_s *dtd, const uint8_t *data, uint32_t nbytes);
+static inline void lpc313x_queuedtd(uint8_t epphy, struct lpc313x_dtd_s *dtd);
+static inline void lpc313x_ep0xfer(uint8_t epphy, uint8_t *data, uint32_t nbytes);
+static void        lpc313x_readsetup(uint8_t epphy, struct usb_ctrlreq_s *ctrl);
+
+static inline void lpc313x_set_address(struct lpc313x_usbdev_s *priv, uint16_t address);
+
+static void        lpc313x_flushep(struct lpc313x_ep_s *privep);
+static inline bool lpc313x_epstalled(struct lpc313x_ep_s *privep);
+
+static int         lpc313x_progressep(struct lpc313x_ep_s *privep);
+static inline void lpc313x_abortrequest(struct lpc313x_ep_s *privep,
+					struct lpc313x_req_s *privreq, int16_t result);
+static void        lpc313x_reqcomplete(struct lpc313x_ep_s *privep, int16_t result);
+
+static void        lpc313x_cancelrequests(struct lpc313x_ep_s *privep, int16_t status);
+
+/* Interrupt handling **********************************************************/
+static struct lpc313x_ep_s *lpc313x_epfindbyaddr(struct lpc313x_usbdev_s *priv, uint16_t eplog);
+static void                 lpc313x_dispatchrequest(struct lpc313x_usbdev_s *priv, const struct usb_ctrlreq_s *ctrl);
+static void                 lpc313x_ep0configure(struct lpc313x_usbdev_s *priv);
+static void                 lpc313x_usbreset(struct lpc313x_usbdev_s *priv);
+
+static inline void          lpc313x_ep0state(struct lpc313x_usbdev_s *priv, uint16_t state);
+static void                 lpc313x_ep0setup(struct lpc313x_usbdev_s *priv);
+
+static void                 lpc313x_ep0complete(struct lpc313x_usbdev_s *priv, uint8_t epphy);
+static void                 lpc313x_ep0nak(struct lpc313x_usbdev_s *priv, uint8_t epphy);
+static bool                 lpc313x_epcomplete(struct lpc313x_usbdev_s *priv, uint8_t epphy);
+
+static int                  lpc313x_usbinterrupt(int irq, FAR void *context);
+
+/* Endpoint operations *********************************************************/
+
+/* USB device controller operations ********************************************/
+
+static int  lpc313x_epconfigure(FAR struct usbdev_ep_s *ep,
+              const struct usb_epdesc_s *desc, bool last);
+static int  lpc313x_epdisable(FAR struct usbdev_ep_s *ep);
+static FAR struct usbdev_req_s *lpc313x_epallocreq(FAR struct usbdev_ep_s *ep);
+static void lpc313x_epfreereq(FAR struct usbdev_ep_s *ep,
+              FAR struct usbdev_req_s *);
+static void *lpc313x_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes);
+static void lpc313_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf);
+static int  lpc313x_epsubmit(FAR struct usbdev_ep_s *ep,
+              struct usbdev_req_s *req);
+static int  lpc313x_epcancel(FAR struct usbdev_ep_s *ep,
+              struct usbdev_req_s *req);
+static int  lpc313x_epstall(FAR struct usbdev_ep_s *ep, bool resume);
+
+static FAR struct usbdev_ep_s *lcp313x_allocep(FAR struct usbdev_s *dev,
+					       uint8_t epno, bool in, uint8_t eptype);
+static void lpc313x_freeep(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep);
+static int  lpc313x_getframe(struct usbdev_s *dev);
+static int  lpc313x_wakeup(struct usbdev_s *dev);
+static int  lpc313x_selfpowered(struct usbdev_s *dev, bool selfpowered);
+static int  lpc313x_pullup(struct usbdev_s *dev, bool enable);
+
+/*******************************************************************************
+ * Private Data
+ *******************************************************************************/
+
+/* Since there is only a single USB interface, all status information can be
+ * be simply retained in a single global instance.
+ */
+
+static struct lpc313x_usbdev_s g_usbdev;
+
+static struct lpc313x_dqh_s __attribute__((aligned(2048))) g_qh[LPC313X_NPHYSENDPOINTS];
+static struct lpc313x_dtd_s __attribute__((aligned(32)))   g_td[LPC313X_NPHYSENDPOINTS];
+
+static const struct usbdev_epops_s g_epops =
+{
+  .configure   = lpc313x_epconfigure,
+  .disable     = lpc313x_epdisable,
+  .allocreq    = lpc313x_epallocreq,
+  .freereq     = lpc313x_epfreereq,
+#ifdef CONFIG_ARCH_USBDEV_DMA
+  .allocbuffer = lpc313x_epallocbuffer,
+  .freebuffer  = lpc313x_epfreebuffer,
+#endif
+  .submit      = lpc313x_epsubmit,
+  .cancel      = lpc313x_epcancel,
+  .stall       = lpc313x_epstall,
+};
+
+static const struct usbdev_ops_s g_devops =
+{
+  .allocep     = lcp313x_allocep,
+  .freeep      = lpc313x_freeep,
+  .getframe    = lpc313x_getframe,
+  .wakeup      = lpc313x_wakeup,
+  .selfpowered = lpc313x_selfpowered,
+  .pullup      = lpc313x_pullup,
+};
+
+/*******************************************************************************
+ * Public Data
+ *******************************************************************************/
+
+/*******************************************************************************
+ * Private Functions
+ *******************************************************************************/
+
+/*******************************************************************************
+ * Name: lpc313x_getreg
+ *
+ * Description:
+ *   Get the contents of an LPC313x register
+ *
+ *******************************************************************************/
+
+#if defined(CONFIG_LPC313X_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG)
+static uint32_t lpc313x_getreg(uint32_t addr)
+{
+  static uint32_t prevaddr = 0;
+  static uint32_t preval = 0;
+  static uint32_t count = 0;
+
+  /* Read the value from the register */
+
+  uint32_t val = getreg32(addr);
+
+  /* Is this the same value that we read from the same registe last time?  Are
+   * we polling the register?  If so, suppress some of the output.
+   */
+
+  if (addr == prevaddr && val == preval)
+    {
+      if (count == 0xffffffff || ++count > 3)
+        {
+           if (count == 4)
+             {
+               lldbg("...\n");
+             }
+          return val;
+        }
+    }
+
+  /* No this is a new address or value */
+
+  else
+    {
+       /* Did we print "..." for the previous value? */
+
+       if (count > 3)
+         {
+           /* Yes.. then show how many times the value repeated */
+
+           lldbg("[repeats %d more times]\n", count-3);
+         }
+
+       /* Save the new address, value, and count */
+
+       prevaddr = addr;
+       preval   = val;
+       count    = 1;
+    }
+
+  /* Show the register value read */
+
+  lldbg("%08x->%08x\n", addr, val);
+  return val;
+}
+#endif
+
+/*******************************************************************************
+ * Name: lpc313x_putreg
+ *
+ * Description:
+ *   Set the contents of an LPC313x register to a value
+ *
+ *******************************************************************************/
+
+#if defined(CONFIG_LPC313X_USBDEV_REGDEBUG) && defined(CONFIG_DEBUG)
+static void lpc313x_putreg(uint32_t val, uint32_t addr)
+{
+  /* Show the register value being written */
+
+  lldbg("%08x<-%08x\n", addr, val);
+
+  /* Write the value */
+
+  putreg32(val, addr);
+}
+#endif
+
+/*******************************************************************************
+ * Name: lpc313x_clrbits
+ *
+ * Description:
+ *   Clear bits in a register
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_clrbits(uint32_t mask, uint32_t addr)
+{
+  uint32_t reg = lpc313x_getreg(addr);
+  reg &= ~mask;
+  lpc313x_putreg(reg, addr);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_setbits
+ *
+ * Description:
+ *   Set bits in a register
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_setbits(uint32_t mask, uint32_t addr)
+{
+  uint32_t reg = lpc313x_getreg(addr);
+  reg |= mask;
+  lpc313x_putreg(reg, addr);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_chgbits
+ *
+ * Description:
+ *   Change bits in a register
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_chgbits(uint32_t mask, uint32_t val, uint32_t addr)
+{
+  uint32_t reg = lpc313x_getreg(addr);
+  reg &= ~mask;
+  reg |= val;
+  lpc313x_putreg(reg, addr);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_rqdequeue
+ *
+ * Description:
+ *   Remove a request from an endpoint request queue
+ *
+ *******************************************************************************/
+
+static FAR struct lpc313x_req_s *lpc313x_rqdequeue(FAR struct lpc313x_ep_s *privep)
+{
+  FAR struct lpc313x_req_s *ret = privep->head;
+
+  if (ret)
+    {
+      privep->head = ret->flink;
+      if (!privep->head)
+        {
+          privep->tail = NULL;
+        }
+
+      ret->flink = NULL;
+    }
+
+  return ret;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_rqenqueue
+ *
+ * Description:
+ *   Add a request from an endpoint request queue
+ *
+ *******************************************************************************/
+
+static bool lpc313x_rqenqueue(FAR struct lpc313x_ep_s *privep,
+                              FAR struct lpc313x_req_s *req)
+{
+  bool is_empty = !privep->head;
+  
+  req->flink = NULL;
+  if (is_empty)
+    {
+      privep->head = req;
+      privep->tail = req;
+    }
+  else
+    {
+      privep->tail->flink = req;
+      privep->tail        = req;
+    }
+  return is_empty;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_writedtd
+ *
+ * Description:
+ *   Initialise a DTD to transfer the data
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_writedtd(struct lpc313x_dtd_s *dtd, const uint8_t *data, uint32_t nbytes)
+{
+  dtd->nextdesc  = DTD_NEXTDESC_INVALID;
+  dtd->config    = DTD_CONFIG_LENGTH(nbytes) | DTD_CONFIG_IOC | DTD_CONFIG_ACTIVE;
+  dtd->buffer0   = ((uint32_t) data);
+  dtd->buffer1   = (((uint32_t) data) + 0x1000) & 0xfffff000;
+  dtd->buffer2   = (((uint32_t) data) + 0x2000) & 0xfffff000;
+  dtd->buffer3   = (((uint32_t) data) + 0x3000) & 0xfffff000;
+  dtd->buffer4   = (((uint32_t) data) + 0x4000) & 0xfffff000;
+  dtd->xfer_len  = nbytes;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_queuedtd
+ *
+ * Description:
+ *   Add the DTD to the device list
+ *
+ *******************************************************************************/
+
+static void lpc313x_queuedtd(uint8_t epphy, struct lpc313x_dtd_s *dtd)
+{
+  /* Queue the DTD onto the Endpoint */
+  /* NOTE - this only works when no DTD is currently queued */
+
+  g_qh[epphy].overlay.nextdesc = (uint32_t) dtd;
+  g_qh[epphy].overlay.config  &= ~(DTD_CONFIG_ACTIVE | DTD_CONFIG_HALTED);
+
+  uint32_t bit = LPC313X_ENDPTMASK(epphy);
+
+  lpc313x_setbits (bit, LPC313X_USBDEV_ENDPTPRIME);
+    
+  while (lpc313x_getreg (LPC313X_USBDEV_ENDPTPRIME) & bit)
+    ;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_ep0xfer
+ *
+ * Description:
+ *   Schedule a short transfer for Endpoint 0 (IN or OUT)
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_ep0xfer(uint8_t epphy, uint8_t *buf, uint32_t nbytes)
+{
+  struct lpc313x_dtd_s *dtd = &g_td[epphy];
+
+  lpc313x_writedtd(dtd, buf, nbytes);
+    
+  lpc313x_queuedtd(epphy, dtd);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_readsetup
+ *
+ * Description:
+ *   Read a Setup packet from the DTD.
+ *
+ *******************************************************************************/
+static void lpc313x_readsetup(uint8_t epphy, struct usb_ctrlreq_s *ctrl)
+{
+    struct lpc313x_dqh_s *dqh = &g_qh[epphy];
+    int i;
+
+    do {
+	/* Set the trip wire */
+	lpc313x_setbits(USBDEV_USBCMD_SUTW, LPC313X_USBDEV_USBCMD);
+
+	// copy the request...
+	for (i = 0; i < 8; i++)
+	    ((uint8_t *) ctrl)[i] = ((uint8_t *) dqh->setup)[i];
+	
+    } while (!(lpc313x_getreg(LPC313X_USBDEV_USBCMD) & USBDEV_USBCMD_SUTW));
+    
+    /* Clear the trip wire */
+    lpc313x_clrbits(USBDEV_USBCMD_SUTW, LPC313X_USBDEV_USBCMD);
+
+    /* Clear the Setup Interrupt */
+    lpc313x_putreg (LPC313X_ENDPTMASK(LPC313X_EP0_OUT), LPC313X_USBDEV_ENDPTSETUPSTAT);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_set_address
+ *
+ * Description:
+ *   Set the devices USB address
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_set_address(struct lpc313x_usbdev_s *priv, uint16_t address)
+{
+  priv->paddr    = address;
+  priv->paddrset = address != 0;
+
+  lpc313x_chgbits(USBDEV_DEVICEADDR_MASK, priv->paddr << USBDEV_DEVICEADDR_SHIFT, 
+		  LPC313X_USBDEV_DEVICEADDR);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_flushep
+ *
+ * Description:
+ *   Flush any primed descriptors from this ep
+ *
+ *******************************************************************************/
+
+static void lpc313x_flushep(struct lpc313x_ep_s *privep)
+{
+  uint32_t mask = LPC313X_ENDPTMASK(privep->epphy);
+  do {
+      lpc313x_putreg (mask, LPC313X_USBDEV_ENDPTFLUSH);
+      while ((lpc313x_getreg(LPC313X_USBDEV_ENDPTFLUSH) & mask) != 0)
+	;
+  } while ((lpc313x_getreg(LPC313X_USBDEV_ENDPTSTATUS) & mask) != 0);
+}
+
+
+/*******************************************************************************
+ * Name: lpc313x_epstalled
+ *
+ * Description:
+ *   Return whether the endpoint is stalled or not
+ *
+ *******************************************************************************/
+
+static inline bool lpc313x_epstalled(struct lpc313x_ep_s *privep)
+{
+  uint32_t ctrl = lpc313x_getreg (LPC313X_USBDEV_ENDPTCTRL(privep->epphy));
+
+  if (LPC313X_EPPHYIN(privep->epphy))
+    return (ctrl & USBDEV_ENDPTCTRL_TXS);
+  else
+    return (ctrl & USBDEV_ENDPTCTRL_RXS);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_progressep
+ *
+ * Description:
+ *   Progress the Endpoint by priming the first request into the queue head
+ *
+ *******************************************************************************/
+
+static int lpc313x_progressep(struct lpc313x_ep_s *privep)
+{
+  struct lpc313x_dtd_s *dtd = &g_td[privep->epphy];
+  struct lpc313x_req_s *privreq;
+
+  /* Check the request from the head of the endpoint request queue */
+
+  privreq = lpc313x_rqpeek(privep);
+  if (!privreq)
+    {
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EPINQEMPTY), 0);
+      return OK;
+    }
+
+  /* Ignore any attempt to send a zero length packet */
+
+  if (privreq->req.len == 0)
+    {
+	/* If the class driver is responding to a setup packet, then wait for the 
+	 * host to illicit thr response */
+
+	if (privep->epphy == LPC313X_EP0_IN && privep->dev->ep0state == EP0STATE_SETUP_OUT)
+	  lpc313x_ep0state (privep->dev, EP0STATE_WAIT_NAK_IN);
+	else
+	  {
+	    if (LPC313X_EPPHYIN(privep->epphy))
+		usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_EPINNULLPACKET), 0);
+	    else
+		usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_EPOUTNULLPACKET), 0);
+	  }
+	  
+      lpc313x_reqcomplete(privep, OK);
+      return OK;
+    }
+
+  if (privep->epphy == LPC313X_EP0_IN)
+    lpc313x_ep0state (privep->dev,  EP0STATE_DATA_IN);
+  else if (privep->epphy == LPC313X_EP0_OUT)
+    lpc313x_ep0state (privep->dev, EP0STATE_DATA_OUT);
+
+  int bytesleft = privreq->req.len - privreq->req.xfrd;
+
+  if (bytesleft > privep->ep.maxpacket)
+    bytesleft = privep->ep.maxpacket;
+
+  if (LPC313X_EPPHYIN(privep->epphy))
+    usbtrace(TRACE_WRITE(privep->epphy), privreq->req.xfrd);
+  else
+    usbtrace(TRACE_READ(privep->epphy), privreq->req.xfrd);
+
+  /* Initialise the DTD to transfer the next chunk */
+  lpc313x_writedtd (dtd, privreq->req.buf + privreq->req.xfrd, bytesleft);
+
+  /* then queue onto the DQH */
+  lpc313x_queuedtd(privep->epphy, dtd);
+
+  return OK;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_abortrequest
+ *
+ * Description:
+ *   Discard a request
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_abortrequest(struct lpc313x_ep_s *privep,
+                                        struct lpc313x_req_s *privreq,
+                                        int16_t result)
+{
+  usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_REQABORTED), (uint16_t)privep->epphy);
+
+  /* Save the result in the request structure */
+
+  privreq->req.result = result;
+
+  /* Callback to the request completion handler */
+
+  privreq->req.callback(&privep->ep, &privreq->req);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_reqcomplete
+ *
+ * Description:
+ *   Handle termination of the request at the head of the endpoint request queue.
+ *
+ *******************************************************************************/
+
+static void lpc313x_reqcomplete(struct lpc313x_ep_s *privep, int16_t result)
+{
+  struct lpc313x_req_s *privreq;
+  irqstate_t flags;
+
+  /* Remove the completed request at the head of the endpoint request list */
+
+  flags = irqsave();
+  privreq = lpc313x_rqdequeue(privep);
+  irqrestore(flags);
+
+  if (privreq)
+    {
+      /* If endpoint 0, temporarily reflect the state of protocol stalled
+       * in the callback.
+       */
+
+      bool stalled = privep->stalled;
+      if (privep->epphy == LPC313X_EP0_IN)
+        privep->stalled = privep->dev->stalled;
+
+      /* Save the result in the request structure */
+
+      privreq->req.result = result;
+
+      /* Callback to the request completion handler */
+
+      privreq->req.callback(&privep->ep, &privreq->req);
+
+      /* Restore the stalled indication */
+
+      privep->stalled = stalled;
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_cancelrequests
+ *
+ * Description:
+ *   Cancel all pending requests for an endpoint
+ *
+ *******************************************************************************/
+
+static void lpc313x_cancelrequests(struct lpc313x_ep_s *privep, int16_t status)
+{
+  if (!lpc313x_rqempty(privep))
+      lpc313x_flushep(privep);
+
+  while (!lpc313x_rqempty(privep))
+    {
+      // FIXME: the entry at the head should be sync'd with the DTD
+      // FIXME: only report the error status if the transfer hasn't completed
+      usbtrace(TRACE_COMPLETE(privep->epphy),
+               (lpc313x_rqpeek(privep))->req.xfrd);
+      lpc313x_reqcomplete(privep, status);
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epfindbyaddr
+ *
+ * Description:
+ *   Find the physical endpoint structure corresponding to a logic endpoint
+ *   address
+ *
+ *******************************************************************************/
+
+static struct lpc313x_ep_s *lpc313x_epfindbyaddr(struct lpc313x_usbdev_s *priv,
+						 uint16_t eplog)
+{
+  struct lpc313x_ep_s *privep;
+  int i;
+
+  /* Endpoint zero is a special case */
+
+  if (USB_EPNO(eplog) == 0)
+    {
+      return &priv->eplist[0];
+    }
+
+  /* Handle the remaining */
+
+  for (i = 1; i < LPC313X_NPHYSENDPOINTS; i++)
+    {
+      privep = &priv->eplist[i];
+
+      /* Same logical endpoint number? (includes direction bit) */
+
+      if (eplog == privep->ep.eplog)
+        {
+          /* Return endpoint found */
+
+          return privep;
+        }
+    }
+
+  /* Return endpoint not found */
+
+  return NULL;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_dispatchrequest
+ *
+ * Description:
+ *   Provide unhandled setup actions to the class driver. This is logically part
+ *   of the USB interrupt handler.
+ *
+ *******************************************************************************/
+
+static void lpc313x_dispatchrequest(struct lpc313x_usbdev_s *priv,
+                                    const struct usb_ctrlreq_s *ctrl)
+{
+  int ret = -EIO;
+
+  usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_DISPATCH), 0);
+  if (priv->driver)
+    {
+      /* Forward to the control request to the class driver implementation */
+
+      ret = CLASS_SETUP(priv->driver, &priv->usbdev, ctrl);
+    }
+
+  if (ret < 0)
+    {
+	/* Stall on failure */
+
+	usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_DISPATCHSTALL), 0);
+	priv->stalled = true;
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_ep0configure
+ *
+ * Description:
+ *   Reset Usb engine
+ *
+ *******************************************************************************/
+
+static void lpc313x_ep0configure(struct lpc313x_usbdev_s *priv)
+{
+  /* Enable ep0 IN and ep0 OUT */
+  g_qh[LPC313X_EP0_OUT].capability = (DQH_CAPABILITY_MAX_PACKET(CONFIG_USBDEV_EP0_MAXSIZE) |
+				      DQH_CAPABILITY_IOS |
+				      DQH_CAPABILITY_ZLT);
+
+  g_qh[LPC313X_EP0_IN ].capability = (DQH_CAPABILITY_MAX_PACKET(CONFIG_USBDEV_EP0_MAXSIZE) |
+				      DQH_CAPABILITY_IOS |
+				      DQH_CAPABILITY_ZLT);
+  
+  g_qh[LPC313X_EP0_OUT].currdesc = DTD_NEXTDESC_INVALID;
+  g_qh[LPC313X_EP0_IN ].currdesc = DTD_NEXTDESC_INVALID;
+  
+  /* Enable EP0 */
+  lpc313x_setbits (USBDEV_ENDPTCTRL0_RXE | USBDEV_ENDPTCTRL0_TXE, LPC313X_USBDEV_ENDPTCTRL0);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_usbreset
+ *
+ * Description:
+ *   Reset Usb engine
+ *
+ *******************************************************************************/
+
+static void lpc313x_usbreset(struct lpc313x_usbdev_s *priv)
+{
+  int epphy;
+
+  /* Disable all endpoints */
+
+  lpc313x_clrbits (USBDEV_ENDPTCTRL_RXE | USBDEV_ENDPTCTRL_TXE, LPC313X_USBDEV_ENDPTCTRL0);
+  lpc313x_clrbits (USBDEV_ENDPTCTRL_RXE | USBDEV_ENDPTCTRL_TXE, LPC313X_USBDEV_ENDPTCTRL1);
+  lpc313x_clrbits (USBDEV_ENDPTCTRL_RXE | USBDEV_ENDPTCTRL_TXE, LPC313X_USBDEV_ENDPTCTRL2);
+  lpc313x_clrbits (USBDEV_ENDPTCTRL_RXE | USBDEV_ENDPTCTRL_TXE, LPC313X_USBDEV_ENDPTCTRL3);
+
+  /* Clear all pending interrupts */
+
+  lpc313x_putreg (lpc313x_getreg(LPC313X_USBDEV_ENDPTNAK),       LPC313X_USBDEV_ENDPTNAK);
+  lpc313x_putreg (lpc313x_getreg(LPC313X_USBDEV_ENDPTSETUPSTAT), LPC313X_USBDEV_ENDPTSETUPSTAT);
+  lpc313x_putreg (lpc313x_getreg(LPC313X_USBDEV_ENDPTCOMPLETE),  LPC313X_USBDEV_ENDPTCOMPLETE);
+
+  /* Wait for all prime operations to have completed and then flush all DTDs */
+  while (lpc313x_getreg (LPC313X_USBDEV_ENDPTPRIME) != 0)
+    ;
+  lpc313x_putreg (LPC313X_ENDPTMASK_ALL, LPC313X_USBDEV_ENDPTFLUSH);
+  while (lpc313x_getreg (LPC313X_USBDEV_ENDPTFLUSH))
+    ;
+
+  /* Reset endpoints */
+  for (epphy = 0; epphy < LPC313X_NPHYSENDPOINTS; epphy++)
+    {
+      struct lpc313x_ep_s *privep = &priv->eplist[epphy];
+
+      lpc313x_cancelrequests (privep, -ESHUTDOWN);
+
+      /* Reset endpoint status */
+      privep->stalled = false;
+      privep->halted  = false;
+    }
+
+  /* Tell the class driver that we are disconnected. The class 
+   * driver should then accept any new configurations. */
+
+  if (priv->driver)
+      CLASS_DISCONNECT(priv->driver, &priv->usbdev);
+
+  /* Set the interrupt Threshold control interval to 0 */
+  lpc313x_chgbits(USBDEV_USBCMD_ITC_MASK, USBDEV_USBCMD_ITCIMME, LPC313X_USBDEV_USBCMD);
+
+  /* Zero out the Endpoint queue heads */
+  memset ((void *) g_qh, 0, sizeof (g_qh));
+  memset ((void *) g_td, 0, sizeof (g_td));
+
+  /* Set USB address to 0 */
+  lpc313x_set_address (priv, 0);
+
+  /* Initialise the Enpoint List Address */
+  lpc313x_putreg ((uint32_t)g_qh, LPC313X_USBDEV_ENDPOINTLIST);
+
+  /* EndPoint 0 initialization */
+  lpc313x_ep0configure(priv);
+
+  /* Enable Device interrupts */
+  lpc313x_putreg(USB_FRAME_INT | USB_ERROR_INT | 
+		 USBDEV_USBINTR_NAKE | USBDEV_USBINTR_SLE | USBDEV_USBINTR_URE | USBDEV_USBINTR_PCE | USBDEV_USBINTR_UE,
+		 LPC313X_USBDEV_USBINTR);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_setstate
+ *
+ * Description:
+ *   Sets the EP0 state and manages the NAK interrupts
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_ep0state(struct lpc313x_usbdev_s *priv, uint16_t state)
+{
+  priv->ep0state = state;
+  
+  switch (state)
+    {
+    case EP0STATE_WAIT_NAK_IN:
+      lpc313x_putreg (LPC313X_ENDPTMASK(LPC313X_EP0_IN), LPC313X_USBDEV_ENDPTNAKEN);
+      break;
+    case EP0STATE_WAIT_NAK_OUT:
+      lpc313x_putreg (LPC313X_ENDPTMASK(LPC313X_EP0_OUT), LPC313X_USBDEV_ENDPTNAKEN);
+      break;
+    default:
+      lpc313x_putreg(0, LPC313X_USBDEV_ENDPTNAKEN);
+      break;
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_ep0setup
+ *
+ * Description:
+ *   USB Ctrl EP Setup Event. This is logically part of the USB interrupt
+ *   handler.  This event occurs when a setup packet is receive on EP0 OUT.
+ *
+ *******************************************************************************/
+
+static inline void lpc313x_ep0setup(struct lpc313x_usbdev_s *priv)
+{
+  struct lpc313x_ep_s *privep;
+  struct usb_ctrlreq_s ctrl;
+  uint16_t value;
+  uint16_t index;
+  uint16_t len;
+
+  /* Terminate any pending requests - since all DTDs will have been retired 
+   * because of the setup packet */
+
+  lpc313x_cancelrequests(&priv->eplist[LPC313X_EP0_OUT], -EPROTO);
+  lpc313x_cancelrequests(&priv->eplist[LPC313X_EP0_IN],  -EPROTO);
+
+  /* Assume NOT stalled */
+
+  priv->eplist[LPC313X_EP0_OUT].stalled = false;
+  priv->eplist[LPC313X_EP0_IN].stalled = false;
+  priv->stalled = false;
+
+  /* Read EP0 setup data */
+  lpc313x_readsetup(LPC313X_EP0_OUT, &ctrl);
+
+  /* Starting a control request - update state */
+  lpc313x_ep0state (priv, (ctrl.type & USB_REQ_DIR_IN) ? EP0STATE_SETUP_IN : EP0STATE_SETUP_OUT);
+
+  /* And extract the little-endian 16-bit values to host order */
+  value = GETUINT16(ctrl.value);
+  index = GETUINT16(ctrl.index);
+  len   = GETUINT16(ctrl.len);
+
+  ullvdbg("type=%02x req=%02x value=%04x index=%04x len=%04x\n",
+          ctrl.type, ctrl.req, value, index, len);
+
+  /* Dispatch any non-standard requests */
+  if ((ctrl.type & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD)
+    lpc313x_dispatchrequest(priv, &ctrl);
+  else
+    {
+    /* Handle standard request.  Pick off the things of interest to the USB
+     * device controller driver; pass what is left to the class driver */
+    switch (ctrl.req)
+      {
+      case USB_REQ_GETSTATUS:
+        {
+          /* type:  device-to-host; recipient = device, interface, endpoint
+           * value: 0
+           * index: zero interface endpoint
+           * len:   2; data = status
+           */
+  
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_GETSTATUS), 0);
+          if (!priv->paddrset || len != 2 ||
+              (ctrl.type & USB_REQ_DIR_IN) == 0 || value != 0)
+            {
+              priv->stalled = true;
+	    }
+          else
+            {
+              switch (ctrl.type & USB_REQ_RECIPIENT_MASK)
+                {
+                case USB_REQ_RECIPIENT_ENDPOINT:
+                  {
+                    usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EPGETSTATUS), 0);
+                    privep = lpc313x_epfindbyaddr(priv, index);
+                    if (!privep)
+  		      {
+                        usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADEPGETSTATUS), 0);
+                        priv->stalled = true;
+                      }
+                    else
+                      {
+  		        if (lpc313x_epstalled(privep))
+			  priv->ep0buf[0] = 1; /* Stalled */
+			else
+                          priv->ep0buf[0] = 0; /* Not stalled */
+                        priv->ep0buf[1] = 0;
+  
+                        lpc313x_ep0xfer (LPC313X_EP0_IN, priv->ep0buf, 2);
+                        lpc313x_ep0state (priv, EP0STATE_SHORTWRITE);
+                      }
+                    }
+                  break;
+  
+                case USB_REQ_RECIPIENT_DEVICE:
+                  {
+  		    if (index == 0)
+                      {
+                        usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_DEVGETSTATUS), 0);
+  
+                        /* Features:  Remote Wakeup=YES; selfpowered=? */
+  
+                        priv->ep0buf[0] = (priv->selfpowered << USB_FEATURE_SELFPOWERED) |
+  			                (1 << USB_FEATURE_REMOTEWAKEUP);
+                        priv->ep0buf[1] = 0;
+
+			lpc313x_ep0xfer(LPC313X_EP0_IN, priv->ep0buf, 2);
+                        lpc313x_ep0state (priv, EP0STATE_SHORTWRITE);
+                      }
+                    else
+                      {
+                        usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADDEVGETSTATUS), 0);
+                        priv->stalled = true;
+                      }
+                  }
+                  break;
+  
+                case USB_REQ_RECIPIENT_INTERFACE:
+                  {
+                    usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_IFGETSTATUS), 0);
+                    priv->ep0buf[0] = 0;
+                    priv->ep0buf[1] = 0;
+
+                    lpc313x_ep0xfer(LPC313X_EP0_IN, priv->ep0buf, 2);
+		    lpc313x_ep0state (priv, EP0STATE_SHORTWRITE);
+                  }
+                  break;
+  
+                default:
+                  {
+                    usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADGETSTATUS), 0);
+                    priv->stalled = true;
+                  }
+                  break;
+                }
+            }
+        }
+        break;
+  
+      case USB_REQ_CLEARFEATURE:
+        {
+          /* type:  host-to-device; recipient = device, interface or endpoint
+           * value: feature selector
+           * index: zero interface endpoint;
+           * len:   zero, data = none
+           */
+  
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_CLEARFEATURE), 0);
+          if ((ctrl.type & USB_REQ_RECIPIENT_MASK) != USB_REQ_RECIPIENT_ENDPOINT)
+            {
+              lpc313x_dispatchrequest(priv, &ctrl);
+            }
+          else if (priv->paddrset != 0 && value == USB_FEATURE_ENDPOINTHALT && len == 0 &&
+                   (privep = lpc313x_epfindbyaddr(priv, index)) != NULL)
+            {
+              privep->halted = 0;
+  	    
+              lpc313x_epstall(&privep->ep, true);
+  
+              lpc313x_ep0state (priv, EP0STATE_WAIT_NAK_IN);
+            }
+          else
+            {
+              usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADCLEARFEATURE), 0);
+              priv->stalled = true;
+            }
+        }
+        break;
+  
+      case USB_REQ_SETFEATURE:
+        {
+          /* type:  host-to-device; recipient = device, interface, endpoint
+           * value: feature selector
+           * index: zero interface endpoint;
+           * len:   0; data = none
+           */
+  
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_SETFEATURE), 0);
+          if (((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE) &&
+              value == USB_FEATURE_TESTMODE)
+            {
+              ullvdbg("test mode: %d\n", index);
+            }
+          else if ((ctrl.type & USB_REQ_RECIPIENT_MASK) != USB_REQ_RECIPIENT_ENDPOINT)
+            {
+             lpc313x_dispatchrequest(priv, &ctrl);
+            }
+          else if (priv->paddrset != 0 && value == USB_FEATURE_ENDPOINTHALT && len == 0 &&
+                   (privep = lpc313x_epfindbyaddr(priv, index)) != NULL)
+            {
+              privep->halted = 1;
+  
+	      lpc313x_epstall(&privep->ep, false);
+  
+              lpc313x_ep0state (priv, EP0STATE_WAIT_NAK_IN);
+            }
+          else
+            {
+              usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADSETFEATURE), 0);
+              priv->stalled = true;
+            }
+        }
+        break;
+  
+      case USB_REQ_SETADDRESS:
+        {
+          /* type:  host-to-device; recipient = device
+           * value: device address
+           * index: 0
+           * len:   0; data = none
+           */
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EP0SETUPSETADDRESS), value);
+          if ((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
+              index  == 0 && len == 0 && value < 128)
+            {
+              /* Save the address.  We cannot actually change to the next address until
+               * the completion of the status phase. */
+  
+              priv->paddr = ctrl.value[0];
+	      priv->paddrset = false;
+  
+	      lpc313x_ep0state (priv, EP0STATE_WAIT_NAK_IN);
+            }
+          else
+            {
+              usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADSETADDRESS), 0);
+              priv->stalled = true;
+            }
+        }
+        break;
+  
+      case USB_REQ_GETDESCRIPTOR:
+        /* type:  device-to-host; recipient = device
+         * value: descriptor type and index
+         * index: 0 or language ID;
+         * len:   descriptor len; data = descriptor
+         */
+      case USB_REQ_SETDESCRIPTOR:
+        /* type:  host-to-device; recipient = device
+         * value: descriptor type and index
+         * index: 0 or language ID;
+         * len:   descriptor len; data = descriptor
+         */
+        {
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_GETSETDESC), 0);
+          if ((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE)
+            {
+              lpc313x_dispatchrequest(priv, &ctrl);
+            }
+          else
+            {
+              usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADGETSETDESC), 0);
+              priv->stalled = true;
+            }
+        }
+        break;
+  
+      case USB_REQ_GETCONFIGURATION:
+        /* type:  device-to-host; recipient = device
+         * value: 0;
+         * index: 0;
+         * len:   1; data = configuration value
+         */
+        {
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_GETCONFIG), 0);
+          if (priv->paddrset && (ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
+              value == 0 && index == 0 && len == 1)
+            {
+              lpc313x_dispatchrequest(priv, &ctrl);
+            }
+          else
+            {
+              usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADGETCONFIG), 0);
+              priv->stalled = true;
+            }
+        }
+        break;
+  
+      case USB_REQ_SETCONFIGURATION:
+        /* type:  host-to-device; recipient = device
+         * value: configuration value
+         * index: 0;
+         * len:   0; data = none
+         */
+        {
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_SETCONFIG), 0);
+          if ((ctrl.type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE &&
+              index == 0 && len == 0)
+            {
+              lpc313x_dispatchrequest(priv, &ctrl);
+            }
+          else
+            {
+              usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADSETCONFIG), 0);
+              priv->stalled = true;
+            }
+        }
+        break;
+  
+      case USB_REQ_GETINTERFACE:
+        /* type:  device-to-host; recipient = interface
+         * value: 0
+         * index: interface;
+         * len:   1; data = alt interface
+         */
+      case USB_REQ_SETINTERFACE:
+        /* type:  host-to-device; recipient = interface
+         * value: alternate setting
+         * index: interface;
+         * len:   0; data = none
+         */
+        {
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_GETSETIF), 0);
+          lpc313x_dispatchrequest(priv, &ctrl);
+        }
+        break;
+  
+      case USB_REQ_SYNCHFRAME:
+        /* type:  device-to-host; recipient = endpoint
+         * value: 0
+         * index: endpoint;
+         * len:   2; data = frame number
+         */
+        {
+          usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_SYNCHFRAME), 0);
+        }
+        break;
+  
+      default:
+        {
+          usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDCTRLREQ), 0);
+          priv->stalled = true;
+        }
+        break;
+      }
+  }
+
+  if (priv->stalled)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_EP0SETUPSTALLED), priv->ep0state);
+      lpc313x_epstall(&priv->eplist[LPC313X_EP0_IN].ep, false);
+      lpc313x_epstall(&priv->eplist[LPC313X_EP0_OUT].ep, false);
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_ep0complete
+ *
+ * Description:
+ *   Transfer complete handler for Endpoint 0
+ *
+ *******************************************************************************/
+
+static void lpc313x_ep0complete(struct lpc313x_usbdev_s *priv, uint8_t epphy)
+{
+  struct lpc313x_ep_s *privep = &priv->eplist[epphy];
+
+  usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EP0COMPLETE), (uint16_t)priv->ep0state);
+  
+  switch (priv->ep0state)
+    {
+    case EP0STATE_DATA_IN:
+      if (lpc313x_rqempty(privep))
+	return;
+
+      if (lpc313x_epcomplete (priv, epphy))
+	lpc313x_ep0state (priv, EP0STATE_WAIT_NAK_OUT);
+      break;
+
+    case EP0STATE_DATA_OUT:
+      if (lpc313x_rqempty(privep))
+	return;
+	
+      if (lpc313x_epcomplete (priv, epphy))
+	lpc313x_ep0state (priv, EP0STATE_WAIT_NAK_IN);
+      break;
+	
+    case EP0STATE_SHORTWRITE:
+      lpc313x_ep0state (priv, EP0STATE_WAIT_NAK_OUT);
+      break;
+	
+    case EP0STATE_WAIT_STATUS_IN:
+      lpc313x_ep0state (priv, EP0STATE_IDLE);
+
+      /* If we've received a SETADDRESS packet, then we set the address
+       * now that the status phase has completed */
+      if (! priv->paddrset && priv->paddr != 0)
+	{
+	  usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EP0INSETADDRESS), (uint16_t)priv->paddr);
+	  lpc313x_set_address (priv, priv->paddr);
+	}
+      break;
+
+    case EP0STATE_WAIT_STATUS_OUT:
+      lpc313x_ep0state (priv, EP0STATE_IDLE);
+      break;
+
+    default:
+#ifdef CONFIG_DEBUG
+      DEBUGASSERT(priv->ep0state != EP0STATE_DATA_IN        &&
+		  priv->ep0state != EP0STATE_DATA_OUT       &&
+		  priv->ep0state != EP0STATE_SHORTWRITE     &&
+		  priv->ep0state != EP0STATE_WAIT_STATUS_IN &&
+		  priv->ep0state != EP0STATE_WAIT_STATUS_OUT);
+#endif
+      priv->stalled = true;
+      break;
+    }
+
+  if (priv->stalled)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_EP0SETUPSTALLED), priv->ep0state);
+      lpc313x_epstall(&priv->eplist[LPC313X_EP0_IN].ep, false);
+      lpc313x_epstall(&priv->eplist[LPC313X_EP0_OUT].ep, false);
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_ep0nak
+ *
+ * Description:
+ *   Handle a NAK interrupt on EP0
+ *
+ *******************************************************************************/
+
+static void lpc313x_ep0nak(struct lpc313x_usbdev_s *priv, uint8_t epphy)
+{
+  usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EP0NAK), (uint16_t)priv->ep0state);
+
+  switch (priv->ep0state)
+    {
+    case EP0STATE_WAIT_NAK_IN:
+      lpc313x_ep0xfer (LPC313X_EP0_IN, NULL, 0);
+      lpc313x_ep0state (priv, EP0STATE_WAIT_STATUS_IN);
+      break;
+    case EP0STATE_WAIT_NAK_OUT:
+      lpc313x_ep0xfer (LPC313X_EP0_OUT, NULL, 0);
+      lpc313x_ep0state (priv, EP0STATE_WAIT_STATUS_OUT);
+      break;
+    default:
+#ifdef CONFIG_DEBUG
+      DEBUGASSERT(priv->ep0state != EP0STATE_WAIT_NAK_IN &&
+		  priv->ep0state != EP0STATE_WAIT_NAK_OUT);
+#endif
+      priv->stalled = true;
+      break;
+    }
+  if (priv->stalled)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_EP0SETUPSTALLED), priv->ep0state);
+      lpc313x_epstall(&priv->eplist[LPC313X_EP0_IN].ep, false);
+      lpc313x_epstall(&priv->eplist[LPC313X_EP0_OUT].ep, false);
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epcomplete
+ *
+ * Description:
+ *   Transfer complete handler for Endpoints other than 0
+ *   returns whether the request at the head has completed
+ *
+ *******************************************************************************/
+
+bool
+lpc313x_epcomplete(struct lpc313x_usbdev_s *priv, uint8_t epphy)
+{
+  struct lpc313x_ep_s  *privep  = &priv->eplist[epphy];
+  struct lpc313x_req_s *privreq = privep->head;
+  struct lpc313x_dtd_s *dtd     = &g_td[epphy];
+
+  if (privreq == NULL)		/* This shouldn't really happen */
+  {
+    if (LPC313X_EPPHYOUT(privep->epphy))
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EPINQEMPTY), 0);
+    else
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EPOUTQEMPTY), 0);
+    return true;
+  }
+    
+  int xfrd = dtd->xfer_len - (dtd->config >> 16);
+    
+  privreq->req.xfrd += xfrd;
+
+  bool complete;
+  if (LPC313X_EPPHYOUT(privep->epphy))
+    {
+      /* read(OUT) completes when request filled, or a short transfer is received */
+      complete = (privreq->req.xfrd >= privreq->req.len || xfrd < privep->ep.maxpacket);
+
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EPIN), complete);
+    }
+  else
+    {
+      // write(IN) completes when request finished, unless we need to terminate with a ZLP
+      bool need_zlp = xfrd == privep->ep.maxpacket && ((privreq->req.flags & USBDEV_REQFLAGS_NULLPKT) != 0);
+
+      complete = (privreq->req.xfrd >= privreq->req.len && !need_zlp);
+
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EPOUT), complete);
+    }
+
+  if (complete)
+    {
+      usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd);
+      lpc313x_reqcomplete(privep, OK);
+    }
+    
+  /* If there's more requests, then progress them */
+  if (!lpc313x_rqempty(privep))
+    lpc313x_progressep(privep);
+
+  return complete;
+}
+
+
+/*******************************************************************************
+ * Name: lpc313x_usbinterrupt
+ *
+ * Description:
+ *   USB interrupt handler
+ *
+ *******************************************************************************/
+
+static int lpc313x_usbinterrupt(int irq, FAR void *context)
+{
+  struct lpc313x_usbdev_s *priv = &g_usbdev;
+  uint32_t disr, portsc1, n;
+
+  usbtrace(TRACE_INTENTRY(LPC313X_TRACEINTID_USB), 0);
+
+  /* Read the interrupts and then clear them */
+  disr = lpc313x_getreg(LPC313X_USBDEV_USBSTS);
+  lpc313x_putreg(disr, LPC313X_USBDEV_USBSTS);
+
+  if (disr & USBDEV_USBSTS_URI)
+    {
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_DEVRESET),0);
+
+      lpc313x_usbreset(priv);
+
+      usbtrace(TRACE_INTEXIT(LPC313X_TRACEINTID_USB), 0);
+      return OK;
+  }
+  
+  if (disr & USBDEV_USBSTS_SLI)
+    {
+      // FIXME: what do we need to do here...
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_SUSPENDCHG),0);
+    }
+
+  if (disr & USBDEV_USBSTS_PCI)
+    {
+      portsc1 = lpc313x_getreg(LPC313X_USBDEV_PORTSC1);
+
+      if (portsc1 & USBDEV_PRTSC1_HSP)
+	priv->usbdev.speed = USB_SPEED_HIGH;
+      else
+	priv->usbdev.speed = USB_SPEED_FULL;
+
+      if (portsc1 & USBDEV_PRTSC1_FPR)
+        {
+	  /* FIXME: this occurs because of a J-to-K transition detected
+	   *         while the port is in SUSPEND state - presumambly this 
+	   *         is where the host is resuming the device?
+	   *
+	   *  - but do we need to "ack" the interrupt
+	   */
+	}
+    }
+  
+#ifdef CONFIG_LPC313X_USBDEV_FRAME_INTERRUPT
+  if (disr & USBDEV_USBSTT_SRI)
+    {
+      usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_FRAME), 0);
+      
+      priv->sof = (int)lpc313x_getreg(LPC313X_USBDEV_FRINDEX_OFFSET); 
+    }
+#endif
+
+  if (disr & USBDEV_USBSTS_UEI)
+    {
+      /* FIXME: these occur when a transfer results in an error condition
+       *        it is set alongside USBINT if the DTD also had its IOC 
+       *        bit set. */
+    }
+  
+  if (disr & USBDEV_USBSTS_UI)
+    {
+      /* Handle completion interrupts */
+      uint32_t mask = lpc313x_getreg (LPC313X_USBDEV_ENDPTCOMPLETE);
+
+      if (mask)
+        {
+	  // Clear any NAK interrupt and completion interrupts
+	  lpc313x_putreg (mask, LPC313X_USBDEV_ENDPTNAK);
+	  lpc313x_putreg (mask, LPC313X_USBDEV_ENDPTCOMPLETE);
+	  
+	  if (mask & LPC313X_ENDPTMASK(0))
+	    lpc313x_ep0complete(priv, 0);
+	  if (mask & LPC313X_ENDPTMASK(1))
+	    lpc313x_ep0complete(priv, 1);
+	  
+	  for (n = 1; n < LPC313X_NLOGENDPOINTS; n++)
+	    {
+	      if (mask & LPC313X_ENDPTMASK((n<<1)))
+		lpc313x_epcomplete (priv, (n<<1));
+	      if (mask & LPC313X_ENDPTMASK((n<<1)+1))
+		lpc313x_epcomplete(priv, (n<<1)+1);
+	    }
+	}
+
+      /* Handle setup interrupts */
+      uint32_t setupstat = lpc313x_getreg(LPC313X_USBDEV_ENDPTSETUPSTAT);
+      if (setupstat)
+        {
+	  /* Clear the endpoint complete CTRL OUT and IN when a Setup is received */
+	  lpc313x_putreg (LPC313X_ENDPTMASK(LPC313X_EP0_IN) | LPC313X_ENDPTMASK(LPC313X_EP0_OUT), 
+			  LPC313X_USBDEV_ENDPTCOMPLETE);
+	  
+	  if (setupstat & LPC313X_ENDPTMASK(LPC313X_EP0_OUT))
+	  {
+	    usbtrace(TRACE_INTDECODE(LPC313X_TRACEINTID_EP0SETUP), setupstat);
+	    lpc313x_ep0setup(priv);
+	  }
+	}
+    }
+
+  if (disr & USBDEV_USBSTS_NAKI)
+    {
+      uint32_t pending = lpc313x_getreg(LPC313X_USBDEV_ENDPTNAK) & lpc313x_getreg(LPC313X_USBDEV_ENDPTNAKEN);
+      if (pending)
+        {
+	  /* We shouldn't see NAK interrupts except on Endpoint 0 */
+	  if (pending & LPC313X_ENDPTMASK(0))
+	      lpc313x_ep0nak(priv, 0);
+	  if (pending & LPC313X_ENDPTMASK(1))
+	      lpc313x_ep0nak(priv, 1);
+	}
+      
+      // clear the interrupts
+      lpc313x_putreg(pending, LPC313X_USBDEV_ENDPTNAK);
+    }
+  usbtrace(TRACE_INTEXIT(LPC313X_TRACEINTID_USB), 0);
+  return OK;
+}
+
+/*******************************************************************************
+ * Endpoint operations
+ *******************************************************************************/
+
+/*******************************************************************************
+ * Name: lpc313x_epconfigure
+ *
+ * Description:
+ *   Configure endpoint, making it usable
+ *
+ * Input Parameters:
+ *   ep   - the struct usbdev_ep_s instance obtained from allocep()
+ *   desc - A struct usb_epdesc_s instance describing the endpoint
+ *   last - true if this this last endpoint to be configured.  Some hardware
+ *          needs to take special action when all of the endpoints have been
+ *          configured.
+ *
+ *******************************************************************************/
+
+static int lpc313x_epconfigure(FAR struct usbdev_ep_s *ep,
+                               FAR const struct usb_epdesc_s *desc,
+                               bool last)
+{
+  FAR struct lpc313x_ep_s *privep = (FAR struct lpc313x_ep_s *)ep;
+
+  usbtrace(TRACE_EPCONFIGURE, privep->epphy);
+  DEBUGASSERT(desc->addr == ep->eplog);
+
+  // Initialise EP capabilities
+  
+  uint16_t maxsize = GETUINT16(desc->mxpacketsize);
+  if ((desc->attr & USB_EP_ATTR_XFERTYPE_MASK) == USB_EP_ATTR_XFER_ISOC)
+    {
+      g_qh[privep->epphy].capability = (DQH_CAPABILITY_MAX_PACKET(maxsize) |
+					DQH_CAPABILITY_IOS |
+					DQH_CAPABILITY_ZLT);
+    }
+  else
+    {
+      g_qh[privep->epphy].capability = (DQH_CAPABILITY_MAX_PACKET(maxsize) |
+					DQH_CAPABILITY_ZLT);
+    }
+
+  /* Setup Endpoint Control Register */
+
+  if (LPC313X_EPPHYIN(privep->epphy))
+    {
+      /* Reset the data toggles */
+      uint32_t cfg = USBDEV_ENDPTCTRL_TXR;
+
+      /* Set the endpoint type */
+      switch (desc->attr & USB_EP_ATTR_XFERTYPE_MASK)
+        {
+	case USB_EP_ATTR_XFER_CONTROL: cfg |= USBDEV_ENDPTCTRL_TXT_CTRL; break;
+	case USB_EP_ATTR_XFER_ISOC:    cfg |= USBDEV_ENDPTCTRL_TXT_ISOC; break;
+	case USB_EP_ATTR_XFER_BULK:    cfg |= USBDEV_ENDPTCTRL_TXT_BULK; break;
+	case USB_EP_ATTR_XFER_INT:     cfg |= USBDEV_ENDPTCTRL_TXT_INTR; break;
+	}
+      lpc313x_chgbits (0xFFFF0000, cfg, LPC313X_USBDEV_ENDPTCTRL(privep->epphy));
+    }
+  else
+    {
+      /* Reset the data toggles */
+      uint32_t cfg = USBDEV_ENDPTCTRL_RXR;
+
+      /* Set the endpoint type */
+      switch (desc->attr & USB_EP_ATTR_XFERTYPE_MASK)
+        {
+	case USB_EP_ATTR_XFER_CONTROL: cfg |= USBDEV_ENDPTCTRL_RXT_CTRL; break;
+	case USB_EP_ATTR_XFER_ISOC:    cfg |= USBDEV_ENDPTCTRL_RXT_ISOC; break;
+	case USB_EP_ATTR_XFER_BULK:    cfg |= USBDEV_ENDPTCTRL_RXT_BULK; break;
+	}
+      lpc313x_chgbits (0x0000FFFF, cfg, LPC313X_USBDEV_ENDPTCTRL(privep->epphy));
+    }
+
+  /* Enable the endpoint */
+  if (LPC313X_EPPHYIN(privep->epphy))
+    lpc313x_setbits (USBDEV_ENDPTCTRL_TXE, LPC313X_USBDEV_ENDPTCTRL(privep->epphy));
+  else
+    lpc313x_setbits (USBDEV_ENDPTCTRL_RXE, LPC313X_USBDEV_ENDPTCTRL(privep->epphy));
+  
+   return OK;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epdisable
+ *
+ * Description:
+ *   The endpoint will no longer be used
+ *
+ *******************************************************************************/
+
+static int lpc313x_epdisable(FAR struct usbdev_ep_s *ep)
+{
+  FAR struct lpc313x_ep_s *privep = (FAR struct lpc313x_ep_s *)ep;
+  irqstate_t flags;
+
+#ifdef CONFIG_DEBUG
+  if (!ep)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      return -EINVAL;
+    }
+#endif
+  usbtrace(TRACE_EPDISABLE, privep->epphy);
+
+  flags = irqsave();
+
+  /* Disable Endpoint */
+  if (LPC313X_EPPHYIN(privep->epphy))
+    lpc313x_clrbits (USBDEV_ENDPTCTRL_TXE, LPC313X_USBDEV_ENDPTCTRL(privep->epphy));
+  else
+    lpc313x_clrbits (USBDEV_ENDPTCTRL_RXE, LPC313X_USBDEV_ENDPTCTRL(privep->epphy));
+
+  /* Cancel any ongoing activity */
+  lpc313x_cancelrequests(privep, -ESHUTDOWN);
+
+  privep->halted = 1;
+
+  irqrestore(flags);
+  return OK;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epallocreq
+ *
+ * Description:
+ *   Allocate an I/O request
+ *
+ *******************************************************************************/
+
+static FAR struct usbdev_req_s *lpc313x_epallocreq(FAR struct usbdev_ep_s *ep)
+{
+  FAR struct lpc313x_req_s *privreq;
+
+#ifdef CONFIG_DEBUG
+  if (!ep)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      return NULL;
+    }
+#endif
+  usbtrace(TRACE_EPALLOCREQ, ((FAR struct lpc313x_ep_s *)ep)->epphy);
+
+  privreq = (FAR struct lpc313x_req_s *)malloc(sizeof(struct lpc313x_req_s));
+  if (!privreq)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_ALLOCFAIL), 0);
+      return NULL;
+    }
+
+  memset(privreq, 0, sizeof(struct lpc313x_req_s));
+
+  return &privreq->req;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epfreereq
+ *
+ * Description:
+ *   Free an I/O request
+ *
+ *******************************************************************************/
+
+static void lpc313x_epfreereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
+{
+  FAR struct lpc313x_req_s *privreq = (FAR struct lpc313x_req_s *)req;
+
+#ifdef CONFIG_DEBUG
+  if (!ep || !req)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      return;
+    }
+#endif
+
+  usbtrace(TRACE_EPFREEREQ, ((FAR struct lpc313x_ep_s *)ep)->epphy);
+
+  free(privreq);
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epallocbuffer
+ *
+ * Description:
+ *   Allocate an I/O buffer
+ *
+ *******************************************************************************/
+
+#ifdef CONFIG_ARCH_USBDEV_DMA
+static void *lpc313x_epallocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes)
+{
+  usbtrace(TRACE_EPALLOCBUFFER, privep->epphy);
+  return malloc(bytes)
+}
+#endif
+
+/*******************************************************************************
+ * Name: lpc313x_epfreebuffer
+ *
+ * Description:
+ *   Free an I/O buffer
+ *
+ *******************************************************************************/
+
+#ifdef CONFIG_LPC313x_USBDEV_DMA
+static void lpc313x_epfreebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf)
+{
+  usbtrace(TRACE_EPFREEBUFFER, privep->epphy);
+  free(buf);
+}
+#endif
+
+/*******************************************************************************
+ * Name: lpc313x_epsubmit
+ *
+ * Description:
+ *   Submit an I/O request to the endpoint
+ *
+ *******************************************************************************/
+
+static int lpc313x_epsubmit(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
+{
+  FAR struct lpc313x_req_s *privreq = (FAR struct lpc313x_req_s *)req;
+  FAR struct lpc313x_ep_s *privep = (FAR struct lpc313x_ep_s *)ep;
+  FAR struct lpc313x_usbdev_s *priv;
+  irqstate_t flags;
+  int ret = OK;
+
+#ifdef CONFIG_DEBUG
+  if (!req || !req->callback || !req->buf || !ep)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      ullvdbg("req=%p callback=%p buf=%p ep=%p\n", req, req->callback, req->buf, ep);
+      return -EINVAL;
+    }
+#endif
+
+  usbtrace(TRACE_EPSUBMIT, privep->epphy);
+  priv = privep->dev;
+
+  if (!priv->driver || priv->usbdev.speed == USB_SPEED_UNKNOWN)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_NOTCONFIGURED), priv->usbdev.speed);
+      return -ESHUTDOWN;
+    }
+
+  /* Handle the request from the class driver */
+
+  req->result = -EINPROGRESS;
+  req->xfrd   = 0;
+
+  /* Disable Interrupts */
+
+  flags = irqsave();
+
+  /* If we are stalled, then drop all requests on the floor */
+
+  if (privep->stalled)
+    {
+      lpc313x_abortrequest(privep, privreq, -EBUSY);
+      ret = -EBUSY;
+    }
+
+  /* Handle IN (device-to-host) requests */
+
+  else 
+    {
+      /* Add the new request to the request queue for the endpoint */
+
+      if (LPC313X_EPPHYIN(privep->epphy))
+	usbtrace(TRACE_INREQQUEUED(privep->epphy), privreq->req.len);
+      else
+	  usbtrace(TRACE_OUTREQQUEUED(privep->epphy), privreq->req.len);
+
+      if (lpc313x_rqenqueue(privep, privreq))
+	lpc313x_progressep(privep);
+    }
+
+  irqrestore(flags);
+  return ret;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epcancel
+ *
+ * Description:
+ *   Cancel an I/O request previously sent to an endpoint
+ *
+ *******************************************************************************/
+
+static int lpc313x_epcancel(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req)
+{
+  FAR struct lpc313x_ep_s *privep = (FAR struct lpc313x_ep_s *)ep;
+  FAR struct lpc313x_usbdev_s *priv;
+  irqstate_t flags;
+
+#ifdef CONFIG_DEBUG
+  if (!ep || !req)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      return -EINVAL;
+    }
+#endif
+
+  usbtrace(TRACE_EPCANCEL, privep->epphy);
+  priv = privep->dev;
+
+  flags = irqsave();
+  
+  /* FIXME: if the request is the first, then we need to flush the EP
+   *         otherwise just remove it from the list
+   *
+   *  but ... all other implementations cancel all requests ...
+   */
+
+  lpc313x_cancelrequests(privep, -ESHUTDOWN);
+  irqrestore(flags);
+  return OK;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_epstall
+ *
+ * Description:
+ *   Stall or resume and endpoint
+ *
+ *******************************************************************************/
+
+static int lpc313x_epstall(FAR struct usbdev_ep_s *ep, bool resume)
+{
+  FAR struct lpc313x_ep_s *privep = (FAR struct lpc313x_ep_s *)ep;
+  irqstate_t flags;
+
+  /* STALL or RESUME the endpoint */
+
+  flags = irqsave();
+  usbtrace(resume ? TRACE_EPRESUME : TRACE_EPSTALL, privep->epphy);
+
+  uint32_t addr = LPC313X_USBDEV_ENDPTCTRL(privep->epphy);
+  uint32_t mask = LPC313X_EPPHYIN(privep->epphy) ? USBDEV_ENDPTCTRL_TXS : USBDEV_ENDPTCTRL_RXS;
+
+  if (resume)
+    {
+      privep->stalled = false;
+
+      lpc313x_clrbits (mask, addr);
+
+      /* FIXME: do we need to restart any queued write requests? */
+    }
+  else
+    {
+      privep->stalled = true;
+
+      lpc313x_setbits (mask, addr);
+    }
+
+  irqrestore(flags);
+  return OK;
+}
+
+/*******************************************************************************
+ * Device operations
+ *******************************************************************************/
+
+/*******************************************************************************
+ * Name: lcp313x_allocep
+ *
+ * Description:
+ *   Allocate an endpoint matching the parameters.
+ *
+ * Input Parameters:
+ *   eplog  - 7-bit logical endpoint number (direction bit ignored).  Zero means
+ *            that any endpoint matching the other requirements will suffice.  The
+ *            assigned endpoint can be found in the eplog field.
+ *   in     - true: IN (device-to-host) endpoint requested
+ *   eptype - Endpoint type.  One of {USB_EP_ATTR_XFER_ISOC, USB_EP_ATTR_XFER_BULK,
+ *            USB_EP_ATTR_XFER_INT}
+ *
+ *******************************************************************************/
+
+static FAR struct usbdev_ep_s *lcp313x_allocep(FAR struct usbdev_s *dev, uint8_t eplog,
+                                               bool in, uint8_t eptype)
+{
+  FAR struct lpc313x_usbdev_s *priv = (FAR struct lpc313x_usbdev_s *)dev;
+  uint32_t epset = LPC313X_EPALLSET & ~LPC313X_EPCTRLSET;
+  irqstate_t flags;
+  int epndx = 0;
+
+  usbtrace(TRACE_DEVALLOCEP, (uint16_t)eplog);
+
+  /* Ignore any direction bits in the logical address */
+
+  eplog = USB_EPNO(eplog);
+
+  /* A logical address of 0 means that any endpoint will do */
+
+  if (eplog > 0)
+    {
+      /* Otherwise, we will return the endpoint structure only for the requested
+       * 'logical' endpoint.  All of the other checks will still be performed.
+       *
+       * First, verify that the logical endpoint is in the range supported by
+       * by the hardware.
+       */
+
+      if (eplog >= LPC313X_NLOGENDPOINTS)
+        {
+          usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADEPNO), (uint16_t)eplog);
+          return NULL;
+        }
+
+      /* Convert the logical address to a physical OUT endpoint address and
+       * remove all of the candidate endpoints from the bitset except for the
+       * the IN/OUT pair for this logical address.
+       */
+
+      epset &= 3 << (eplog << 1);
+    }
+
+  /* Get the subset matching the requested direction */
+
+  if (in)
+    {
+      epset &= LPC313X_EPINSET;
+    }
+  else
+    {
+      epset &= LPC313X_EPOUTSET;
+    }
+
+  /* Get the subset matching the requested type */
+
+  switch (eptype)
+    {
+    case USB_EP_ATTR_XFER_INT: /* Interrupt endpoint */
+      epset &= LPC313X_EPINTRSET;
+      break;
+
+    case USB_EP_ATTR_XFER_BULK: /* Bulk endpoint */
+      epset &= LPC313X_EPBULKSET;
+      break;
+
+    case USB_EP_ATTR_XFER_ISOC: /* Isochronous endpoint */
+      epset &= LPC313X_EPISOCSET;
+      break;
+
+    case USB_EP_ATTR_XFER_CONTROL: /* Control endpoint -- not a valid choice */
+    default:
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BADEPTYPE), (uint16_t)eptype);
+      return NULL;
+    }
+
+  /* Is the resulting endpoint supported by the LPC313x? */
+
+  if (epset)
+    {
+      /* Yes.. now see if any of the request endpoints are available */
+
+      flags = irqsave();
+      epset &= priv->epavail;
+      if (epset)
+        {
+          /* Select the lowest bit in the set of matching, available endpoints */
+
+          for (epndx = 2; epndx < LPC313X_NPHYSENDPOINTS; epndx++)
+            {
+              uint32_t bit = 1 << epndx;
+              if ((epset & bit) != 0)
+                {
+                  /* Mark the IN/OUT endpoint no longer available */
+
+                  priv->epavail &= ~(3 << (bit & ~1));
+                  irqrestore(flags);
+
+                  /* And return the pointer to the standard endpoint structure */
+
+                  return &priv->eplist[epndx].ep;
+                }
+            }
+          /* Shouldn't get here */
+        }
+      irqrestore(flags);
+    }
+
+  usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_NOEP), (uint16_t)eplog);
+  return NULL;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_freeep
+ *
+ * Description:
+ *   Free the previously allocated endpoint
+ *
+ *******************************************************************************/
+
+static void lpc313x_freeep(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep)
+{
+  FAR struct lpc313x_usbdev_s *priv = (FAR struct lpc313x_usbdev_s *)dev;
+  FAR struct lpc313x_ep_s *privep = (FAR struct lpc313x_ep_s *)ep;
+  irqstate_t flags;
+
+  usbtrace(TRACE_DEVFREEEP, (uint16_t)privep->epphy);
+
+  if (priv && privep)
+    {
+      /* Mark the endpoint as available */
+
+      flags = irqsave();
+      priv->epavail |= (1 << privep->epphy);
+      irqrestore(flags);
+    }
+}
+
+/*******************************************************************************
+ * Name: lpc313x_getframe
+ *
+ * Description:
+ *   Returns the current frame number
+ *
+ *******************************************************************************/
+
+static int lpc313x_getframe(struct usbdev_s *dev)
+{
+#ifdef CONFIG_LPC313X_USBDEV_FRAME_INTERRUPT
+  FAR struct lpc313x_usbdev_s *priv = (FAR struct lpc313x_usbdev_s *)dev;
+
+  /* Return last valid value of SOF read by the interrupt handler */
+
+  usbtrace(TRACE_DEVGETFRAME, (uint16_t)priv->sof);
+  return priv->sof;
+#else
+  /* Return the last frame number detected by the hardware */
+
+  usbtrace(TRACE_DEVGETFRAME, 0);
+
+  /* FIXME: this actually returns the micro frame number! */
+  return (int)lpc313x_getreg(LPC313X_USBDEV_FRINDEX_OFFSET);
+#endif
+}
+
+/*******************************************************************************
+ * Name: lpc313x_wakeup
+ *
+ * Description:
+ *   Tries to wake up the host connected to this device
+ *
+ *******************************************************************************/
+
+static int lpc313x_wakeup(struct usbdev_s *dev)
+{
+  irqstate_t flags;
+
+  usbtrace(TRACE_DEVWAKEUP, 0);
+
+  flags = irqsave();
+  lpc313x_setbits(USBDEV_PRTSC1_FPR, LPC313X_USBDEV_PORTSC1);
+  irqrestore(flags);
+  return OK;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_selfpowered
+ *
+ * Description:
+ *   Sets/clears the device selfpowered feature 
+ *
+ *******************************************************************************/
+
+static int lpc313x_selfpowered(struct usbdev_s *dev, bool selfpowered)
+{
+  FAR struct lpc313x_usbdev_s *priv = (FAR struct lpc313x_usbdev_s *)dev;
+
+  usbtrace(TRACE_DEVSELFPOWERED, (uint16_t)selfpowered);
+
+#ifdef CONFIG_DEBUG
+  if (!dev)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      return -ENODEV;
+    }
+#endif
+
+  priv->selfpowered = selfpowered;
+  return OK;
+}
+
+/*******************************************************************************
+ * Name: lpc313x_pullup
+ *
+ * Description:
+ *   Software-controlled connect to/disconnect from USB host
+ *
+ *******************************************************************************/
+
+static int lpc313x_pullup(struct usbdev_s *dev, bool enable)
+{
+  usbtrace(TRACE_DEVPULLUP, (uint16_t)enable);
+
+  irqstate_t flags = irqsave();
+  if (enable)
+    lpc313x_setbits (USBDEV_USBCMD_RS, LPC313X_USBDEV_USBCMD);
+  else
+    lpc313x_clrbits (USBDEV_USBCMD_RS, LPC313X_USBDEV_USBCMD);
+  irqrestore(flags);
+  return OK;
+}
+
+/*******************************************************************************
+ * Public Functions
+ *******************************************************************************/
+
+/*******************************************************************************
+ * Name: up_usbinitialize
+ *
+ * Description:
+ *   Initialize USB hardware.
+ *
+ * Assumptions:
+ * - This function is called very early in the initialization sequence
+ * - PLL and GIO pin initialization is not performed here but should been in
+ *   the low-level  boot logic:  PLL1 must be configured for operation at 48MHz
+ *   and P0.23 and PO.31 in PINSEL1 must be configured for Vbus and USB connect
+ *   LED.
+ *
+ *******************************************************************************/
+
+void up_usbinitialize(void)
+{
+  struct lpc313x_usbdev_s *priv = &g_usbdev;
+  int i;
+
+  usbtrace(TRACE_DEVINIT, 0);
+
+  /* Disable USB interrupts */
+  
+  lpc313x_putreg(0, LPC313X_USBDEV_USBINTR);
+
+  /* Initialize the device state structure */
+
+  memset(priv, 0, sizeof(struct lpc313x_usbdev_s));
+  priv->usbdev.ops = &g_devops;
+  priv->usbdev.ep0 = &priv->eplist[LPC313X_EP0_IN].ep;
+  priv->epavail    = LPC313X_EPALLSET;
+
+  /* Initialize the endpoint list */
+
+  for (i = 0; i < LPC313X_NPHYSENDPOINTS; i++)
+    {
+      uint32_t bit = 1 << i;
+
+      /* Set endpoint operations, reference to driver structure (not
+       * really necessary because there is only one controller), and
+       * the physical endpoint number (which is just the index to the
+       * endpoint).
+       */
+      priv->eplist[i].ep.ops       = &g_epops;
+      priv->eplist[i].dev          = priv;
+
+      /* The index, i, is the physical endpoint address;  Map this
+       * to a logical endpoint address usable by the class driver.
+       */
+
+      priv->eplist[i].epphy        = i;
+      if (LPC313X_EPPHYIN(i))
+        {
+          priv->eplist[i].ep.eplog = LPC313X_EPPHYIN2LOG(i);
+        }
+      else
+        {
+          priv->eplist[i].ep.eplog = LPC313X_EPPHYOUT2LOG(i);
+        }
+
+      /* The maximum packet size may depend on the type of endpoint */
+
+      if ((LPC313X_EPCTRLSET & bit) != 0)
+        {
+          priv->eplist[i].ep.maxpacket = LPC313X_EP0MAXPACKET;
+        }
+      else if ((LPC313X_EPINTRSET & bit) != 0)
+        {
+          priv->eplist[i].ep.maxpacket = LPC313X_INTRMAXPACKET;
+        }
+      else if ((LPC313X_EPBULKSET & bit) != 0)
+        {
+          priv->eplist[i].ep.maxpacket = LPC313X_BULKMAXPACKET;
+        }
+      else /* if ((LPC313X_EPISOCSET & bit) != 0) */
+        {
+          priv->eplist[i].ep.maxpacket = LPC313X_ISOCMAXPACKET;
+        }
+    }
+
+  /* Enable USB to AHB clock and to Event router*/
+
+  lpc313x_enableclock (CLKID_USBOTGAHBCLK);
+  lpc313x_enableclock (CLKID_EVENTROUTERPCLK);
+
+  /* Reset USB block */
+
+  lpc313x_softreset (RESETID_USBOTGAHBRST);
+
+  /* Enable USB OTG PLL and wait for lock */
+
+  lpc313x_putreg (0, LPC313X_SYSCREG_USB_ATXPLLPDREG);
+  
+  uint32_t bank = EVNTRTR_BANK(EVENTRTR_USBATXPLLLOCK);
+  uint32_t bit  = EVNTRTR_BIT(EVENTRTR_USBATXPLLLOCK);
+
+  while (! (lpc313x_getreg(LPC313X_EVNTRTR_RSR(bank)) & (1 << bit)))
+    ;
+
+  /* Enable USB AHB clock */
+
+  lpc313x_enableclock (CLKID_USBOTGAHBCLK);
+
+  /* Reset the controller */
+
+  lpc313x_putreg (USBDEV_USBCMD_RST, LPC313X_USBDEV_USBCMD);
+  while (lpc313x_getreg (LPC313X_USBDEV_USBCMD) & USBDEV_USBCMD_RST)
+      ;
+
+  /* Attach USB controller interrupt handler */
+
+  if (irq_attach(LPC313X_IRQ_USBOTG, lpc313x_usbinterrupt) != 0)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_IRQREGISTRATION),
+               (uint16_t)LPC313X_IRQ_USBOTG);
+      goto errout;
+    }
+
+
+  /* Program the controller to be the USB device controller */
+
+  lpc313x_putreg (USBDEV_USBMODE_SDIS | USBDEV_USBMODE_SLOM | USBDEV_USBMODE_CMDEVICE,
+		  LPC313X_USBDEV_USBMODE);
+
+  /* Disconnect device */
+
+  lpc313x_pullup(&priv->usbdev, false);
+
+  /* Reset/Re-initialize the USB hardware */
+
+  lpc313x_usbreset(priv);
+
+  return;
+
+errout:
+  up_usbuninitialize();
+}
+
+/*******************************************************************************
+ * Name: up_usbuninitialize
+ *******************************************************************************/
+
+void up_usbuninitialize(void)
+{
+  struct lpc313x_usbdev_s *priv = &g_usbdev;
+  irqstate_t flags;
+
+  usbtrace(TRACE_DEVUNINIT, 0);
+
+  if (priv->driver)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_DRIVERREGISTERED), 0);
+      usbdev_unregister(priv->driver);
+    }
+
+  /* Disconnect device */
+
+  flags = irqsave();
+  lpc313x_pullup(&priv->usbdev, false);
+  priv->usbdev.speed = USB_SPEED_UNKNOWN;
+
+  /* Disable and detach IRQs */
+
+  up_disable_irq(LPC313X_IRQ_USBOTG);
+  irq_detach(LPC313X_IRQ_USBOTG);
+
+  /* Reset the controller */
+
+  lpc313x_putreg (USBDEV_USBCMD_RST, LPC313X_USBDEV_USBCMD);
+  while (lpc313x_getreg (LPC313X_USBDEV_USBCMD) & USBDEV_USBCMD_RST)
+      ;
+
+  /* Turn off USB power and clocking */
+
+  lpc313x_disableclock (CLKID_USBOTGAHBCLK);
+  lpc313x_disableclock (CLKID_EVENTROUTERPCLK);
+
+
+  irqrestore(flags);
+}
+
+/*******************************************************************************
+ * Name: usbdev_register
+ *
+ * Description:
+ *   Register a USB device class driver. The class driver's bind() method will be
+ *   called to bind it to a USB device driver.
+ *
+ *******************************************************************************/
+
+int usbdev_register(struct usbdevclass_driver_s *driver)
+{
+  int ret;
+
+  usbtrace(TRACE_DEVREGISTER, 0);
+
+#ifdef CONFIG_DEBUG
+  if (!driver || !driver->ops->bind || !driver->ops->unbind ||
+      !driver->ops->disconnect || !driver->ops->setup)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      return -EINVAL;
+    }
+
+  if (g_usbdev.driver)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_DRIVER), 0);
+      return -EBUSY;
+    }
+#endif
+
+  /* First hook up the driver */
+
+  g_usbdev.driver = driver;
+
+  /* Then bind the class driver */
+
+  ret = CLASS_BIND(driver, &g_usbdev.usbdev);
+  if (ret)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_BINDFAILED), (uint16_t)-ret);
+      g_usbdev.driver = NULL;
+    }
+  else
+    {
+      /* Enable USB controller interrupts */
+
+      up_enable_irq(LPC313X_IRQ_USBOTG);
+
+      /* FIXME: nothing seems to call DEV_CONNECT(), but we need to set
+       *        the RS bit to enable the controller.  It kind of makes sense 
+       *        to do this after the class has bound to us... */
+
+      lpc313x_pullup(&g_usbdev.usbdev, true);
+    }
+  return ret;
+}
+
+/*******************************************************************************
+ * Name: usbdev_unregister
+ *
+ * Description:
+ *   Un-register usbdev class driver.If the USB device is connected to a USB host,
+ *   it will first disconnect().  The driver is also requested to unbind() and clean
+ *   up any device state, before this procedure finally returns.
+ *
+ *******************************************************************************/
+
+int usbdev_unregister(struct usbdevclass_driver_s *driver)
+{
+  usbtrace(TRACE_DEVUNREGISTER, 0);
+
+#ifdef CONFIG_DEBUG
+  if (driver != g_usbdev.driver)
+    {
+      usbtrace(TRACE_DEVERROR(LPC313X_TRACEERR_INVALIDPARMS), 0);
+      return -EINVAL;
+    }
+#endif
+
+  /* Unbind the class driver */
+
+  CLASS_UNBIND(driver, &g_usbdev.usbdev);
+
+  /* Disable USB controller interrupts */
+
+  up_disable_irq(LPC313X_IRQ_USBOTG);
+
+  /* Unhook the driver */
+
+  g_usbdev.driver = NULL;
+  return OK;
+}
diff --git a/configs/ea3131/src/up_usbstrg.c b/configs/ea3131/src/up_usbstrg.c
new file mode 100755
index 0000000000000000000000000000000000000000..5aef28733220a35a462625a4f13f9b5e515b2f0c
--- /dev/null
+++ b/configs/ea3131/src/up_usbstrg.c
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * configs/ea3131/src/up_usbstrg.c
+ *
+ *   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 <stdlib.h>
+
+#include <nuttx/fs.h>
+#include <nuttx/mkfatfs.h>
+#include <nuttx/ramdisk.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+
+#ifndef CONFIG_EXAMPLES_USBSTRG_DEVMINOR1
+#  define CONFIG_EXAMPLES_USBSTRG_DEVMINOR1 0
+#endif
+
+#ifndef CONFIG_EXAMPLES_USBSTRG_DEVPATH1
+#  define CONFIG_EXAMPLES_USBSTRG_DEVPATH1  "/dev/ram"
+#endif
+
+static const char g_source[] = CONFIG_EXAMPLES_USBSTRG_DEVPATH1;
+static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
+
+#define USBSTRG_NSECTORS        64
+#define USBSTRG_SECTORSIZE      512
+#define BUFFER_SIZE             (USBSTRG_NSECTORS*USBSTRG_SECTORSIZE)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: usbstrg_archinitialize
+ *
+ * Description:
+ *   Perform architecture specific initialization
+ *
+ ****************************************************************************/
+
+int usbstrg_archinitialize(void)
+{
+  uint8_t *pbuffer;
+  int ret;
+
+  pbuffer = (uint8_t *) malloc (BUFFER_SIZE);
+  if (!pbuffer)
+    {
+      lib_lowprintf ("usbstrg_archinitialize: Failed to allocate ramdisk of size %d\n",
+                     BUFFER_SIZE);
+      return -ENOMEM;
+    }
+
+  /* Register a RAMDISK device to manage this RAM image */
+  
+  ret = ramdisk_register(CONFIG_EXAMPLES_USBSTRG_DEVMINOR1,
+                         pbuffer,
+                         USBSTRG_NSECTORS,
+                         USBSTRG_SECTORSIZE,
+                         true);
+  if (ret < 0)
+    {
+      printf("create_ramdisk: Failed to register ramdisk at %s: %d\n",
+             g_source, -ret);
+      free(pbuffer);
+      return ret;
+    }
+
+  /* Create a FAT filesystem on the ramdisk */
+
+  ret = mkfatfs(g_source, &g_fmt);
+  if (ret < 0)
+    {
+      printf("create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n",
+             g_source);
+      /* free(pbuffer); -- RAM disk is registered */
+      return ret;
+    }
+
+  return 0;
+}
diff --git a/configs/ea3131/usbserial/Make.defs b/configs/ea3131/usbserial/Make.defs
new file mode 100755
index 0000000000000000000000000000000000000000..96dd769ee1a71b746a4631c66e127e10608de5f4
--- /dev/null
+++ b/configs/ea3131/usbserial/Make.defs
@@ -0,0 +1,170 @@
+############################################################################
+# configs/ea3131/usbserial/Make.defs
+#
+#   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+
+include ${TOPDIR}/.config
+
+# Setup for the selected toolchain
+
+ifeq ($(CONFIG_LPC313X_CODESOURCERYW),y)
+  # CodeSourcery under Windows
+  CROSSDEV = arm-none-eabi-
+  WINTOOL = y
+  MAXOPTIMIZATION = -O2
+endif
+ifeq ($(CONFIG_LPC313X_CODESOURCERYL),y)
+  # CodeSourcery under Linux
+  CROSSDEV = arm-none-eabi-
+  MAXOPTIMIZATION = -O2
+endif
+ifeq ($(CONFIG_LPC313X_DEVKITARM),y)
+  # devkitARM under Windows
+  CROSSDEV = arm-eabi-
+  WINTOOL = y
+endif
+ifeq ($(CONFIG_LPC313X_RAISONANCE),y)
+  # Raisonance RIDE7 under Windows
+  CROSSDEV = arm-none-eabi-
+  WINTOOL = y
+  MAXOPTIMIZATION = -O2
+endif
+ifeq ($(CONFIG_LPC313X_BUILDROOT),y)
+  # NuttX buildroot under Linux or Cygwin
+  CROSSDEV = arm-elf-
+  MAXOPTIMIZATION = -Os
+endif
+
+ifeq ($(WINTOOL),y)
+  # Windows-native toolchains
+  DIRLINK = $(TOPDIR)/tools/winlink.sh
+  DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+  MKDEP = $(TOPDIR)/tools/mknulldeps.sh
+  ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}"
+  ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}"
+  ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/usbserial/ld.script}"
+else
+  # Linux/Cygwin-native toolchain 
+  MKDEP = $(TOPDIR)/tools/mkdeps.sh
+  ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
+  ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx
+  ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/usbserial/ld.script
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+AR = $(CROSSDEV)ar rcs
+NM = $(CROSSDEV)nm
+OBJCOPY = $(CROSSDEV)objcopy
+OBJDUMP = $(CROSSDEV)objdump
+
+ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'}
+ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1}
+
+ifeq ("${CONFIG_DEBUG_SYMBOLS}","y")
+  ARCHOPTIMIZATION = -g
+else
+  ARCHOPTIMIZATION = $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
+endif
+
+ifeq ($(ARCHCCMAJOR),4)
+  ARCHCPUFLAGS = -mtune=arm9tdmi -march=armv5te -mfloat-abi=soft -fno-builtin
+else
+  ARCHCPUFLAGS = -mapcs-32 -mtune=arm9tdmi -march=armv5te -msoft-float -fno-builtin
+endif
+
+ARCHCFLAGS = -fno-builtin
+ARCHCXXFLAGS = -fno-builtin -fno-exceptions
+ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
+ARCHWARNINGSXX = -Wall -Wshadow
+ARCHDEFINES =
+ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
+
+CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) -pipe
+CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
+CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) -pipe
+CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
+CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES)
+AFLAGS = $(CFLAGS) -D__ASSEMBLY__
+
+NXFLATLDFLAGS1 = -r -d -warn-common
+NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat.ld -no-check-sections
+LDNXFLATFLAGS = -e main -s 2048
+
+OBJEXT = .o
+LIBEXT = .a
+EXEEXT =
+
+ifneq ($(CONFIG_LPC313X_BUILDROOT),y)
+  LDFLAGS += -nostartfiles -nodefaultlibs
+endif
+ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
+  LDFLAGS += -g
+endif
+
+define PREPROCESS
+	@echo "CPP: $1->$2"
+	@$(CPP) $(CPPFLAGS) $1 -o $2
+endef
+
+define COMPILE
+	@echo "CC: $1"
+	@$(CC) -c $(CFLAGS) $1 -o $2
+endef
+
+define COMPILEXX
+	@echo "CXX: $1"
+	@$(CXX) -c $(CXXFLAGS) $1 -o $2
+endef
+
+define ASSEMBLE
+	@echo "AS: $1"
+	@$(CC) -c $(AFLAGS) $1 -o $2
+endef
+
+define ARCHIVE
+	echo "AR: $2"; \
+	$(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; }
+endef
+
+define CLEAN
+	@rm -f *.o *.a
+endef
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -g -pipe
+HOSTLDFLAGS =
+
diff --git a/configs/ea3131/usbserial/defconfig b/configs/ea3131/usbserial/defconfig
new file mode 100755
index 0000000000000000000000000000000000000000..6ef507ba7051ba11f0a18ebd0100cbefd1ace9f1
--- /dev/null
+++ b/configs/ea3131/usbserial/defconfig
@@ -0,0 +1,824 @@
+############################################################################
+# configs/ea3131/usbserial/defconfig
+#
+#   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+#
+# architecture selection
+#
+# CONFIG_ARCH - identifies the arch subdirectory and, hence, the
+#   processor architecture.
+# CONFIG_ARCH_family - for use in C code.  This identifies the
+#   particular chip family that the architecture is implemented
+#   in.
+# CONFIG_ARCH_architecture - for use in C code.  This identifies the
+#   specific architecture within the chip familyl.
+# CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory
+# CONFIG_ARCH_CHIP_name - For use in C code
+# CONFIG_ARCH_BOARD - identifies the configs subdirectory and, hence,
+#   the board that supports the particular chip or SoC.
+# CONFIG_ARCH_BOARD_name - for use in C code
+# CONFIG_ENDIAN_BIG - define if big endian (default is little endian)
+# CONFIG_BOARD_LOOPSPERMSEC - for delay loops
+# CONFIG_DRAM_SIZE - For most ARM9 architectures, this describes the
+#   size of installed DRAM.  For the LPC313X, it is used only to
+#   deterimine how to map the executable regions.  It is SDRAM size
+#   only if you are executing out of the external SDRAM; or it could
+#   be NOR FLASH size, external SRAM size, or internal SRAM size.
+# CONFIG_DRAM_START - The start address of DRAM (physical)
+# CONFIG_DRAM_VSTART - The startaddress of DRAM (virtual)
+# CONFIG_ARCH_IRQPRIO - The LPC313x supports interrupt prioritization
+# CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt
+#   stack. If defined, this symbol is the size of the interrupt
+#   stack in bytes.  If not defined, the user task stacks will be
+#   used during interrupt handling.
+# CONFIG_ARCH_STACKDUMP - Do stack dumps after assertions
+# CONFIG_ARCH_BOOTLOADER - Set if you are using a bootloader.
+# CONFIG_ARCH_LEDS -  Use LEDs to show state. Unique to board architecture.
+# CONFIG_ARCH_BUTTONS -  Enable support for buttons. Unique to board architecture.
+# CONFIG_ARCH_CALIBRATION - Enables some build in instrumentation that
+#   cause a 100 second delay during boot-up.  This 100 second delay
+#   serves no purpose other than it allows you to calibrate
+#   CONFIG_BOARD_LOOPSPERMSEC.  You simply use a stop watch to measure
+#   the 100 second delay then adjust CONFIG_BOARD_LOOPSPERMSEC until
+#   the delay actually is 100 seconds.
+# CONFIG_ARCH_DMA - Support DMA initialization
+#
+CONFIG_ARCH=arm
+CONFIG_ARCH_ARM=y
+CONFIG_ARCH_ARM926EJS=y
+CONFIG_ARCH_CHIP=lpc313x
+CONFIG_ARCH_CHIP_LPC3131=y
+CONFIG_ARCH_BOARD=ea3131
+CONFIG_ARCH_BOARD_EA3131=y
+CONFIG_BOARD_LOOPSPERMSEC=16945
+CONFIG_DRAM_SIZE=0x00030000
+CONFIG_DRAM_START=0x11028000
+CONFIG_DRAM_VSTART=0x11028000
+CONFIG_ARCH_IRQPRIO=y
+CONFIG_ARCH_INTERRUPTSTACK=n
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_BOOTLOADER=n
+CONFIG_ARCH_LEDS=y
+CONFIG_ARCH_BUTTONS=n
+CONFIG_ARCH_CALIBRATION=n
+CONFIG_ARCH_DMA=n
+
+#
+# ARM-specific configuration
+#
+# CONFIG_ARCH_LOWVECTORS - define if vectors reside at address 0x0000:00000
+#   Undefine if vectors reside at address 0xffff:0000
+# CONFIG_ARCH_ROMPGTABLE - A pre-initialized, read-only page table is available.
+#   If defined, then board-specific logic must also define PGTABLE_BASE_PADDR,
+#   PGTABLE_BASE_VADDR, and all memory section mapping in a file named
+#   board_memorymap.h.
+#
+CONFIG_ARCH_LOWVECTORS=y
+CONFIG_ARCH_ROMPGTABLE=y
+
+# Identify toolchain and linker options
+#
+CONFIG_LPC313X_CODESOURCERYW=n
+CONFIG_LPC313X_CODESOURCERYL=y
+CONFIG_LPC313X_DEVKITARM=n
+CONFIG_LPC313X_BUILDROOT=n
+
+#
+#  Individual subsystems can be enabled:
+#
+CONFIG_LPC313X_MCI=n
+CONFIG_LPC313X_SPI=n
+CONFIG_LPC313X_UART=y
+
+#
+# Exernal memory available on the board (see also CONFIG_MM_REGIONS)
+#
+# CONFIG_LPC313X_EXTSRAM0 - Select if external SRAM0 is present
+# CONFIG_LPC313X_EXTSRAM0HEAP - Select if external SRAM0 should be
+#   configured as part of the NuttX heap.
+# CONFIG_LPC313X_EXTSRAM0SIZE - Size (in bytes) of the installed
+#   external SRAM0 memory
+# CONFIG_LPC313X_EXTSRAM1 - Select if external SRAM1 is present
+# CONFIG_LPC313X_EXTSRAM1HEAP - Select if external SRAM1 should be
+#   configured as part of the NuttX heap.
+# CONFIG_LPC313X_EXTSRAM1SIZE - Size (in bytes) of the installed
+#   external SRAM1 memory
+# CONFIG_LPC313X_EXTSDRAM - Select if external SDRAM is present
+# CONFIG_LPC313X_EXTSDRAMHEAP - Select if external SDRAM should be
+#   configured as part of the NuttX heap.
+# CONFIG_LPC313X_EXTSDRAMSIZE - Size (in bytes) of the installed
+#   external SDRAM memory
+# CONFIG_LPC313X_EXTNAND - Select if external NAND is present
+# CONFIG_LPC313X_EXTSDRAMSIZE - Size (in bytes) of the installed
+#   external NAND memory
+#
+CONFIG_LPC313X_EXTSRAM0=n
+CONFIG_LPC313X_EXTSRAM0HEAP=n
+CONFIG_LPC313X_EXTSRAM0SIZE=(128*1024)
+CONFIG_LPC313X_EXTSRAM1=n
+CONFIG_LPC313X_EXTSRAM1HEAP=n
+CONFIG_LPC313X_EXTSRAM1SIZE=(128*1024)
+CONFIG_LPC313X_EXTSDRAM=n
+CONFIG_LPC313X_EXTSDRAMHEAP=n
+CONFIG_LPC313X_EXTSDRAMSIZE=(64*1024*1024)
+CONFIG_LPC313X_EXTNAND=n
+CONFIG_LPC313X_EXTNANDSIZE=(64*1024*1024)
+
+#
+# LPC313X specific device driver settings
+#
+# CONFIG_UART_SERIAL_CONSOLE - selects the UART for the
+#   console and ttys0
+# CONFIG_UART_RXBUFSIZE - Characters are buffered as received.
+#   This specific the size of the receive buffer
+# CONFIG_UART_TXBUFSIZE - Characters are buffered before
+#   being sent.  This specific the size of the transmit buffer
+# CONFIG_UART_BAUD - The configure BAUD of the UART.  Must be
+# CONFIG_UART_BITS - The number of bits.  Must be either 7 or 8.
+# CONFIG_UART_PARTIY - 0=no parity, 1=odd parity, 2=even parity
+# CONFIG_UART_2STOP - Two stop bits
+#
+CONFIG_UART_SERIAL_CONSOLE=y
+CONFIG_UART_TXBUFSIZE=256
+CONFIG_UART_RXBUFSIZE=256
+CONFIG_UART_BAUD=115200
+CONFIG_UART_BITS=8
+CONFIG_UART_PARITY=0
+CONFIG_UART_2STOP=0
+
+#
+# General build options
+#
+# CONFIG_RRLOAD_BINARY - make the rrload binary format used with
+#   BSPs from www.ridgerun.com using the tools/mkimage.sh script
+# CONFIG_INTELHEX_BINARY - make the Intel HEX binary format
+#   used with many different loaders using the GNU objcopy program
+#   Should not be selected if you are not using the GNU toolchain.
+# CONFIG_MOTOROLA_SREC - make the Motorola S-Record binary format
+#   used with many different loaders using the GNU objcopy program
+#   Should not be selected if you are not using the GNU toolchain.
+# CONFIG_RAW_BINARY - make a raw binary format file used with many
+#   different loaders using the GNU objcopy program.  This option
+#   should not be selected if you are not using the GNU toolchain.
+# CONFIG_HAVE_LIBM - toolchain supports libm.a
+#
+CONFIG_RRLOAD_BINARY=n
+CONFIG_INTELHEX_BINARY=n
+CONFIG_MOTOROLA_SREC=n
+CONFIG_RAW_BINARY=y
+CONFIG_HAVE_LIBM=n
+
+#
+# General OS setup
+#
+# CONFIG_EXAMPLE - identifies the subdirectory in examples
+#   that will be used in the build
+# CONFIG_DEBUG - enables built-in debug options
+# CONFIG_DEBUG_VERBOSE - enables verbose debug output
+# CONFIG_DEBUG_SYMBOLS - build without optimization and with
+#   debug symbols (needed for use with a debugger).
+# CONFIG_MM_REGIONS - If the architecture includes multiple
+#   regions of memory to allocate from, this specifies the
+#   number of memory regions that the memory manager must
+#   handle and enables the API mm_addregion(start, end);
+# CONFIG_ARCH_LOWPUTC - architecture supports low-level, boot
+#   time console output
+# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz
+#   or TICKS_PER_MSEC=10.  This setting may be defined to
+#   inform NuttX that the processor hardware is providing
+#   system timer interrupts at some interrupt interval other
+#   than 10 msec.
+# CONFIG_RR_INTERVAL - The round robin timeslice will be set
+#   this number of milliseconds;  Round robin scheduling can
+#   be disabled by setting this value to zero.
+# CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in 
+#   scheduler to monitor system performance
+# CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
+#   task name to save in the TCB.  Useful if scheduler
+#   instrumentation is selected.  Set to zero to disable.
+# CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
+#   Used to initialize the internal time logic.
+# CONFIG_GREGORIAN_TIME - Enables Gregorian time conversions.
+#   You would only need this if you are concerned about accurate
+#   time conversions in the past or in the distant future.
+# CONFIG_JULIAN_TIME - Enables Julian time conversions. You
+#   would only need this if you are concerned about accurate
+#   time conversion in the distand past.  You must also define
+#   CONFIG_GREGORIAN_TIME in order to use Julian time.
+# CONFIG_DEV_CONSOLE - Set if architecture-specific logic
+#   provides /dev/console.  Enables stdout, stderr, stdin.
+# CONFIG_DEV_LOWCONSOLE - Use the simple, low-level serial console
+#   driver (minimul support)
+# CONFIG_MUTEX_TYPES: Set to enable support for recursive and
+#   errorcheck mutexes. Enables pthread_mutexattr_settype().
+# CONFIG_PRIORITY_INHERITANCE : Set to enable support for priority
+#   inheritance on mutexes and semaphores. 
+# CONFIG_SEM_PREALLOCHOLDERS: This setting is only used if priority
+#   inheritance is enabled.  It defines the maximum number of
+#   different threads (minus one) that can take counts on a
+#   semaphore with priority inheritance support.  This may be 
+#   set to zero if priority inheritance is disabled OR if you
+#   are only using semaphores as mutexes (only one holder) OR
+#   if no more than two threads participate using a counting
+#   semaphore.
+# CONFIG_SEM_NNESTPRIO.  If priority inheritance is enabled,
+#   then this setting is the maximum number of higher priority
+#   threads (minus 1) than can be waiting for another thread
+#   to release a count on a semaphore.  This value may be set
+#   to zero if no more than one thread is expected to wait for
+#   a semaphore.
+# CONFIG_FDCLONE_DISABLE. Disable cloning of all file descriptors
+#   by task_create() when a new task is started.  If set, all
+#   files/drivers will appear to be closed in the new task.
+# CONFIG_FDCLONE_STDIO. Disable cloning of all but the first
+#   three file descriptors (stdin, stdout, stderr) by task_create()
+#   when a new task is started. If set, all files/drivers will
+#   appear to be closed in the new task except for stdin, stdout,
+#   and stderr.
+# CONFIG_SDCLONE_DISABLE. Disable cloning of all socket
+#   desciptors by task_create() when a new task is started. If
+#   set, all sockets will appear to be closed in the new task.
+# CONFIG_NXFLAT. Enable support for the NXFLAT binary format.
+#  This format will support execution of NuttX binaries located
+#  in a ROMFS filesystem (see examples/nxflat).
+# CONFIG_SCHED_WORKQUEUE.  Create a dedicated "worker" thread to
+#  handle delayed processing from interrupt handlers.  This feature
+#  is required for some drivers but, if there are not complaints,
+#  can be safely disabled.  The worker thread also performs
+#  garbage collection -- completing any delayed memory deallocations
+#  from interrupt handlers.  If the worker thread is disabled,
+#  then that clean will be performed by the IDLE thread instead
+#  (which runs at the lowest of priority and may not be appropriate
+#  if memory reclamation is of high priority).  If CONFIG_SCHED_WORKQUEUE
+#  is enabled, then the following options can also be used:
+# CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker
+#  thread.  Default: 50
+# CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for
+#  work in units of microseconds.  Default: 50*1000 (50 MS).
+# CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker
+#  thread.  Default: CONFIG_IDLETHREAD_STACKSIZE.
+# CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
+#  the worker thread.  Default: 4
+#
+CONFIG_EXAMPLE=usbserial
+CONFIG_DEBUG=n
+CONFIG_DEBUG_VERBOSE=n
+CONFIG_DEBUG_FS=n
+CONFIG_DEBUG_USB=n
+CONFIG_DEBUG_SYMBOLS=n
+CONFIG_MM_REGIONS=1
+CONFIG_ARCH_LOWPUTC=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_INSTRUMENTATION=n
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_START_YEAR=2010
+CONFIG_START_MONTH=3
+CONFIG_START_DAY=28
+CONFIG_GREGORIAN_TIME=n
+CONFIG_JULIAN_TIME=n
+CONFIG_DEV_CONSOLE=y
+CONFIG_DEV_LOWCONSOLE=y
+CONFIG_MUTEX_TYPES=n
+CONFIG_PRIORITY_INHERITANCE=n
+CONFIG_SEM_PREALLOCHOLDERS=0
+CONFIG_SEM_NNESTPRIO=0
+CONFIG_FDCLONE_DISABLE=n
+CONFIG_FDCLONE_STDIO=n
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NXFLAT=n
+CONFIG_SCHED_WORKQUEUE=y
+CONFIG_SCHED_WORKPRIORITY=50
+CONFIG_SCHED_WORKPERIOD=(50*1000)
+CONFIG_SCHED_WORKSTACKSIZE=1024
+CONFIG_SIG_SIGWORK=4
+
+#
+# The following can be used to disable categories of
+# APIs supported by the OS.  If the compiler supports
+# weak functions, then it should not be necessary to
+# disable functions unless you want to restrict usage
+# of those APIs.
+#
+# There are certain dependency relationships in these
+# features.
+#
+# o mq_notify logic depends on signals to awaken tasks
+#   waiting for queues to become full or empty.
+# o pthread_condtimedwait() depends on signals to wake
+#   up waiting tasks.
+#
+CONFIG_DISABLE_CLOCK=n
+CONFIG_DISABLE_POSIX_TIMERS=n
+CONFIG_DISABLE_PTHREAD=n
+CONFIG_DISABLE_SIGNALS=n
+CONFIG_DISABLE_MQUEUE=n
+CONFIG_DISABLE_MOUNTPOINT=n
+CONFIG_DISABLE_ENVIRON=y
+CONFIG_DISABLE_POLL=y
+
+#
+# Misc libc settings
+#
+# CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a
+#   little smaller if we do not support fieldwidthes
+#
+CONFIG_NOPRINTF_FIELDWIDTH=n
+
+#
+# Allow for architecture optimized implementations
+#
+# The architecture can provide optimized versions of the
+# following to improve system performance
+#
+CONFIG_ARCH_MEMCPY=n
+CONFIG_ARCH_MEMCMP=n
+CONFIG_ARCH_MEMMOVE=n
+CONFIG_ARCH_MEMSET=n
+CONFIG_ARCH_STRCMP=n
+CONFIG_ARCH_STRCPY=n
+CONFIG_ARCH_STRNCPY=n
+CONFIG_ARCH_STRLEN=n
+CONFIG_ARCH_BZERO=n
+CONFIG_ARCH_KMALLOC=n
+CONFIG_ARCH_KZMALLOC=n
+CONFIG_ARCH_KFREE=n
+
+#
+# Sizes of configurable things (0 disables)
+#
+# CONFIG_MAX_TASKS - The maximum number of simultaneously
+#   active tasks.  This value must be a power of two.
+# CONFIG_MAX_TASK_ARGS - This controls the maximum number of
+#   of parameters that a task may receive (i.e., maxmum value
+#   of 'argc')
+# CONFIG_NPTHREAD_KEYS - The number of items of thread-
+#   specific data that can be retained
+# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
+#   descriptors (one for each open)
+# CONFIG_NFILE_STREAMS - The maximum number of streams that
+#   can be fopen'ed
+# CONFIG_NAME_MAX - The maximum size of a file name.
+# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
+#   on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_NUNGET_CHARS - Number of characters that can be
+#   buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
+#   structures.  The system manages a pool of preallocated
+#   message structures to minimize dynamic allocations
+# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
+#   a fixed payload size given by this settin (does not include
+#   other message structure overhead.
+# CONFIG_MAX_WDOGPARMS - Maximum number of parameters that
+#   can be passed to a watchdog handler
+# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
+#   structures.  The system manages a pool of preallocated
+#   watchdog structures to minimize dynamic allocations
+# CONFIG_PREALLOC_TIMERS - The number of pre-allocated POSIX
+#   timer structures.  The system manages a pool of preallocated
+#   timer structures to minimize dynamic allocations.  Set to
+#   zero for all dynamic allocations.
+#
+CONFIG_MAX_TASKS=16
+CONFIG_MAX_TASK_ARGS=4
+CONFIG_NPTHREAD_KEYS=4
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+CONFIG_STDIO_BUFFER_SIZE=256
+CONFIG_NUNGET_CHARS=2
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=4
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Filesystem configuration
+#
+# CONFIG_FS_FAT - Enable FAT filesystem support
+# CONFIG_FAT_SECTORSIZE - Max supported sector size
+# CONFIG_FS_ROMFS - Enable ROMFS filesystem support
+CONFIG_FS_FAT=y
+CONFIG_FS_ROMFS=n
+CONFIG_FS_WRITABLE=y
+
+#
+# Block driver buffering
+#
+# CONFIG_FS_READAHEAD
+#   Enable read-ahead buffering
+# CONFIG_FS_WRITEBUFFER
+#   Enable write buffering
+#
+CONFIG_FS_READAHEAD=n
+CONFIG_FS_WRITEBUFFER=n
+
+#
+# SDIO-based MMC/SD driver
+#
+# CONFIG_SDIO_DMA
+#   SDIO driver supports DMA
+# CONFIG_MMCSD_MMCSUPPORT
+#   Enable support for MMC cards
+# CONFIG_MMCSD_HAVECARDDETECT
+#   SDIO driver card detection is 100% accurate
+#
+CONFIG_SDIO_DMA=n
+CONFIG_MMCSD_MMCSUPPORT=n
+CONFIG_MMCSD_HAVECARDDETECT=n
+
+#
+# TCP/IP and UDP support via uIP
+# CONFIG_NET - Enable or disable all network features
+# CONFIG_NET_IPv6 - Build in support for IPv6
+# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread.
+# CONFIG_NET_SOCKOPTS - Enable or disable support for socket options
+# CONFIG_NET_BUFSIZE - uIP buffer size
+# CONFIG_NET_TCP - TCP support on or off
+# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks)
+# CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers
+# CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero)
+# CONFIG_NET_TCPBACKLOG - Incoming connections pend in a backlog until
+#   accept() is called. The size of the backlog is selected when listen() is called.
+# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks)
+# CONFIG_NET_UDP - UDP support on or off
+# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off
+# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections
+# CONFIG_NET_ICMP - ICMP ping response support on or off
+# CONFIG_NET_ICMP_PING - ICMP ping request support on or off
+# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address
+# CONFIG_NET_STATISTICS - uIP statistics on or off
+# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window
+# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table
+# CONFIG_NET_BROADCAST - Broadcast support
+# CONFIG_NET_LLH_LEN - The link level header length
+# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates
+#
+CONFIG_NET=n
+CONFIG_NET_IPv6=n
+CONFIG_NSOCKET_DESCRIPTORS=0
+CONFIG_NET_SOCKOPTS=y
+CONFIG_NET_BUFSIZE=420
+CONFIG_NET_TCP=n
+CONFIG_NET_TCP_CONNS=40
+CONFIG_NET_MAX_LISTENPORTS=40
+CONFIG_NET_UDP=n
+CONFIG_NET_UDP_CHECKSUMS=y
+#CONFIG_NET_UDP_CONNS=10
+CONFIG_NET_ICMP=n
+CONFIG_NET_ICMP_PING=n
+#CONFIG_NET_PINGADDRCONF=0
+CONFIG_NET_STATISTICS=y
+#CONFIG_NET_RECEIVE_WINDOW=
+#CONFIG_NET_ARPTAB_SIZE=8
+CONFIG_NET_BROADCAST=n
+#CONFIG_NET_LLH_LEN=14
+#CONFIG_NET_FWCACHE_SIZE=2
+
+#
+# UIP Network Utilities
+# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP
+# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries
+#
+CONFIG_NET_DHCP_LIGHT=n
+CONFIG_NET_RESOLV_ENTRIES=4
+
+#
+# USB Device Configuration
+#
+# CONFIG_USBDEV
+#   Enables USB device support
+# CONFIG_USBDEV_ISOCHRONOUS
+#   Build in extra support for isochronous endpoints
+# CONFIG_USBDEV_DUALSPEED
+#   Hardware handles high and full speed operation (USB 2.0)
+# CONFIG_USBDEV_SELFPOWERED
+#   Will cause USB features to indicate that the device is
+#   self-powered
+# CONFIG_USBDEV_MAXPOWER
+#   Maximum power consumption in mA
+# CONFIG_USBDEV_TRACE
+#   Enables USB tracing for debug
+# CONFIG_USBDEV_TRACE_NRECORDS
+#   Number of trace entries to remember
+#
+CONFIG_USBDEV=y
+CONFIG_USBDEV_ISOCHRONOUS=n
+CONFIG_USBDEV_DUALSPEED=y
+CONFIG_USBDEV_SELFPOWERED=y
+CONFIG_USBDEV_REMOTEWAKEUP=n
+CONFIG_USBDEV_MAXPOWER=100
+CONFIG_USBDEV_TRACE=y
+CONFIG_USBDEV_TRACE_NRECORDS=128
+
+#
+# LPC313X USB Configuration
+#
+# CONFIG_LPC313X_GIO_USBATTACH
+#   GIO that detects USB attach/detach events
+# CONFIG_LPC313X_GIO_USBDPPULLUP
+#   GIO 
+# CONFIG_DMA320_USBDEV_DMA
+#   Enable LPC313X-specific DMA support
+#
+CONFIG_LPC313X_GIO_USBATTACH=6
+CONFIG_LPC313X_GIO_USBDPPULLUP=17
+CONFIG_LPC313X_VENDORID=0xd320
+CONFIG_LPC313X_PRODUCTID=0x3211
+CONFIG_LPC313X_USBDEV_DMA=n
+
+#
+# USB Serial Device Configuration
+#
+# CONFIG_USBSER
+#   Enable compilation of the USB serial driver
+# CONFIG_USBSER_EPINTIN
+#   The logical 7-bit address of a hardware endpoint that supports
+#   interrupt IN operation
+# CONFIG_USBSER_EPBULKOUT
+#   The logical 7-bit address of a hardware endpoint that supports
+#   bulk OUT operation
+# CONFIG_USBSER_EPBULKIN
+#   The logical 7-bit address of a hardware endpoint that supports
+#   bulk IN operation
+# CONFIG_USBSER_NWRREQS and CONFIG_USBSER_NRDREQS
+#   The number of write/read requests that can be in flight
+# CONFIG_USBSER_VENDORID and CONFIG_USBSER_VENDORSTR
+#   The vendor ID code/string
+# CONFIG_USBSER_PRODUCTID and CONFIG_USBSER_PRODUCTSTR
+#   The product ID code/string
+# CONFIG_USBSER_RXBUFSIZE and CONFIG_USBSER_TXBUFSIZE
+#   Size of the serial receive/transmit buffers
+#
+CONFIG_USBSER=y
+CONFIG_USBSER_EPINTIN=3
+CONFIG_USBSER_EPBULKOUT=2
+CONFIG_USBSER_EPBULKIN=1
+CONFIG_USBSER_NWRREQS=4
+CONFIG_USBSER_NRDREQS=4
+CONFIG_USBSER_VENDORID=0x067b
+CONFIG_USBSER_PRODUCTID=0x2303
+CONFIG_USBSER_VENDORSTR="Nuttx"
+CONFIG_USBSER_PRODUCTSTR="USBdev Serial"
+CONFIG_USBSER_RXBUFSIZE=512
+CONFIG_USBSER_TXBUFSIZE=512
+
+#
+# USB Storage Device Configuration
+#
+# CONFIG_USBSTRG
+#   Enable compilation of the USB storage driver
+# CONFIG_USBSTRG_EP0MAXPACKET
+#   Max packet size for endpoint 0
+# CONFIG_USBSTRG_EPBULKOUT and CONFIG_USBSTRG_EPBULKIN
+#   The logical 7-bit address of a hardware endpoints that support
+#   bulk OUT and IN operations
+# CONFIG_USBSTRG_NWRREQS and CONFIG_USBSTRG_NRDREQS
+#   The number of write/read requests that can be in flight
+# CONFIG_USBSTRG_BULKINREQLEN and CONFIG_USBSTRG_BULKOUTREQLEN
+#   The size of the buffer in each write/read request.  This
+#   value needs to be at least as large as the endpoint
+#   maxpacket and ideally as large as a block device sector.
+# CONFIG_USBSTRG_VENDORID and CONFIG_USBSTRG_VENDORSTR
+#   The vendor ID code/string
+# CONFIG_USBSTRG_PRODUCTID and CONFIG_USBSTRG_PRODUCTSTR
+#   The product ID code/string
+# CONFIG_USBSTRG_REMOVABLE
+#   Select if the media is removable
+#
+CONFIG_USBSTRG=n
+CONFIG_USBSTRG_EP0MAXPACKET=64
+CONFIG_USBSTRG_EPBULKOUT=2
+CONFIG_USBSTRG_EPBULKIN=1
+CONFIG_USBSTRG_NRDREQS=2
+CONFIG_USBSTRG_NWRREQS=2
+CONFIG_USBSTRG_BULKINREQLEN=512
+CONFIG_USBSTRG_BULKOUTREQLEN=512
+CONFIG_USBSTRG_VENDORID=0x584e
+CONFIG_USBSTRG_VENDORSTR="NuttX"
+CONFIG_USBSTRG_PRODUCTID=0x5342
+CONFIG_USBSTRG_PRODUCTSTR="USBdev Storage"
+CONFIG_USBSTRG_VERSIONNO=0x0399
+CONFIG_USBSTRG_REMOVABLE=y
+
+#
+# Settings for examples/uip
+#
+CONFIG_EXAMPLE_UIP_IPADDR=(10<<24|0<<16|0<<8|2)
+CONFIG_EXAMPLE_UIP_DRIPADDR=(10<<24|0<<16|0<<8|1)
+CONFIG_EXAMPLE_UIP_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLE_UIP_DHCPC=n
+
+#
+# Settings for examples/nettest
+#
+CONFIG_EXAMPLE_NETTEST_SERVER=n
+CONFIG_EXAMPLE_NETTEST_PERFORMANCE=n
+CONFIG_EXAMPLE_NETTEST_NOMAC=n
+CONFIG_EXAMPLE_NETTEST_IPADDR=(10<<24|0<<16|0<<8|2)
+CONFIG_EXAMPLE_NETTEST_DRIPADDR=(10<<24|0<<16|0<<8|1)
+CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
+
+#
+# Settings for examples/ostest
+#
+CONFIG_EXAMPLES_OSTEST_LOOPS=1
+CONFIG_EXAMPLES_OSTEST_STACKSIZE=2048
+CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=3
+
+#
+# Settings for examples/nsh
+#
+# CONFIG_EXAMPLES_NSH_FILEIOSIZE - Size of a static I/O buffer
+# CONFIG_EXAMPLES_NSH_STRERROR - Use strerror(errno)
+# CONFIG_EXAMPLES_NSH_LINELEN - Maximum length of one command line
+# CONFIG_EXAMPLES_NSH_STACKSIZE - Stack size to use for new threads.
+# CONFIG_EXAMPLES_NSH_NESTDEPTH - Max number of nested if-then[-else]-fi
+# CONFIG_EXAMPLES_NSH_DISABLESCRIPT - Disable scripting support
+# CONFIG_EXAMPLES_NSH_DISABLEBG - Disable background commands
+# CONFIG_EXAMPLES_NSH_ROMFSETC - Use startup script in /etc
+# CONFIG_EXAMPLES_NSH_CONSOLE - Use serial console front end
+# CONFIG_EXAMPLES_NSH_TELNET - Use telnetd console front end
+# CONFIG_EXAMPLES_NSH_ARCHINIT - Platform provides architecture
+#   specific initialization (nsh_archinitialize()).
+#
+# If CONFIG_EXAMPLES_NSH_TELNET is selected:
+# CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE -- Telnetd I/O buffer size
+# CONFIG_EXAMPLES_NSH_DHCPC - Obtain address using DHCP
+# CONFIG_EXAMPLES_NSH_IPADDR - Provides static IP address
+# CONFIG_EXAMPLES_NSH_DRIPADDR - Provides static router IP address
+# CONFIG_EXAMPLES_NSH_NETMASK - Provides static network mask
+# CONFIG_EXAMPLES_NSH_NOMAC - Use a bogus MAC address
+#
+# If CONFIG_EXAMPLES_NSH_ROMFSETC is selected:
+# CONFIG_EXAMPLES_NSH_ROMFSMOUNTPT - ROMFS mountpoint
+# CONFIG_EXAMPLES_NSH_INITSCRIPT - Relative path to init script
+# CONFIG_EXAMPLES_NSH_ROMFSDEVNO - ROMFS RAM device minor
+# CONFIG_EXAMPLES_NSH_ROMFSSECTSIZE - ROMF sector size
+# CONFIG_EXAMPLES_NSH_FATDEVNO - FAT FS RAM device minor
+# CONFIG_EXAMPLES_NSH_FATSECTSIZE - FAT FS sector size
+# CONFIG_EXAMPLES_NSH_FATNSECTORS - FAT FS number of sectors
+# CONFIG_EXAMPLES_NSH_FATMOUNTPT - FAT FS mountpoint
+#
+CONFIG_EXAMPLES_NSH_FILEIOSIZE=512
+CONFIG_EXAMPLES_NSH_STRERROR=n
+CONFIG_EXAMPLES_NSH_LINELEN=64
+CONFIG_EXAMPLES_NSH_STACKSIZE=2048
+CONFIG_EXAMPLES_NSH_NESTDEPTH=3
+CONFIG_EXAMPLES_NSH_DISABLESCRIPT=n
+CONFIG_EXAMPLES_NSH_DISABLEBG=n
+CONFIG_EXAMPLES_NSH_ROMFSETC=n
+CONFIG_EXAMPLES_NSH_CONSOLE=y
+CONFIG_EXAMPLES_NSH_TELNET=n
+CONFIG_EXAMPLES_NSH_ARCHINIT=y
+CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
+CONFIG_EXAMPLES_NSH_DHCPC=n
+CONFIG_EXAMPLES_NSH_NOMAC=n
+CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
+CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
+CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLES_NSH_ROMFSMOUNTPT="/etc"
+CONFIG_EXAMPLES_NSH_INITSCRIPT="init.d/rcS"
+CONFIG_EXAMPLES_NSH_ROMFSDEVNO=0
+CONFIG_EXAMPLES_NSH_ROMFSSECTSIZE=64
+CONFIG_EXAMPLES_NSH_FATDEVNO=1
+CONFIG_EXAMPLES_NSH_FATSECTSIZE=512
+CONFIG_EXAMPLES_NSH_FATNSECTORS=1024
+CONFIG_EXAMPLES_NSH_FATMOUNTPT=/tmp
+
+#
+# Architecture-specific NSH options
+#
+CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO=0
+CONFIG_EXAMPLES_NSH_MMCSDSLOTNO=0
+CONFIG_EXAMPLES_NSH_MMCSDMINOR=0
+
+#
+# Settings for examples/usbserial
+#
+# CONFIG_EXAMPLES_USBSERIAL_INONLY
+#    Only verify IN (device-to-host) data transfers.  Default: both
+# CONFIG_EXAMPLES_USBSERIAL_OUTONLY
+#    Only verify OUT (host-to-device) data transfers.  Default: both
+# CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL
+#    Send only small, single packet messages.  Default: Send large and small.
+# CONFIG_EXAMPLES_USBSERIAL_ONLYBIG
+#    Send only large, multi-packet messages.  Default: Send large and small.
+#
+CONFIG_EXAMPLES_USBSERIAL_INONLY=n
+CONFIG_EXAMPLES_USBSERIAL_OUTONLY=n
+CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL=n
+CONFIG_EXAMPLES_USBSERIAL_ONLYBIG=n
+
+CONFIG_EXAMPLES_USBSERIAL_TRACEINIT=n
+CONFIG_EXAMPLES_USBSERIAL_TRACECLASS=n
+CONFIG_EXAMPLES_USBSERIAL_TRACETRANSFERS=n
+CONFIG_EXAMPLES_USBSERIAL_TRACECONTROLLER=n
+CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS=n
+
+#
+# Settings for examples/usbstorage
+#
+# CONFIG_EXAMPLES_USBSTRG_NLUNS
+#    Defines the number of logical units (LUNs) exported by the USB storage
+#    driver.  Each LUN corresponds to one exported block driver (or partition
+#    of a block driver).  May be 1, 2, or 3.  Default is 1.
+# CONFIG_EXAMPLES_USBSTRG_DEVMINOR1
+#    The minor device number of the block driver for the first LUN. For
+#    example, N in /dev/mmcsdN.  Used for registering the block driver. Default
+#    is zero.
+# CONFIG_EXAMPLES_USBSTRG_DEVPATH1
+#    The full path to the registered block driver.  Default is "/dev/mmcsd0"
+#  CONFIG_EXAMPLES_USBSTRG_DEVMINOR2 and CONFIG_EXAMPLES_USBSTRG_DEVPATH2
+#    Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBSTRG_NLUNS
+#    is 2 or 3.  No defaults.
+#  CONFIG_EXAMPLES_USBSTRG_DEVMINOR3 and CONFIG_EXAMPLES_USBSTRG_DEVPATH3
+#    Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBSTRG_NLUNS
+#    is 3.  No defaults.
+#
+#  If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB), then
+#  the example code will also manage the USB trace output.  The amount of trace output
+#  can be controlled using:
+#
+#  CONFIG_EXAMPLES_USBSTRG_TRACEINIT
+#    Show initialization events
+#  CONFIG_EXAMPLES_USBSTRG_TRACECLASS
+#    Show class driver events
+#  CONFIG_EXAMPLES_USBSTRG_TRACETRANSFERS
+#    Show data transfer events
+#  CONFIG_EXAMPLES_USBSTRG_TRACECONTROLLER
+#    Show controller events
+#  CONFIG_EXAMPLES_USBSTRG_TRACEINTERRUPTS
+#    Show interrupt-related events.
+CONFIG_EXAMPLES_USBSTRG_NLUNS=1
+CONFIG_EXAMPLES_USBSTRG_DEVMINOR1=0
+CONFIG_EXAMPLES_USBSTRG_DEVPATH1="/dev/ram0"
+CONFIG_EXAMPLES_USBSTRG_TRACEINIT=n
+CONFIG_EXAMPLES_USBSTRG_TRACECLASS=n
+CONFIG_EXAMPLES_USBSTRG_TRACETRANSFERS=n
+CONFIG_EXAMPLES_USBSTRG_TRACECONTROLLER=n
+CONFIG_EXAMPLES_USBSTRG_TRACEINTERRUPTS=n
+
+#
+# Stack and heap information
+#
+# CONFIG_BOOT_RUNFROMFLASH - Some configurations support XIP
+#   operation from FLASH but must copy initialized .data sections to RAM.
+# CONFIG_BOOT_COPYTORAM -  Some configurations boot in FLASH
+#   but copy themselves entirely into RAM for better performance.
+# CONFIG_CUSTOM_STACK - The up_ implementation will handle
+#   all stack operations outside of the nuttx model.
+# CONFIG_STACK_POINTER - The initial stack pointer (arm7tdmi only)
+# CONFIG_IDLETHREAD_STACKSIZE - The size of the initial stack.
+#  This is the thread that (1) performs the inital boot of the system up
+#  to the point where user_start() is spawned, and (2) there after is the
+#  IDLE thread that executes only when there is no other thread ready to
+#  run.
+# CONFIG_USERMAIN_STACKSIZE - The size of the stack to allocate
+#  for the main user thread that begins at the user_start() entry point.
+# CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size
+# CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
+# CONFIG_HEAP_BASE - The beginning of the heap
+# CONFIG_HEAP_SIZE - The size of the heap
+#
+CONFIG_BOOT_RUNFROMFLASH=n
+CONFIG_BOOT_COPYTORAM=n
+CONFIG_CUSTOM_STACK=n
+CONFIG_STACK_POINTER=
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+CONFIG_HEAP_BASE=
+CONFIG_HEAP_SIZE=
diff --git a/configs/ea3131/usbserial/ld.script b/configs/ea3131/usbserial/ld.script
new file mode 100755
index 0000000000000000000000000000000000000000..7ce7bf21c1808c144105f88e04e265e9d098b577
--- /dev/null
+++ b/configs/ea3131/usbserial/ld.script
@@ -0,0 +1,107 @@
+/****************************************************************************
+ * configs/ea3131/usbserial/ld.script
+ *
+ *   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 LPC3131 has 192Kb of ISRAM beginning at virtual address 0x1102:8000.
+ * LPC313x boot ROM expects the boot image be compiled with entry point at
+ * 0x1102:9000.  A 128b header will appear at this address (applied by
+ * lpc313xImgCreator) and the executable code must begin at 0x1102:9080.
+ */
+
+MEMORY
+{
+    isram (rwx) : ORIGIN = 0x11029080, LENGTH = 192K - 4224
+}
+
+OUTPUT_ARCH(arm)
+ENTRY(_stext)
+SECTIONS
+{
+	.text : {
+		_stext = ABSOLUTE(.);
+		*(.vectors)
+		*(.text .text.*)        
+		*(.fixup)
+		*(.gnu.warning)
+		*(.rodata .rodata.*)        
+		*(.gnu.linkonce.t.*)
+		*(.glue_7)
+		*(.glue_7t)
+		*(.got)
+		*(.gcc_except_table)
+		*(.gnu.linkonce.r.*)
+		_etext = ABSOLUTE(.);
+	} > isram
+
+	_eronly = ABSOLUTE(.);
+
+	.data : {
+		_sdata = ABSOLUTE(.);
+		*(.data .data.*)
+		*(.gnu.linkonce.d.*)
+		CONSTRUCTORS
+		_edata = ABSOLUTE(.);
+	} > isram
+
+	.ARM.extab : {
+		*(.ARM.extab*)
+	} >isram
+
+	.ARM.exidx : {
+		__exidx_start = ABSOLUTE(.);
+		*(.ARM.exidx*)
+		__exidx_end = ABSOLUTE(.);
+	} > isram
+
+	.bss : {
+		_sbss = ABSOLUTE(.);
+		*(.bss .bss.*)
+		*(.gnu.linkonce.b.*)
+		*(COMMON)
+		_ebss = ABSOLUTE(.);
+	} > isram
+					/* Stabs debugging sections.	*/
+	.stab 0 : { *(.stab) }
+	.stabstr 0 : { *(.stabstr) }
+	.stab.excl 0 : { *(.stab.excl) }
+	.stab.exclstr 0 : { *(.stab.exclstr) }
+	.stab.index 0 : { *(.stab.index) }
+	.stab.indexstr 0 : { *(.stab.indexstr) }
+	.comment 0 : { *(.comment) }
+	.debug_abbrev 0 : { *(.debug_abbrev) }
+	.debug_info 0 : { *(.debug_info) }
+	.debug_line 0 : { *(.debug_line) }
+	.debug_pubnames 0 : { *(.debug_pubnames) }
+	.debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/configs/ea3131/usbserial/setenv.sh b/configs/ea3131/usbserial/setenv.sh
new file mode 100755
index 0000000000000000000000000000000000000000..3adbc484c7a3f9ed07f3c5c9d21229f85cc8070a
--- /dev/null
+++ b/configs/ea3131/usbserial/setenv.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# configs/ea3131/usbserial/setenv.sh
+#
+#   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+
+if [ "$(basename $0)" = "setenv.sh" ] ; then
+  echo "You must source this script, not run it!" 1>&2
+  exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then export PATH_ORIG=${PATH}; fi
+
+WD=`pwd`
+export BUILDROOT_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+export LPCTOOL_DIR="${WD}/configs/ea3131/tools"
+export PATH="${BUILDROOT_BIN}:${LPCTOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"
diff --git a/configs/ea3131/usbstorage/Make.defs b/configs/ea3131/usbstorage/Make.defs
new file mode 100755
index 0000000000000000000000000000000000000000..28f95d9565068946c155941cc90ab38a5ccbdbb4
--- /dev/null
+++ b/configs/ea3131/usbstorage/Make.defs
@@ -0,0 +1,170 @@
+############################################################################
+# configs/ea3131/usbstorage/Make.defs
+#
+#   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+
+include ${TOPDIR}/.config
+
+# Setup for the selected toolchain
+
+ifeq ($(CONFIG_LPC313X_CODESOURCERYW),y)
+  # CodeSourcery under Windows
+  CROSSDEV = arm-none-eabi-
+  WINTOOL = y
+  MAXOPTIMIZATION = -O2
+endif
+ifeq ($(CONFIG_LPC313X_CODESOURCERYL),y)
+  # CodeSourcery under Linux
+  CROSSDEV = arm-none-eabi-
+  MAXOPTIMIZATION = -O2
+endif
+ifeq ($(CONFIG_LPC313X_DEVKITARM),y)
+  # devkitARM under Windows
+  CROSSDEV = arm-eabi-
+  WINTOOL = y
+endif
+ifeq ($(CONFIG_LPC313X_RAISONANCE),y)
+  # Raisonance RIDE7 under Windows
+  CROSSDEV = arm-none-eabi-
+  WINTOOL = y
+  MAXOPTIMIZATION = -O2
+endif
+ifeq ($(CONFIG_LPC313X_BUILDROOT),y)
+  # NuttX buildroot under Linux or Cygwin
+  CROSSDEV = arm-elf-
+  MAXOPTIMIZATION = -Os
+endif
+
+ifeq ($(WINTOOL),y)
+  # Windows-native toolchains
+  DIRLINK = $(TOPDIR)/tools/winlink.sh
+  DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+  MKDEP = $(TOPDIR)/tools/mknulldeps.sh
+  ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}"
+  ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}"
+  ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/usbstorage/ld.script}"
+else
+  # Linux/Cygwin-native toolchain 
+  MKDEP = $(TOPDIR)/tools/mkdeps.sh
+  ARCHINCLUDES = -I. -isystem $(TOPDIR)/include
+  ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx
+  ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/usbstorage/ld.script
+endif
+
+CC = $(CROSSDEV)gcc
+CXX = $(CROSSDEV)g++
+CPP = $(CROSSDEV)gcc -E
+LD = $(CROSSDEV)ld
+AR = $(CROSSDEV)ar rcs
+NM = $(CROSSDEV)nm
+OBJCOPY = $(CROSSDEV)objcopy
+OBJDUMP = $(CROSSDEV)objdump
+
+ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'}
+ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1}
+
+ifeq ("${CONFIG_DEBUG_SYMBOLS}","y")
+  ARCHOPTIMIZATION = -g
+else
+  ARCHOPTIMIZATION = $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
+endif
+
+ifeq ($(ARCHCCMAJOR),4)
+  ARCHCPUFLAGS = -mtune=arm9tdmi -march=armv5te -mfloat-abi=soft -fno-builtin
+else
+  ARCHCPUFLAGS = -mapcs-32 -mtune=arm9tdmi -march=armv5te -msoft-float -fno-builtin
+endif
+
+ARCHCFLAGS = -fno-builtin
+ARCHCXXFLAGS = -fno-builtin -fno-exceptions
+ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
+ARCHWARNINGSXX = -Wall -Wshadow
+ARCHDEFINES =
+ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
+
+CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) -pipe
+CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
+CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) -pipe
+CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
+CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES)
+AFLAGS = $(CFLAGS) -D__ASSEMBLY__
+
+NXFLATLDFLAGS1 = -r -d -warn-common
+NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat.ld -no-check-sections
+LDNXFLATFLAGS = -e main -s 2048
+
+OBJEXT = .o
+LIBEXT = .a
+EXEEXT =
+
+ifneq ($(CONFIG_LPC313X_BUILDROOT),y)
+  LDFLAGS += -nostartfiles -nodefaultlibs
+endif
+ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
+  LDFLAGS += -g
+endif
+
+define PREPROCESS
+	@echo "CPP: $1->$2"
+	@$(CPP) $(CPPFLAGS) $1 -o $2
+endef
+
+define COMPILE
+	@echo "CC: $1"
+	@$(CC) -c $(CFLAGS) $1 -o $2
+endef
+
+define COMPILEXX
+	@echo "CXX: $1"
+	@$(CXX) -c $(CXXFLAGS) $1 -o $2
+endef
+
+define ASSEMBLE
+	@echo "AS: $1"
+	@$(CC) -c $(AFLAGS) $1 -o $2
+endef
+
+define ARCHIVE
+	echo "AR: $2"; \
+	$(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; }
+endef
+
+define CLEAN
+	@rm -f *.o *.a
+endef
+
+HOSTCC = gcc
+HOSTINCLUDES = -I.
+HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -g -pipe
+HOSTLDFLAGS =
+
diff --git a/configs/ea3131/usbstorage/defconfig b/configs/ea3131/usbstorage/defconfig
new file mode 100755
index 0000000000000000000000000000000000000000..7474122a4c3e5eb60507b7ab60725fad227add96
--- /dev/null
+++ b/configs/ea3131/usbstorage/defconfig
@@ -0,0 +1,824 @@
+############################################################################
+# configs/ea3131/usbstorage/defconfig
+#
+#   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+#
+# architecture selection
+#
+# CONFIG_ARCH - identifies the arch subdirectory and, hence, the
+#   processor architecture.
+# CONFIG_ARCH_family - for use in C code.  This identifies the
+#   particular chip family that the architecture is implemented
+#   in.
+# CONFIG_ARCH_architecture - for use in C code.  This identifies the
+#   specific architecture within the chip familyl.
+# CONFIG_ARCH_CHIP - Identifies the arch/*/chip subdirectory
+# CONFIG_ARCH_CHIP_name - For use in C code
+# CONFIG_ARCH_BOARD - identifies the configs subdirectory and, hence,
+#   the board that supports the particular chip or SoC.
+# CONFIG_ARCH_BOARD_name - for use in C code
+# CONFIG_ENDIAN_BIG - define if big endian (default is little endian)
+# CONFIG_BOARD_LOOPSPERMSEC - for delay loops
+# CONFIG_DRAM_SIZE - For most ARM9 architectures, this describes the
+#   size of installed DRAM.  For the LPC313X, it is used only to
+#   deterimine how to map the executable regions.  It is SDRAM size
+#   only if you are executing out of the external SDRAM; or it could
+#   be NOR FLASH size, external SRAM size, or internal SRAM size.
+# CONFIG_DRAM_START - The start address of DRAM (physical)
+# CONFIG_DRAM_VSTART - The startaddress of DRAM (virtual)
+# CONFIG_ARCH_IRQPRIO - The LPC313x supports interrupt prioritization
+# CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt
+#   stack. If defined, this symbol is the size of the interrupt
+#   stack in bytes.  If not defined, the user task stacks will be
+#   used during interrupt handling.
+# CONFIG_ARCH_STACKDUMP - Do stack dumps after assertions
+# CONFIG_ARCH_BOOTLOADER - Set if you are using a bootloader.
+# CONFIG_ARCH_LEDS -  Use LEDs to show state. Unique to board architecture.
+# CONFIG_ARCH_BUTTONS -  Enable support for buttons. Unique to board architecture.
+# CONFIG_ARCH_CALIBRATION - Enables some build in instrumentation that
+#   cause a 100 second delay during boot-up.  This 100 second delay
+#   serves no purpose other than it allows you to calibrate
+#   CONFIG_BOARD_LOOPSPERMSEC.  You simply use a stop watch to measure
+#   the 100 second delay then adjust CONFIG_BOARD_LOOPSPERMSEC until
+#   the delay actually is 100 seconds.
+# CONFIG_ARCH_DMA - Support DMA initialization
+#
+CONFIG_ARCH=arm
+CONFIG_ARCH_ARM=y
+CONFIG_ARCH_ARM926EJS=y
+CONFIG_ARCH_CHIP=lpc313x
+CONFIG_ARCH_CHIP_LPC3131=y
+CONFIG_ARCH_BOARD=ea3131
+CONFIG_ARCH_BOARD_EA3131=y
+CONFIG_BOARD_LOOPSPERMSEC=16945
+CONFIG_DRAM_SIZE=0x00030000
+CONFIG_DRAM_START=0x11028000
+CONFIG_DRAM_VSTART=0x11028000
+CONFIG_ARCH_IRQPRIO=y
+CONFIG_ARCH_INTERRUPTSTACK=n
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_BOOTLOADER=n
+CONFIG_ARCH_LEDS=y
+CONFIG_ARCH_BUTTONS=n
+CONFIG_ARCH_CALIBRATION=n
+CONFIG_ARCH_DMA=n
+
+#
+# ARM-specific configuration
+#
+# CONFIG_ARCH_LOWVECTORS - define if vectors reside at address 0x0000:00000
+#   Undefine if vectors reside at address 0xffff:0000
+# CONFIG_ARCH_ROMPGTABLE - A pre-initialized, read-only page table is available.
+#   If defined, then board-specific logic must also define PGTABLE_BASE_PADDR,
+#   PGTABLE_BASE_VADDR, and all memory section mapping in a file named
+#   board_memorymap.h.
+#
+CONFIG_ARCH_LOWVECTORS=y
+CONFIG_ARCH_ROMPGTABLE=y
+
+# Identify toolchain and linker options
+#
+CONFIG_LPC313X_CODESOURCERYW=n
+CONFIG_LPC313X_CODESOURCERYL=y
+CONFIG_LPC313X_DEVKITARM=n
+CONFIG_LPC313X_BUILDROOT=n
+
+#
+#  Individual subsystems can be enabled:
+#
+CONFIG_LPC313X_MCI=n
+CONFIG_LPC313X_SPI=n
+CONFIG_LPC313X_UART=y
+
+#
+# Exernal memory available on the board (see also CONFIG_MM_REGIONS)
+#
+# CONFIG_LPC313X_EXTSRAM0 - Select if external SRAM0 is present
+# CONFIG_LPC313X_EXTSRAM0HEAP - Select if external SRAM0 should be
+#   configured as part of the NuttX heap.
+# CONFIG_LPC313X_EXTSRAM0SIZE - Size (in bytes) of the installed
+#   external SRAM0 memory
+# CONFIG_LPC313X_EXTSRAM1 - Select if external SRAM1 is present
+# CONFIG_LPC313X_EXTSRAM1HEAP - Select if external SRAM1 should be
+#   configured as part of the NuttX heap.
+# CONFIG_LPC313X_EXTSRAM1SIZE - Size (in bytes) of the installed
+#   external SRAM1 memory
+# CONFIG_LPC313X_EXTSDRAM - Select if external SDRAM is present
+# CONFIG_LPC313X_EXTSDRAMHEAP - Select if external SDRAM should be
+#   configured as part of the NuttX heap.
+# CONFIG_LPC313X_EXTSDRAMSIZE - Size (in bytes) of the installed
+#   external SDRAM memory
+# CONFIG_LPC313X_EXTNAND - Select if external NAND is present
+# CONFIG_LPC313X_EXTSDRAMSIZE - Size (in bytes) of the installed
+#   external NAND memory
+#
+CONFIG_LPC313X_EXTSRAM0=n
+CONFIG_LPC313X_EXTSRAM0HEAP=n
+CONFIG_LPC313X_EXTSRAM0SIZE=(128*1024)
+CONFIG_LPC313X_EXTSRAM1=n
+CONFIG_LPC313X_EXTSRAM1HEAP=n
+CONFIG_LPC313X_EXTSRAM1SIZE=(128*1024)
+CONFIG_LPC313X_EXTSDRAM=n
+CONFIG_LPC313X_EXTSDRAMHEAP=n
+CONFIG_LPC313X_EXTSDRAMSIZE=(64*1024*1024)
+CONFIG_LPC313X_EXTNAND=n
+CONFIG_LPC313X_EXTNANDSIZE=(64*1024*1024)
+
+#
+# LPC313X specific device driver settings
+#
+# CONFIG_UART_SERIAL_CONSOLE - selects the UART for the
+#   console and ttys0
+# CONFIG_UART_RXBUFSIZE - Characters are buffered as received.
+#   This specific the size of the receive buffer
+# CONFIG_UART_TXBUFSIZE - Characters are buffered before
+#   being sent.  This specific the size of the transmit buffer
+# CONFIG_UART_BAUD - The configure BAUD of the UART.  Must be
+# CONFIG_UART_BITS - The number of bits.  Must be either 7 or 8.
+# CONFIG_UART_PARTIY - 0=no parity, 1=odd parity, 2=even parity
+# CONFIG_UART_2STOP - Two stop bits
+#
+CONFIG_UART_SERIAL_CONSOLE=y
+CONFIG_UART_TXBUFSIZE=256
+CONFIG_UART_RXBUFSIZE=256
+CONFIG_UART_BAUD=115200
+CONFIG_UART_BITS=8
+CONFIG_UART_PARITY=0
+CONFIG_UART_2STOP=0
+
+#
+# General build options
+#
+# CONFIG_RRLOAD_BINARY - make the rrload binary format used with
+#   BSPs from www.ridgerun.com using the tools/mkimage.sh script
+# CONFIG_INTELHEX_BINARY - make the Intel HEX binary format
+#   used with many different loaders using the GNU objcopy program
+#   Should not be selected if you are not using the GNU toolchain.
+# CONFIG_MOTOROLA_SREC - make the Motorola S-Record binary format
+#   used with many different loaders using the GNU objcopy program
+#   Should not be selected if you are not using the GNU toolchain.
+# CONFIG_RAW_BINARY - make a raw binary format file used with many
+#   different loaders using the GNU objcopy program.  This option
+#   should not be selected if you are not using the GNU toolchain.
+# CONFIG_HAVE_LIBM - toolchain supports libm.a
+#
+CONFIG_RRLOAD_BINARY=n
+CONFIG_INTELHEX_BINARY=n
+CONFIG_MOTOROLA_SREC=n
+CONFIG_RAW_BINARY=y
+CONFIG_HAVE_LIBM=n
+
+#
+# General OS setup
+#
+# CONFIG_EXAMPLE - identifies the subdirectory in examples
+#   that will be used in the build
+# CONFIG_DEBUG - enables built-in debug options
+# CONFIG_DEBUG_VERBOSE - enables verbose debug output
+# CONFIG_DEBUG_SYMBOLS - build without optimization and with
+#   debug symbols (needed for use with a debugger).
+# CONFIG_MM_REGIONS - If the architecture includes multiple
+#   regions of memory to allocate from, this specifies the
+#   number of memory regions that the memory manager must
+#   handle and enables the API mm_addregion(start, end);
+# CONFIG_ARCH_LOWPUTC - architecture supports low-level, boot
+#   time console output
+# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz
+#   or TICKS_PER_MSEC=10.  This setting may be defined to
+#   inform NuttX that the processor hardware is providing
+#   system timer interrupts at some interrupt interval other
+#   than 10 msec.
+# CONFIG_RR_INTERVAL - The round robin timeslice will be set
+#   this number of milliseconds;  Round robin scheduling can
+#   be disabled by setting this value to zero.
+# CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in 
+#   scheduler to monitor system performance
+# CONFIG_TASK_NAME_SIZE - Spcifies that maximum size of a
+#   task name to save in the TCB.  Useful if scheduler
+#   instrumentation is selected.  Set to zero to disable.
+# CONFIG_START_YEAR, CONFIG_START_MONTH, CONFIG_START_DAY -
+#   Used to initialize the internal time logic.
+# CONFIG_GREGORIAN_TIME - Enables Gregorian time conversions.
+#   You would only need this if you are concerned about accurate
+#   time conversions in the past or in the distant future.
+# CONFIG_JULIAN_TIME - Enables Julian time conversions. You
+#   would only need this if you are concerned about accurate
+#   time conversion in the distand past.  You must also define
+#   CONFIG_GREGORIAN_TIME in order to use Julian time.
+# CONFIG_DEV_CONSOLE - Set if architecture-specific logic
+#   provides /dev/console.  Enables stdout, stderr, stdin.
+# CONFIG_DEV_LOWCONSOLE - Use the simple, low-level serial console
+#   driver (minimul support)
+# CONFIG_MUTEX_TYPES: Set to enable support for recursive and
+#   errorcheck mutexes. Enables pthread_mutexattr_settype().
+# CONFIG_PRIORITY_INHERITANCE : Set to enable support for priority
+#   inheritance on mutexes and semaphores. 
+# CONFIG_SEM_PREALLOCHOLDERS: This setting is only used if priority
+#   inheritance is enabled.  It defines the maximum number of
+#   different threads (minus one) that can take counts on a
+#   semaphore with priority inheritance support.  This may be 
+#   set to zero if priority inheritance is disabled OR if you
+#   are only using semaphores as mutexes (only one holder) OR
+#   if no more than two threads participate using a counting
+#   semaphore.
+# CONFIG_SEM_NNESTPRIO.  If priority inheritance is enabled,
+#   then this setting is the maximum number of higher priority
+#   threads (minus 1) than can be waiting for another thread
+#   to release a count on a semaphore.  This value may be set
+#   to zero if no more than one thread is expected to wait for
+#   a semaphore.
+# CONFIG_FDCLONE_DISABLE. Disable cloning of all file descriptors
+#   by task_create() when a new task is started.  If set, all
+#   files/drivers will appear to be closed in the new task.
+# CONFIG_FDCLONE_STDIO. Disable cloning of all but the first
+#   three file descriptors (stdin, stdout, stderr) by task_create()
+#   when a new task is started. If set, all files/drivers will
+#   appear to be closed in the new task except for stdin, stdout,
+#   and stderr.
+# CONFIG_SDCLONE_DISABLE. Disable cloning of all socket
+#   desciptors by task_create() when a new task is started. If
+#   set, all sockets will appear to be closed in the new task.
+# CONFIG_NXFLAT. Enable support for the NXFLAT binary format.
+#  This format will support execution of NuttX binaries located
+#  in a ROMFS filesystem (see examples/nxflat).
+# CONFIG_SCHED_WORKQUEUE.  Create a dedicated "worker" thread to
+#  handle delayed processing from interrupt handlers.  This feature
+#  is required for some drivers but, if there are not complaints,
+#  can be safely disabled.  The worker thread also performs
+#  garbage collection -- completing any delayed memory deallocations
+#  from interrupt handlers.  If the worker thread is disabled,
+#  then that clean will be performed by the IDLE thread instead
+#  (which runs at the lowest of priority and may not be appropriate
+#  if memory reclamation is of high priority).  If CONFIG_SCHED_WORKQUEUE
+#  is enabled, then the following options can also be used:
+# CONFIG_SCHED_WORKPRIORITY - The execution priority of the worker
+#  thread.  Default: 50
+# CONFIG_SCHED_WORKPERIOD - How often the worker thread checks for
+#  work in units of microseconds.  Default: 50*1000 (50 MS).
+# CONFIG_SCHED_WORKSTACKSIZE - The stack size allocated for the worker
+#  thread.  Default: CONFIG_IDLETHREAD_STACKSIZE.
+# CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
+#  the worker thread.  Default: 4
+#
+CONFIG_EXAMPLE=usbstorage
+CONFIG_DEBUG=n
+CONFIG_DEBUG_VERBOSE=n
+CONFIG_DEBUG_FS=n
+CONFIG_DEBUG_USB=n
+CONFIG_DEBUG_SYMBOLS=n
+CONFIG_MM_REGIONS=1
+CONFIG_ARCH_LOWPUTC=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_INSTRUMENTATION=n
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_START_YEAR=2010
+CONFIG_START_MONTH=3
+CONFIG_START_DAY=28
+CONFIG_GREGORIAN_TIME=n
+CONFIG_JULIAN_TIME=n
+CONFIG_DEV_CONSOLE=y
+CONFIG_DEV_LOWCONSOLE=y
+CONFIG_MUTEX_TYPES=n
+CONFIG_PRIORITY_INHERITANCE=n
+CONFIG_SEM_PREALLOCHOLDERS=0
+CONFIG_SEM_NNESTPRIO=0
+CONFIG_FDCLONE_DISABLE=n
+CONFIG_FDCLONE_STDIO=n
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_NXFLAT=n
+CONFIG_SCHED_WORKQUEUE=n
+CONFIG_SCHED_WORKPRIORITY=50
+CONFIG_SCHED_WORKPERIOD=(50*1000)
+CONFIG_SCHED_WORKSTACKSIZE=1024
+CONFIG_SIG_SIGWORK=4
+
+#
+# The following can be used to disable categories of
+# APIs supported by the OS.  If the compiler supports
+# weak functions, then it should not be necessary to
+# disable functions unless you want to restrict usage
+# of those APIs.
+#
+# There are certain dependency relationships in these
+# features.
+#
+# o mq_notify logic depends on signals to awaken tasks
+#   waiting for queues to become full or empty.
+# o pthread_condtimedwait() depends on signals to wake
+#   up waiting tasks.
+#
+CONFIG_DISABLE_CLOCK=n
+CONFIG_DISABLE_POSIX_TIMERS=n
+CONFIG_DISABLE_PTHREAD=n
+CONFIG_DISABLE_SIGNALS=n
+CONFIG_DISABLE_MQUEUE=n
+CONFIG_DISABLE_MOUNTPOINT=n
+CONFIG_DISABLE_ENVIRON=y
+CONFIG_DISABLE_POLL=y
+
+#
+# Misc libc settings
+#
+# CONFIG_NOPRINTF_FIELDWIDTH - sprintf-related logic is a
+#   little smaller if we do not support fieldwidthes
+#
+CONFIG_NOPRINTF_FIELDWIDTH=n
+
+#
+# Allow for architecture optimized implementations
+#
+# The architecture can provide optimized versions of the
+# following to improve system performance
+#
+CONFIG_ARCH_MEMCPY=n
+CONFIG_ARCH_MEMCMP=n
+CONFIG_ARCH_MEMMOVE=n
+CONFIG_ARCH_MEMSET=n
+CONFIG_ARCH_STRCMP=n
+CONFIG_ARCH_STRCPY=n
+CONFIG_ARCH_STRNCPY=n
+CONFIG_ARCH_STRLEN=n
+CONFIG_ARCH_BZERO=n
+CONFIG_ARCH_KMALLOC=n
+CONFIG_ARCH_KZMALLOC=n
+CONFIG_ARCH_KFREE=n
+
+#
+# Sizes of configurable things (0 disables)
+#
+# CONFIG_MAX_TASKS - The maximum number of simultaneously
+#   active tasks.  This value must be a power of two.
+# CONFIG_MAX_TASK_ARGS - This controls the maximum number of
+#   of parameters that a task may receive (i.e., maxmum value
+#   of 'argc')
+# CONFIG_NPTHREAD_KEYS - The number of items of thread-
+#   specific data that can be retained
+# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
+#   descriptors (one for each open)
+# CONFIG_NFILE_STREAMS - The maximum number of streams that
+#   can be fopen'ed
+# CONFIG_NAME_MAX - The maximum size of a file name.
+# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
+#   on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_NUNGET_CHARS - Number of characters that can be
+#   buffered by ungetc() (Only if CONFIG_NFILE_STREAMS > 0)
+# CONFIG_PREALLOC_MQ_MSGS - The number of pre-allocated message
+#   structures.  The system manages a pool of preallocated
+#   message structures to minimize dynamic allocations
+# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
+#   a fixed payload size given by this settin (does not include
+#   other message structure overhead.
+# CONFIG_MAX_WDOGPARMS - Maximum number of parameters that
+#   can be passed to a watchdog handler
+# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
+#   structures.  The system manages a pool of preallocated
+#   watchdog structures to minimize dynamic allocations
+# CONFIG_PREALLOC_TIMERS - The number of pre-allocated POSIX
+#   timer structures.  The system manages a pool of preallocated
+#   timer structures to minimize dynamic allocations.  Set to
+#   zero for all dynamic allocations.
+#
+CONFIG_MAX_TASKS=16
+CONFIG_MAX_TASK_ARGS=4
+CONFIG_NPTHREAD_KEYS=4
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NFILE_STREAMS=8
+CONFIG_NAME_MAX=32
+CONFIG_STDIO_BUFFER_SIZE=256
+CONFIG_NUNGET_CHARS=2
+CONFIG_PREALLOC_MQ_MSGS=4
+CONFIG_MQ_MAXMSGSIZE=32
+CONFIG_MAX_WDOGPARMS=2
+CONFIG_PREALLOC_WDOGS=4
+CONFIG_PREALLOC_TIMERS=4
+
+#
+# Filesystem configuration
+#
+# CONFIG_FS_FAT - Enable FAT filesystem support
+# CONFIG_FAT_SECTORSIZE - Max supported sector size
+# CONFIG_FS_ROMFS - Enable ROMFS filesystem support
+CONFIG_FS_FAT=y
+CONFIG_FS_ROMFS=n
+CONFIG_FS_WRITABLE=y
+
+#
+# Block driver buffering
+#
+# CONFIG_FS_READAHEAD
+#   Enable read-ahead buffering
+# CONFIG_FS_WRITEBUFFER
+#   Enable write buffering
+#
+CONFIG_FS_READAHEAD=n
+CONFIG_FS_WRITEBUFFER=n
+
+#
+# SDIO-based MMC/SD driver
+#
+# CONFIG_SDIO_DMA
+#   SDIO driver supports DMA
+# CONFIG_MMCSD_MMCSUPPORT
+#   Enable support for MMC cards
+# CONFIG_MMCSD_HAVECARDDETECT
+#   SDIO driver card detection is 100% accurate
+#
+CONFIG_SDIO_DMA=n
+CONFIG_MMCSD_MMCSUPPORT=n
+CONFIG_MMCSD_HAVECARDDETECT=n
+
+#
+# TCP/IP and UDP support via uIP
+# CONFIG_NET - Enable or disable all network features
+# CONFIG_NET_IPv6 - Build in support for IPv6
+# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread.
+# CONFIG_NET_SOCKOPTS - Enable or disable support for socket options
+# CONFIG_NET_BUFSIZE - uIP buffer size
+# CONFIG_NET_TCP - TCP support on or off
+# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks)
+# CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers
+# CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero)
+# CONFIG_NET_TCPBACKLOG - Incoming connections pend in a backlog until
+#   accept() is called. The size of the backlog is selected when listen() is called.
+# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks)
+# CONFIG_NET_UDP - UDP support on or off
+# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off
+# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections
+# CONFIG_NET_ICMP - ICMP ping response support on or off
+# CONFIG_NET_ICMP_PING - ICMP ping request support on or off
+# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address
+# CONFIG_NET_STATISTICS - uIP statistics on or off
+# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window
+# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table
+# CONFIG_NET_BROADCAST - Broadcast support
+# CONFIG_NET_LLH_LEN - The link level header length
+# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates
+#
+CONFIG_NET=n
+CONFIG_NET_IPv6=n
+CONFIG_NSOCKET_DESCRIPTORS=0
+CONFIG_NET_SOCKOPTS=y
+CONFIG_NET_BUFSIZE=420
+CONFIG_NET_TCP=n
+CONFIG_NET_TCP_CONNS=40
+CONFIG_NET_MAX_LISTENPORTS=40
+CONFIG_NET_UDP=n
+CONFIG_NET_UDP_CHECKSUMS=y
+#CONFIG_NET_UDP_CONNS=10
+CONFIG_NET_ICMP=n
+CONFIG_NET_ICMP_PING=n
+#CONFIG_NET_PINGADDRCONF=0
+CONFIG_NET_STATISTICS=y
+#CONFIG_NET_RECEIVE_WINDOW=
+#CONFIG_NET_ARPTAB_SIZE=8
+CONFIG_NET_BROADCAST=n
+#CONFIG_NET_LLH_LEN=14
+#CONFIG_NET_FWCACHE_SIZE=2
+
+#
+# UIP Network Utilities
+# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP
+# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries
+#
+CONFIG_NET_DHCP_LIGHT=n
+CONFIG_NET_RESOLV_ENTRIES=4
+
+#
+# USB Device Configuration
+#
+# CONFIG_USBDEV
+#   Enables USB device support
+# CONFIG_USBDEV_ISOCHRONOUS
+#   Build in extra support for isochronous endpoints
+# CONFIG_USBDEV_DUALSPEED
+#   Hardware handles high and full speed operation (USB 2.0)
+# CONFIG_USBDEV_SELFPOWERED
+#   Will cause USB features to indicate that the device is
+#   self-powered
+# CONFIG_USBDEV_MAXPOWER
+#   Maximum power consumption in mA
+# CONFIG_USBDEV_TRACE
+#   Enables USB tracing for debug
+# CONFIG_USBDEV_TRACE_NRECORDS
+#   Number of trace entries to remember
+#
+CONFIG_USBDEV=y
+CONFIG_USBDEV_ISOCHRONOUS=n
+CONFIG_USBDEV_DUALSPEED=y
+CONFIG_USBDEV_SELFPOWERED=y
+CONFIG_USBDEV_REMOTEWAKEUP=n
+CONFIG_USBDEV_MAXPOWER=100
+CONFIG_USBDEV_TRACE=n
+CONFIG_USBDEV_TRACE_NRECORDS=128
+
+#
+# LPC313X USB Configuration
+#
+# CONFIG_LPC313X_GIO_USBATTACH
+#   GIO that detects USB attach/detach events
+# CONFIG_LPC313X_GIO_USBDPPULLUP
+#   GIO 
+# CONFIG_DMA320_USBDEV_DMA
+#   Enable LPC313X-specific DMA support
+#
+CONFIG_LPC313X_GIO_USBATTACH=6
+CONFIG_LPC313X_GIO_USBDPPULLUP=17
+CONFIG_LPC313X_VENDORID=0xd320
+CONFIG_LPC313X_PRODUCTID=0x3211
+CONFIG_LPC313X_USBDEV_DMA=n
+
+#
+# USB Serial Device Configuration
+#
+# CONFIG_USBSER
+#   Enable compilation of the USB serial driver
+# CONFIG_USBSER_EPINTIN
+#   The logical 7-bit address of a hardware endpoint that supports
+#   interrupt IN operation
+# CONFIG_USBSER_EPBULKOUT
+#   The logical 7-bit address of a hardware endpoint that supports
+#   bulk OUT operation
+# CONFIG_USBSER_EPBULKIN
+#   The logical 7-bit address of a hardware endpoint that supports
+#   bulk IN operation
+# CONFIG_USBSER_NWRREQS and CONFIG_USBSER_NRDREQS
+#   The number of write/read requests that can be in flight
+# CONFIG_USBSER_VENDORID and CONFIG_USBSER_VENDORSTR
+#   The vendor ID code/string
+# CONFIG_USBSER_PRODUCTID and CONFIG_USBSER_PRODUCTSTR
+#   The product ID code/string
+# CONFIG_USBSER_RXBUFSIZE and CONFIG_USBSER_TXBUFSIZE
+#   Size of the serial receive/transmit buffers
+#
+CONFIG_USBSER=n
+CONFIG_USBSER_EPINTIN=3
+CONFIG_USBSER_EPBULKOUT=2
+CONFIG_USBSER_EPBULKIN=1
+CONFIG_USBSER_NWRREQS=4
+CONFIG_USBSER_NRDREQS=4
+CONFIG_USBSER_VENDORID=0x067b
+CONFIG_USBSER_PRODUCTID=0x2303
+CONFIG_USBSER_VENDORSTR="Nuttx"
+CONFIG_USBSER_PRODUCTSTR="USBdev Serial"
+CONFIG_USBSER_RXBUFSIZE=512
+CONFIG_USBSER_TXBUFSIZE=512
+
+#
+# USB Storage Device Configuration
+#
+# CONFIG_USBSTRG
+#   Enable compilation of the USB storage driver
+# CONFIG_USBSTRG_EP0MAXPACKET
+#   Max packet size for endpoint 0
+# CONFIG_USBSTRG_EPBULKOUT and CONFIG_USBSTRG_EPBULKIN
+#   The logical 7-bit address of a hardware endpoints that support
+#   bulk OUT and IN operations
+# CONFIG_USBSTRG_NWRREQS and CONFIG_USBSTRG_NRDREQS
+#   The number of write/read requests that can be in flight
+# CONFIG_USBSTRG_BULKINREQLEN and CONFIG_USBSTRG_BULKOUTREQLEN
+#   The size of the buffer in each write/read request.  This
+#   value needs to be at least as large as the endpoint
+#   maxpacket and ideally as large as a block device sector.
+# CONFIG_USBSTRG_VENDORID and CONFIG_USBSTRG_VENDORSTR
+#   The vendor ID code/string
+# CONFIG_USBSTRG_PRODUCTID and CONFIG_USBSTRG_PRODUCTSTR
+#   The product ID code/string
+# CONFIG_USBSTRG_REMOVABLE
+#   Select if the media is removable
+#
+CONFIG_USBSTRG=y
+CONFIG_USBSTRG_EP0MAXPACKET=64
+CONFIG_USBSTRG_EPBULKOUT=2
+CONFIG_USBSTRG_EPBULKIN=1
+CONFIG_USBSTRG_NRDREQS=2
+CONFIG_USBSTRG_NWRREQS=2
+CONFIG_USBSTRG_BULKINREQLEN=512
+CONFIG_USBSTRG_BULKOUTREQLEN=512
+CONFIG_USBSTRG_VENDORID=0x584e
+CONFIG_USBSTRG_VENDORSTR="NuttX"
+CONFIG_USBSTRG_PRODUCTID=0x5342
+CONFIG_USBSTRG_PRODUCTSTR="USBdev Storage"
+CONFIG_USBSTRG_VERSIONNO=0x0399
+CONFIG_USBSTRG_REMOVABLE=y
+
+#
+# Settings for examples/uip
+#
+CONFIG_EXAMPLE_UIP_IPADDR=(10<<24|0<<16|0<<8|2)
+CONFIG_EXAMPLE_UIP_DRIPADDR=(10<<24|0<<16|0<<8|1)
+CONFIG_EXAMPLE_UIP_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLE_UIP_DHCPC=n
+
+#
+# Settings for examples/nettest
+#
+CONFIG_EXAMPLE_NETTEST_SERVER=n
+CONFIG_EXAMPLE_NETTEST_PERFORMANCE=n
+CONFIG_EXAMPLE_NETTEST_NOMAC=n
+CONFIG_EXAMPLE_NETTEST_IPADDR=(10<<24|0<<16|0<<8|2)
+CONFIG_EXAMPLE_NETTEST_DRIPADDR=(10<<24|0<<16|0<<8|1)
+CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
+
+#
+# Settings for examples/ostest
+#
+CONFIG_EXAMPLES_OSTEST_LOOPS=1
+CONFIG_EXAMPLES_OSTEST_STACKSIZE=2048
+CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=3
+
+#
+# Settings for examples/nsh
+#
+# CONFIG_EXAMPLES_NSH_FILEIOSIZE - Size of a static I/O buffer
+# CONFIG_EXAMPLES_NSH_STRERROR - Use strerror(errno)
+# CONFIG_EXAMPLES_NSH_LINELEN - Maximum length of one command line
+# CONFIG_EXAMPLES_NSH_STACKSIZE - Stack size to use for new threads.
+# CONFIG_EXAMPLES_NSH_NESTDEPTH - Max number of nested if-then[-else]-fi
+# CONFIG_EXAMPLES_NSH_DISABLESCRIPT - Disable scripting support
+# CONFIG_EXAMPLES_NSH_DISABLEBG - Disable background commands
+# CONFIG_EXAMPLES_NSH_ROMFSETC - Use startup script in /etc
+# CONFIG_EXAMPLES_NSH_CONSOLE - Use serial console front end
+# CONFIG_EXAMPLES_NSH_TELNET - Use telnetd console front end
+# CONFIG_EXAMPLES_NSH_ARCHINIT - Platform provides architecture
+#   specific initialization (nsh_archinitialize()).
+#
+# If CONFIG_EXAMPLES_NSH_TELNET is selected:
+# CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE -- Telnetd I/O buffer size
+# CONFIG_EXAMPLES_NSH_DHCPC - Obtain address using DHCP
+# CONFIG_EXAMPLES_NSH_IPADDR - Provides static IP address
+# CONFIG_EXAMPLES_NSH_DRIPADDR - Provides static router IP address
+# CONFIG_EXAMPLES_NSH_NETMASK - Provides static network mask
+# CONFIG_EXAMPLES_NSH_NOMAC - Use a bogus MAC address
+#
+# If CONFIG_EXAMPLES_NSH_ROMFSETC is selected:
+# CONFIG_EXAMPLES_NSH_ROMFSMOUNTPT - ROMFS mountpoint
+# CONFIG_EXAMPLES_NSH_INITSCRIPT - Relative path to init script
+# CONFIG_EXAMPLES_NSH_ROMFSDEVNO - ROMFS RAM device minor
+# CONFIG_EXAMPLES_NSH_ROMFSSECTSIZE - ROMF sector size
+# CONFIG_EXAMPLES_NSH_FATDEVNO - FAT FS RAM device minor
+# CONFIG_EXAMPLES_NSH_FATSECTSIZE - FAT FS sector size
+# CONFIG_EXAMPLES_NSH_FATNSECTORS - FAT FS number of sectors
+# CONFIG_EXAMPLES_NSH_FATMOUNTPT - FAT FS mountpoint
+#
+CONFIG_EXAMPLES_NSH_FILEIOSIZE=512
+CONFIG_EXAMPLES_NSH_STRERROR=n
+CONFIG_EXAMPLES_NSH_LINELEN=64
+CONFIG_EXAMPLES_NSH_STACKSIZE=2048
+CONFIG_EXAMPLES_NSH_NESTDEPTH=3
+CONFIG_EXAMPLES_NSH_DISABLESCRIPT=n
+CONFIG_EXAMPLES_NSH_DISABLEBG=n
+CONFIG_EXAMPLES_NSH_ROMFSETC=n
+CONFIG_EXAMPLES_NSH_CONSOLE=y
+CONFIG_EXAMPLES_NSH_TELNET=n
+CONFIG_EXAMPLES_NSH_ARCHINIT=n
+CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
+CONFIG_EXAMPLES_NSH_DHCPC=n
+CONFIG_EXAMPLES_NSH_NOMAC=n
+CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
+CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
+CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
+CONFIG_EXAMPLES_NSH_ROMFSMOUNTPT="/etc"
+CONFIG_EXAMPLES_NSH_INITSCRIPT="init.d/rcS"
+CONFIG_EXAMPLES_NSH_ROMFSDEVNO=0
+CONFIG_EXAMPLES_NSH_ROMFSSECTSIZE=64
+CONFIG_EXAMPLES_NSH_FATDEVNO=1
+CONFIG_EXAMPLES_NSH_FATSECTSIZE=512
+CONFIG_EXAMPLES_NSH_FATNSECTORS=1024
+CONFIG_EXAMPLES_NSH_FATMOUNTPT=/tmp
+
+#
+# Architecture-specific NSH options
+#
+CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO=0
+CONFIG_EXAMPLES_NSH_MMCSDSLOTNO=0
+CONFIG_EXAMPLES_NSH_MMCSDMINOR=0
+
+#
+# Settings for examples/usbserial
+#
+# CONFIG_EXAMPLES_USBSERIAL_INONLY
+#    Only verify IN (device-to-host) data transfers.  Default: both
+# CONFIG_EXAMPLES_USBSERIAL_OUTONLY
+#    Only verify OUT (host-to-device) data transfers.  Default: both
+# CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL
+#    Send only small, single packet messages.  Default: Send large and small.
+# CONFIG_EXAMPLES_USBSERIAL_ONLYBIG
+#    Send only large, multi-packet messages.  Default: Send large and small.
+#
+CONFIG_EXAMPLES_USBSERIAL_INONLY=n
+CONFIG_EXAMPLES_USBSERIAL_OUTONLY=n
+CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL=n
+CONFIG_EXAMPLES_USBSERIAL_ONLYBIG=n
+
+CONFIG_EXAMPLES_USBSERIAL_TRACEINIT=n
+CONFIG_EXAMPLES_USBSERIAL_TRACECLASS=n
+CONFIG_EXAMPLES_USBSERIAL_TRACETRANSFERS=n
+CONFIG_EXAMPLES_USBSERIAL_TRACECONTROLLER=n
+CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS=n
+
+#
+# Settings for examples/usbstorage
+#
+# CONFIG_EXAMPLES_USBSTRG_NLUNS
+#    Defines the number of logical units (LUNs) exported by the USB storage
+#    driver.  Each LUN corresponds to one exported block driver (or partition
+#    of a block driver).  May be 1, 2, or 3.  Default is 1.
+# CONFIG_EXAMPLES_USBSTRG_DEVMINOR1
+#    The minor device number of the block driver for the first LUN. For
+#    example, N in /dev/mmcsdN.  Used for registering the block driver. Default
+#    is zero.
+# CONFIG_EXAMPLES_USBSTRG_DEVPATH1
+#    The full path to the registered block driver.  Default is "/dev/mmcsd0"
+#  CONFIG_EXAMPLES_USBSTRG_DEVMINOR2 and CONFIG_EXAMPLES_USBSTRG_DEVPATH2
+#    Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBSTRG_NLUNS
+#    is 2 or 3.  No defaults.
+#  CONFIG_EXAMPLES_USBSTRG_DEVMINOR3 and CONFIG_EXAMPLES_USBSTRG_DEVPATH3
+#    Similar parameters that would have to be provided if CONFIG_EXAMPLES_USBSTRG_NLUNS
+#    is 3.  No defaults.
+#
+#  If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB), then
+#  the example code will also manage the USB trace output.  The amount of trace output
+#  can be controlled using:
+#
+#  CONFIG_EXAMPLES_USBSTRG_TRACEINIT
+#    Show initialization events
+#  CONFIG_EXAMPLES_USBSTRG_TRACECLASS
+#    Show class driver events
+#  CONFIG_EXAMPLES_USBSTRG_TRACETRANSFERS
+#    Show data transfer events
+#  CONFIG_EXAMPLES_USBSTRG_TRACECONTROLLER
+#    Show controller events
+#  CONFIG_EXAMPLES_USBSTRG_TRACEINTERRUPTS
+#    Show interrupt-related events.
+CONFIG_EXAMPLES_USBSTRG_NLUNS=1
+CONFIG_EXAMPLES_USBSTRG_DEVMINOR1=0
+CONFIG_EXAMPLES_USBSTRG_DEVPATH1="/dev/ram0"
+CONFIG_EXAMPLES_USBSTRG_TRACEINIT=n
+CONFIG_EXAMPLES_USBSTRG_TRACECLASS=n
+CONFIG_EXAMPLES_USBSTRG_TRACETRANSFERS=n
+CONFIG_EXAMPLES_USBSTRG_TRACECONTROLLER=n
+CONFIG_EXAMPLES_USBSTRG_TRACEINTERRUPTS=n
+
+#
+# Stack and heap information
+#
+# CONFIG_BOOT_RUNFROMFLASH - Some configurations support XIP
+#   operation from FLASH but must copy initialized .data sections to RAM.
+# CONFIG_BOOT_COPYTORAM -  Some configurations boot in FLASH
+#   but copy themselves entirely into RAM for better performance.
+# CONFIG_CUSTOM_STACK - The up_ implementation will handle
+#   all stack operations outside of the nuttx model.
+# CONFIG_STACK_POINTER - The initial stack pointer (arm7tdmi only)
+# CONFIG_IDLETHREAD_STACKSIZE - The size of the initial stack.
+#  This is the thread that (1) performs the inital boot of the system up
+#  to the point where user_start() is spawned, and (2) there after is the
+#  IDLE thread that executes only when there is no other thread ready to
+#  run.
+# CONFIG_USERMAIN_STACKSIZE - The size of the stack to allocate
+#  for the main user thread that begins at the user_start() entry point.
+# CONFIG_PTHREAD_STACK_MIN - Minimum pthread stack size
+# CONFIG_PTHREAD_STACK_DEFAULT - Default pthread stack size
+# CONFIG_HEAP_BASE - The beginning of the heap
+# CONFIG_HEAP_SIZE - The size of the heap
+#
+CONFIG_BOOT_RUNFROMFLASH=n
+CONFIG_BOOT_COPYTORAM=n
+CONFIG_CUSTOM_STACK=n
+CONFIG_STACK_POINTER=
+CONFIG_IDLETHREAD_STACKSIZE=1024
+CONFIG_USERMAIN_STACKSIZE=2048
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=2048
+CONFIG_HEAP_BASE=
+CONFIG_HEAP_SIZE=
diff --git a/configs/ea3131/usbstorage/ld.script b/configs/ea3131/usbstorage/ld.script
new file mode 100755
index 0000000000000000000000000000000000000000..b23cd18bd5d94d999eed6766adb05df3a1962c21
--- /dev/null
+++ b/configs/ea3131/usbstorage/ld.script
@@ -0,0 +1,107 @@
+/****************************************************************************
+ * configs/ea3131/usbstorage/ld.script
+ *
+ *   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 LPC3131 has 192Kb of ISRAM beginning at virtual address 0x1102:8000.
+ * LPC313x boot ROM expects the boot image be compiled with entry point at
+ * 0x1102:9000.  A 128b header will appear at this address (applied by
+ * lpc313xImgCreator) and the executable code must begin at 0x1102:9080.
+ */
+
+MEMORY
+{
+    isram (rwx) : ORIGIN = 0x11029080, LENGTH = 192K - 4224
+}
+
+OUTPUT_ARCH(arm)
+ENTRY(_stext)
+SECTIONS
+{
+	.text : {
+		_stext = ABSOLUTE(.);
+		*(.vectors)
+		*(.text .text.*)        
+		*(.fixup)
+		*(.gnu.warning)
+		*(.rodata .rodata.*)        
+		*(.gnu.linkonce.t.*)
+		*(.glue_7)
+		*(.glue_7t)
+		*(.got)
+		*(.gcc_except_table)
+		*(.gnu.linkonce.r.*)
+		_etext = ABSOLUTE(.);
+	} > isram
+
+	_eronly = ABSOLUTE(.);
+
+	.data : {
+		_sdata = ABSOLUTE(.);
+		*(.data .data.*)
+		*(.gnu.linkonce.d.*)
+		CONSTRUCTORS
+		_edata = ABSOLUTE(.);
+	} > isram
+
+	.ARM.extab : {
+		*(.ARM.extab*)
+	} >isram
+
+	.ARM.exidx : {
+		__exidx_start = ABSOLUTE(.);
+		*(.ARM.exidx*)
+		__exidx_end = ABSOLUTE(.);
+	} > isram
+
+	.bss : {
+		_sbss = ABSOLUTE(.);
+		*(.bss .bss.*)
+		*(.gnu.linkonce.b.*)
+		*(COMMON)
+		_ebss = ABSOLUTE(.);
+	} > isram
+					/* Stabs debugging sections.	*/
+	.stab 0 : { *(.stab) }
+	.stabstr 0 : { *(.stabstr) }
+	.stab.excl 0 : { *(.stab.excl) }
+	.stab.exclstr 0 : { *(.stab.exclstr) }
+	.stab.index 0 : { *(.stab.index) }
+	.stab.indexstr 0 : { *(.stab.indexstr) }
+	.comment 0 : { *(.comment) }
+	.debug_abbrev 0 : { *(.debug_abbrev) }
+	.debug_info 0 : { *(.debug_info) }
+	.debug_line 0 : { *(.debug_line) }
+	.debug_pubnames 0 : { *(.debug_pubnames) }
+	.debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/configs/ea3131/usbstorage/setenv.sh b/configs/ea3131/usbstorage/setenv.sh
new file mode 100755
index 0000000000000000000000000000000000000000..ae08707d7056ef2a0a5121b8d8558acb0d46ef28
--- /dev/null
+++ b/configs/ea3131/usbstorage/setenv.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# configs/ea3131/usbstorage/setenv.sh
+#
+#   Copyright (C) 2010 Gregory Nutt. All rights reserved.
+#   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+
+if [ "$(basename $0)" = "setenv.sh" ] ; then
+  echo "You must source this script, not run it!" 1>&2
+  exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then export PATH_ORIG=${PATH}; fi
+
+WD=`pwd`
+export BUILDROOT_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin"
+export LPCTOOL_DIR="${WD}/configs/ea3131/tools"
+export PATH="${BUILDROOT_BIN}:${LPCTOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}"
+
+echo "PATH : ${PATH}"