summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/system/usbmsc/usbmsc_main.c26
-rw-r--r--nuttx/arch/arm/src/sam34/Kconfig4
-rwxr-xr-xnuttx/arch/arm/src/sam34/chip/sam_udp.h2
-rw-r--r--nuttx/arch/arm/src/sam34/sam_clockconfig.c7
-rw-r--r--nuttx/configs/sam4e-ek/Kconfig17
-rw-r--r--nuttx/configs/sam4e-ek/README.txt133
-rw-r--r--nuttx/configs/sam4e-ek/src/sam_hsmci.c61
-rw-r--r--nuttx/configs/sam4e-ek/src/sam_usbmsc.c61
-rw-r--r--nuttx/drivers/usbdev/usbdev_trace.c3
-rw-r--r--nuttx/drivers/usbdev/usbdev_trprintf.c2
10 files changed, 240 insertions, 76 deletions
diff --git a/apps/system/usbmsc/usbmsc_main.c b/apps/system/usbmsc/usbmsc_main.c
index 3b3dc96cc..b1717a047 100644
--- a/apps/system/usbmsc/usbmsc_main.c
+++ b/apps/system/usbmsc/usbmsc_main.c
@@ -51,7 +51,7 @@
#include "usbmsc.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
#ifdef CONFIG_SYSTEM_USBMSC_TRACEINIT
@@ -432,6 +432,7 @@ static int msconn_daemon(int argc, char *argv[])
message("msconn_main: usbmsc_archinitialize failed: %d\n", -ret);
return EXIT_FAILURE;
}
+
check_test_memory_usage("After usbmsc_archinitialize()");
/* Then exports the LUN(s) */
@@ -444,6 +445,7 @@ static int msconn_daemon(int argc, char *argv[])
usbmsc_uninitialize(handle);
return EXIT_FAILURE;
}
+
message("msconn_main: handle=%p\n", handle);
check_test_memory_usage("After usbmsc_configure()");
@@ -456,6 +458,7 @@ static int msconn_daemon(int argc, char *argv[])
usbmsc_uninitialize(handle);
return EXIT_FAILURE;
}
+
check_test_memory_usage("After usbmsc_bindlun()");
#if CONFIG_SYSTEM_USBMSC_NLUNS > 1
@@ -469,6 +472,7 @@ static int msconn_daemon(int argc, char *argv[])
usbmsc_uninitialize(handle);
return EXIT_FAILURE;
}
+
check_test_memory_usage("After usbmsc_bindlun() #2");
#if CONFIG_SYSTEM_USBMSC_NLUNS > 2
@@ -482,6 +486,7 @@ static int msconn_daemon(int argc, char *argv[])
usbmsc_uninitialize(handle);
return EXIT_FAILURE;
}
+
check_test_memory_usage("After usbmsc_bindlun() #3");
#endif
@@ -494,6 +499,7 @@ static int msconn_daemon(int argc, char *argv[])
usbmsc_uninitialize(handle);
return EXIT_FAILURE;
}
+
check_test_memory_usage("After usbmsc_exportluns()");
/* It this program was configued as an NSH command, then just exit now.
@@ -519,6 +525,7 @@ static int msconn_daemon(int argc, char *argv[])
usbmsc_uninitialize(handle);
return EXIT_FAILURE;
}
+
check_test_memory_usage("After usbtrace_enumerate()");
# else
message("msconn_main: Still alive\n");
@@ -643,18 +650,19 @@ int msdis_main(int argc, char *argv[])
message("msdis: ERROR: Not connected\n");
return EXIT_FAILURE;
}
- check_test_memory_usage("Since MS connection");
+
+ check_test_memory_usage("Since MS connection");
/* Then disconnect the device and uninitialize the USB mass storage driver */
- usbmsc_uninitialize(g_usbmsc.mshandle);
- g_usbmsc.mshandle = NULL;
- message("msdis: Disconnected\n");
- check_test_memory_usage("After usbmsc_uninitialize()");
+ usbmsc_uninitialize(g_usbmsc.mshandle);
+ g_usbmsc.mshandle = NULL;
+ message("msdis: Disconnected\n");
+ check_test_memory_usage("After usbmsc_uninitialize()");
- /* Dump debug memory usage */
+ /* Dump debug memory usage */
- final_memory_usage("Final memory usage");
- return EXIT_SUCCESS;
+ final_memory_usage("Final memory usage");
+ return EXIT_SUCCESS;
}
#endif
diff --git a/nuttx/arch/arm/src/sam34/Kconfig b/nuttx/arch/arm/src/sam34/Kconfig
index e77006200..2c244a858 100644
--- a/nuttx/arch/arm/src/sam34/Kconfig
+++ b/nuttx/arch/arm/src/sam34/Kconfig
@@ -1130,10 +1130,10 @@ endmenu # EMAC device driver options
endif # SAM34_EMAC
if SAM34_UDP
-menu "USB Full Speed Device Controller driver (DCD) options"
+menu "AT91SAM3/4 USB Full Speed Device Controller driver (DCD) options"
config SAM34_UDP_REGDEBUG
- bool "Enable low-level UPPHS register debug"
+ bool "Enable low-level UDP register debug"
default n
depends on DEBUG
diff --git a/nuttx/arch/arm/src/sam34/chip/sam_udp.h b/nuttx/arch/arm/src/sam34/chip/sam_udp.h
index 140896f8e..c24efd5ff 100755
--- a/nuttx/arch/arm/src/sam34/chip/sam_udp.h
+++ b/nuttx/arch/arm/src/sam34/chip/sam_udp.h
@@ -59,7 +59,7 @@
* 2 2 64 Bulk/Iso/Interrupt
* 3 1 64 Control/Bulk/Interrupt
* 4 2 512 Bulk/Iso/Interrupt
- * 5 2 612 Bulk/Iso/Interrupt
+ * 5 2 512 Bulk/Iso/Interrupt
* 6 2 64 Bulk/Iso/Interrupt
* 7 2 64 Bulk/Iso/Interrupt
*/
diff --git a/nuttx/arch/arm/src/sam34/sam_clockconfig.c b/nuttx/arch/arm/src/sam34/sam_clockconfig.c
index ed6650f88..bd6961e8f 100644
--- a/nuttx/arch/arm/src/sam34/sam_clockconfig.c
+++ b/nuttx/arch/arm/src/sam34/sam_clockconfig.c
@@ -257,13 +257,16 @@ static inline void sam_pmcsetup(void)
regval = (BOARD_PMC_USBS | BOARD_PMC_USBDIV);
putreg32(regval, SAM_PMC_USB);
+#if 0 /* Done in the UDP driver */
/* Set the UDP bit in the SCER register to enable the USB clock output */
regval = getreg32(SAM_PMC_SCER);
regval |= PMC_UDP;
putreg32(regval, SAM_PMC_SCER);
-#endif
-#endif
+
+#endif /* 0 */
+#endif /* SAM_PMC_CKGR_UCKR */
+#endif /* CONFIG_USBDEV */
/* Switch to the fast clock and wait for MCKRDY */
diff --git a/nuttx/configs/sam4e-ek/Kconfig b/nuttx/configs/sam4e-ek/Kconfig
index aebc0f913..382c8db56 100644
--- a/nuttx/configs/sam4e-ek/Kconfig
+++ b/nuttx/configs/sam4e-ek/Kconfig
@@ -20,7 +20,7 @@ endchoice # CPU Frequency
config SAM4EEK_AT25_AUTOMOUNT
bool "AT25 serial FLASH auto-mount"
default n
- depends on NSH_ARCHINIT && SAM34_SPI0 && MTD_AT25
+ depends on SAM34_SPI0 && MTD_AT25
---help---
Automatically initialize the AT25 SPI FLASH driver when NSH starts.
@@ -47,4 +47,19 @@ config SAM4EEK_AT25_NXFFS
endchoice # AT25 serial FLASH configuration
+choice
+ prompt "USB MSC block device"
+ default SAM4EEK_AT25_BLOCKDEVICE if SAM4EEK_AT25_FTL
+ default SAM4EEK_HSMCI_BLOCKDEVICE if !SAM4EEK_AT25_FTL
+ depends on SYSTEM_USBMSC && (SAM4EEK_AT25_FTL || SAM34_HSMCI)
+
+config SAM4EEK_AT25_BLOCKDEVICE
+ bool "AT25 Serial FLASH"
+
+config SAM4EEK_HSMCI_BLOCKDEVICE
+ bool "SD card"
+ depends on SAM34_HSMCI
+
+endchoice # AT25 serial FLASH configuration
+
endif # ARCH_BOARD_SAM4EEK
diff --git a/nuttx/configs/sam4e-ek/README.txt b/nuttx/configs/sam4e-ek/README.txt
index d1b8af274..e77ebfc15 100644
--- a/nuttx/configs/sam4e-ek/README.txt
+++ b/nuttx/configs/sam4e-ek/README.txt
@@ -21,6 +21,7 @@ Contents
- Serial Console
- Networking Support
- AT25 Serial FLASH
+ - USB Full-Speed Device
- SAM4E-EK-specific Configuration Options
- Configurations
@@ -586,6 +587,138 @@ AT25 Serial FLASH
nsh> cat /mnt/at25/atest.txt
This is a test
+USB Full-Speed Device
+=====================
+
+ Basic USB Full-Speed Device Configuration
+ -----------------------------------------
+
+ Support the USB high-speed device (UDPHS) driver can be enabled with these
+ NuttX configuration settings.
+
+ Device Drivers -> USB Device Driver Support
+ CONFIG_USBDEV=y : Enable USB device support
+ CONFIG_USBDEV_DUALSPEED=n : Device does not support High-Speed
+ CONFIG_USBDEV_DMA=n : Device does not use DMA
+
+ System Type -> ATSAM3/4 Peripheral Support
+ CONFIG_SAM34_UDP=y : Enable UDP Full Speed USB device
+
+ Application Configuration -> NSH Library
+ CONFIG_NSH_ARCHINIT=y : NSH board-initialization
+
+ Mass Storage Class
+ ------------------
+
+ The Mass Storage Class (MSC) class driver can be selected for use with
+ UDPHS. Note: The following assumes that the internal AT24 Serial FLASH
+ is configured to support a FAT file system through an FTL layer as
+ described about under "AT25 Serial FLASH".
+
+ Device Drivers -> USB Device Driver Support
+ CONFIG_USBMSC=y : Enable the USB MSC class driver
+ CONFIG_USBMSC_EPBULKOUT=4 : Use EP1 for the BULK OUT endpoint
+ CONFIG_USBMSC_EPBULKIN=5 : Use EP2 for the BULK IN endpoint
+ : Defaults for other settings?
+ Board Selection
+ CONFIG_SAM4EEK_AT25_BLOCKDEVICE=y : Export AT25 serial FLASH device
+ CONFIG_SAM4EEK_HSMCI_BLOCKDEVICE=n : Don't export HSMCI SD card
+
+ Note: If properly configured, you could export the HSMCI SD card instead
+ of the internal AT25 Serial FLASH.
+
+ The following setting enables an add-on that can can be used to control
+ the USB MSC device. It will add two new NSH commands:
+
+ a. msconn will connect the USB serial device and export the AT25
+ to the host, and
+ b. msdis which will disconnect the USB serial device.
+
+ Application Configuration -> System Add-Ons:
+ CONFIG_SYSTEM_USBMSC=y : Enable the USBMSC add-on
+ CONFIG_SYSTEM_USBMSC_NLUNS=1 : One LUN
+ CONFIG_SYSTEM_USBMSC_DEVMINOR1=0 : Minor device zero
+ CONFIG_SYSTEM_USBMSC_DEVPATH1="/dev/mtdblock0"
+ : Use a single, LUN: The AT25
+ : block driver.
+ NOTES:
+
+ a. To prevent file system corruption, make sure that the AT25 is un-
+ mounted *before* exporting the mass storage device to the host:
+
+ nsh> umount /mnt/at25
+ nsh> mscon
+
+ The AT25 can be re-mounted after the mass storage class is disconnected:
+
+ nsh> msdis
+ nsh> mount -t vfat /dev/mtdblock0 /mnt/at25
+
+ b. If you change the value CONFIG_SYSTEM_USBMSC_DEVPATH1, then you
+ can export other file systems:
+
+ "/dev/mmcsd0" would export the HSMCI SD slot
+
+ "/dev/ram0" could even be used to export a RAM disk. But you would
+ first have to use mkrd to create the RAM disk and mkfatfs to put
+ a FAT file system on it.
+
+ CDC/ACM Serial Device Class
+ ---------------------------
+
+ This will select the CDC/ACM serial device. Defaults for the other
+ options should be okay.
+
+ Device Drivers -> USB Device Driver Support
+ CONFIG_CDCACM=y : Enable the CDC/ACM device
+ CONFIG_CDCACM_BULKIN_REQLEN=96 : Default request size
+
+ The following setting enables an example that can can be used to control
+ the CDC/ACM device. It will add two new NSH commands:
+
+ a. sercon will connect the USB serial device (creating /dev/ttyACM0), and
+ b. serdis which will disconnect the USB serial device (destroying
+ /dev/ttyACM0).
+
+ Application Configuration -> Examples:
+ CONFIG_SYSTEM_CDCACM=y : Enable an CDC/ACM example
+
+ Debugging USB Device
+ --------------------
+
+ There is normal console debug output available that can be enabled with
+ CONFIG_DEBUG + CONFIG_DEBUG_USB. However, USB device operation is very
+ time critical and enabling this debug output WILL interfere with the
+ operation of the UDPHS. USB device tracing is a less invasive way to get
+ debug information: If tracing is enabled, the USB device will save
+ encoded trace output in in-memory buffer; if the USB monitor is also
+ enabled, that trace buffer will be periodically emptied and dumped to the
+ system logging device (the serial console in this configuration):
+
+ Device Drivers -> "USB Device Driver Support:
+ CONFIG_USBDEV_TRACE=y : Enable USB trace feature
+ CONFIG_USBDEV_TRACE_NRECORDS=256 : Buffer 256 records in memory
+ CONFIG_USBDEV_TRACE_STRINGS=y : (optional)
+
+ Application Configuration -> NSH LIbrary:
+ CONFIG_NSH_USBDEV_TRACE=n : No builtin tracing from NSH
+ CONFIG_NSH_ARCHINIT=y : Automatically start the USB monitor
+
+ Application Configuration -> System NSH Add-Ons:
+ CONFIG_SYSTEM_USBMONITOR=y : Enable the USB monitor daemon
+ CONFIG_SYSTEM_USBMONITOR_STACKSIZE=2048 : USB monitor daemon stack size
+ CONFIG_SYSTEM_USBMONITOR_PRIORITY=50 : USB monitor daemon priority
+ CONFIG_SYSTEM_USBMONITOR_INTERVAL=1 : Dump trace data every second
+ CONFIG_SYSTEM_USBMONITOR_TRACEINIT=y : Enable TRACE output
+ CONFIG_SYSTEM_USBMONITOR_TRACECLASS=y
+ CONFIG_SYSTEM_USBMONITOR_TRACETRANSFERS=y
+ CONFIG_SYSTEM_USBMONITOR_TRACECONTROLLER=y
+ CONFIG_SYSTEM_USBMONITOR_TRACEINTERRUPTS=y
+
+ NOTE: If USB debug output is also enabled, both outputs will appear on the
+ serial console. However, the debug output will be asynchronous with the
+ trace output and, hence, difficult to interpret.
+
SAM4E-EK-specific Configuration Options
=======================================
diff --git a/nuttx/configs/sam4e-ek/src/sam_hsmci.c b/nuttx/configs/sam4e-ek/src/sam_hsmci.c
index fe4858e3e..c8dcc7085 100644
--- a/nuttx/configs/sam4e-ek/src/sam_hsmci.c
+++ b/nuttx/configs/sam4e-ek/src/sam_hsmci.c
@@ -66,6 +66,7 @@
struct sam_hsmci_state_s
{
struct sdio_dev_s *hsmci; /* R/W device handle */
+ bool initialized; /* TRUE: HSMCI block driver is initialized */
bool inserted; /* TRUE: card is inserted */
};
@@ -129,42 +130,52 @@ int sam_hsmci_initialize(int minor)
{
int ret;
- /* Initialize card-detect GPIO. There is no write-protection GPIO. */
+ /* Have we already initialized? */
- sam_configpio(GPIO_MCI_CD);
+ if (!g_hsmci.initialized)
+ {
+ /* Initialize card-detect GPIO. There is no write-protection GPIO. */
- /* Mount the SDIO-based MMC/SD block driver */
- /* First, get an instance of the SDIO interface */
+ sam_configpio(GPIO_MCI_CD);
- g_hsmci.hsmci = sdio_initialize(0);
- if (!g_hsmci.hsmci)
- {
- fdbg("Failed to initialize SDIO\n");
- return -ENODEV;
- }
+ /* Mount the SDIO-based MMC/SD block driver */
+ /* First, get an instance of the SDIO interface */
- /* Now bind the SDIO interface to the MMC/SD driver */
+ g_hsmci.hsmci = sdio_initialize(0);
+ if (!g_hsmci.hsmci)
+ {
+ fdbg("Failed to initialize SDIO\n");
+ return -ENODEV;
+ }
- ret = mmcsd_slotinitialize(minor, g_hsmci.hsmci);
- if (ret != OK)
- {
- fdbg("Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
- return ret;
- }
+ /* Now bind the SDIO interface to the MMC/SD driver */
- /* Configure card detect interrupts */
+ ret = mmcsd_slotinitialize(minor, g_hsmci.hsmci);
+ if (ret != OK)
+ {
+ fdbg("Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
+ return ret;
+ }
- sam_pioirq(GPIO_MCI_CD);
- (void)irq_attach(MCI_CD_IRQ, sam_hsmci_cardetect);
+ /* Configure card detect interrupts */
- /* Then inform the HSMCI driver if there is or is not a card in the slot. */
+ sam_pioirq(GPIO_MCI_CD);
+ (void)irq_attach(MCI_CD_IRQ, sam_hsmci_cardetect);
- g_hsmci.inserted = sam_cardinserted(0);
- sdio_mediachange(g_hsmci.hsmci, g_hsmci.inserted);
+ /* Then inform the HSMCI driver if there is or is not a card in the slot. */
- /* Enable card detect interrupts */
+ g_hsmci.inserted = sam_cardinserted(0);
+ sdio_mediachange(g_hsmci.hsmci, g_hsmci.inserted);
+
+ /* Now we are initialized */
+
+ g_hsmci.initialized = true;
+
+ /* Enable card detect interrupts */
+
+ sam_pioirqenable(MCI_CD_IRQ);
+ }
- sam_pioirqenable(MCI_CD_IRQ);
return OK;
}
diff --git a/nuttx/configs/sam4e-ek/src/sam_usbmsc.c b/nuttx/configs/sam4e-ek/src/sam_usbmsc.c
index 63e653898..697ba0c86 100644
--- a/nuttx/configs/sam4e-ek/src/sam_usbmsc.c
+++ b/nuttx/configs/sam4e-ek/src/sam_usbmsc.c
@@ -50,7 +50,7 @@
#include "sam_hsmci.h"
-#ifdef CONFIG_SAM34_HSMCI
+#ifdef CONFIG_SAM34_UDP
/****************************************************************************
* Pre-Processor Definitions
@@ -67,6 +67,16 @@
#undef SAM_MMCSDSLOTNO
#define SAM_MMCSDSLOTNO 0
+/* Can't use a block device if it is not available */
+
+#ifndef HAVE_AT25
+# undef CONFIG_SAM4EEK_AT25_BLOCKDEVICE
+#endif
+
+#ifndef HAVE_HSMCI
+# undef CONFIG_SAM4EEK_HSMCI_BLOCKDEVICE
+#endif
+
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
@@ -101,48 +111,31 @@
int usbmsc_archinitialize(void)
{
- FAR struct sdio_dev_s *sdio;
- int ret;
+ /* Initialize the AT25 MTD driver */
- /* First, get an instance of the SDIO interface */
-
- message("usbmsc_archinitialize: "
- "Initializing SDIO slot %d\n",
- SAM_MMCSDSLOTNO);
-
- sdio = sdio_initialize(SAM_MMCSDSLOTNO);
- if (!sdio)
+#if defined(CONFIG_SAM4EEK_AT25_BLOCKDEVICE)
+ int ret = sam_at25_automount(0);
+ if (ret < 0)
{
- message("usbmsc_archinitialize: Failed to initialize SDIO slot %d\n",
- SAM_MMCSDSLOTNO);
- return -ENODEV;
+ message("ERROR: sam_at25_automount failed: %d\n", ret);
}
- /* Now bind the SPI interface to the MMC/SD driver */
+ return ret;
- message("usbmsc_archinitialize: "
- "Bind SDIO to the MMC/SD driver, minor=%d\n",
- CONFIG_SYSTEM_USBMSC_DEVMINOR1);
+#elif defined(CONFIG_SAM4EEK_HSMCI_BLOCKDEVICE)
+ /* Initialize the HSMCI driver */
- ret = mmcsd_slotinitialize(CONFIG_SYSTEM_USBMSC_DEVMINOR1, sdio);
- if (ret != OK)
+ ret = sam_hsmci_initialize(0);
+ if (ret < 0)
{
- message("usbmsc_archinitialize: "
- "Failed to bind SDIO to the MMC/SD driver: %d\n",
- ret);
- return ret;
+ message("ERROR: sam_hsmci_initialize(0) failed: %d\n", ret);
}
- message("usbmsc_archinitialize: "
- "Successfully bound SDIO to the MMC/SD driver\n");
-
- /* Then let's guess and say that there is a card in the slot. I need to check to
- * see if the SAM3U10E-EVAL board supports a GPIO to detect if there is a card in
- * the slot.
- */
+ return ret;
- sdio_mediachange(sdio, true);
- return OK;
+#else
+ return -ENODEV;
+#endif
}
-#endif /* CONFIG_SAM34_HSMCI */
+#endif /* CONFIG_SAM34_UDP */
diff --git a/nuttx/drivers/usbdev/usbdev_trace.c b/nuttx/drivers/usbdev/usbdev_trace.c
index c332c1358..f57cfbdc0 100644
--- a/nuttx/drivers/usbdev/usbdev_trace.c
+++ b/nuttx/drivers/usbdev/usbdev_trace.c
@@ -49,7 +49,7 @@
#undef usbtrace
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
@@ -173,6 +173,7 @@ void usbtrace(uint16_t event, uint16_t value)
usbtrace_trprintf((trprintf_t)lowsyslog, event, value);
#endif
}
+
irqrestore(flags);
}
#endif /* CONFIG_USBDEV_TRACE || CONFIG_DEBUG && CONFIG_DEBUG_USB */
diff --git a/nuttx/drivers/usbdev/usbdev_trprintf.c b/nuttx/drivers/usbdev/usbdev_trprintf.c
index f417c7e49..750de4d6f 100644
--- a/nuttx/drivers/usbdev/usbdev_trprintf.c
+++ b/nuttx/drivers/usbdev/usbdev_trprintf.c
@@ -46,7 +46,7 @@
#include <nuttx/usb/usbdev_trace.h>
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/****************************************************************************