summaryrefslogtreecommitdiff
path: root/apps/examples
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-29 21:53:28 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-29 21:53:28 +0000
commit5faa1bd9cefb4e7a2319faaa5b36da9140aba16a (patch)
tree358673f55511cec814532fbf08a11847936c38cf /apps/examples
parent286b14b0c9d2dbad599e80cac9c269c9cd96b408 (diff)
downloadnuttx-5faa1bd9cefb4e7a2319faaa5b36da9140aba16a.tar.gz
nuttx-5faa1bd9cefb4e7a2319faaa5b36da9140aba16a.tar.bz2
nuttx-5faa1bd9cefb4e7a2319faaa5b36da9140aba16a.zip
A little more work (but not much progress) on the PIC32 USB device driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4440 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples')
-rw-r--r--apps/examples/README.txt34
-rw-r--r--apps/examples/cdcacm/cdcacm.h42
-rw-r--r--apps/examples/cdcacm/cdcacm_main.c15
-rw-r--r--apps/examples/composite/composite.h2
-rw-r--r--apps/examples/usbserial/host.c6
-rw-r--r--apps/examples/usbserial/main.c18
-rw-r--r--apps/examples/usbterm/usbterm.h6
-rw-r--r--apps/examples/usbterm/usbterm_main.c8
8 files changed, 113 insertions, 18 deletions
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index fb947cd71..86edc6e33 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -132,6 +132,28 @@ examples/cdcacm
CONFIG_EXAMPLES_CDCACM_DEVMINOR : The minor number of the CDC/ACM device.
: i.e., the 'x' in /dev/ttyACMx
+ If CONFIG_USBDEV_TRACE is enabled (or CONFIG_DEBUG and CONFIG_DEBUG_USB, or
+ CONFIG_USBDEV_TRACE), then the example code will also initialize the USB trace
+ output. The amount of trace output can be controlled using:
+
+ CONFIG_EXAMPLES_CDCACM_TRACEINIT
+ Show initialization events
+ CONFIG_EXAMPLES_CDCACM_TRACECLASS
+ Show class driver events
+ CONFIG_EXAMPLES_CDCACM_TRACETRANSFERS
+ Show data transfer events
+ CONFIG_EXAMPLES_CDCACM_TRACECONTROLLER
+ Show controller events
+ CONFIG_EXAMPLES_CDCACM_TRACEINTERRUPTS
+ Show interrupt-related events.
+
+ Note: This example is only enables or disable USB CDC/ACM via the NSH
+ 'sercon' and 'serdis' command. It will enable and disable tracing per
+ the settings before enabling and after disabling the CDC/ACM device. It
+ will not, however, monitor buffered trace data in the interim. If
+ CONFIG_USBDEV_TRACE is defined (and the debug options are not), other
+ application logic will need to monitor the buffered trace data.
+
examples/composite
^^^^^^^^^^^^^^^^^^
@@ -188,9 +210,10 @@ examples/composite
CONFIG_EXAMPLES_COMPOSITE_BUFLEN. Default 256.
CONFIG_EXAMPLES_COMPOSITE_TTYUSB - The minor number of the USB serial device.
- Default is zero (corresponding to /dev/ttyUSB0. Default is zero.
+ Default is zero (corresponding to /dev/ttyUSB0 or /dev/ttyACM0). Default is zero.
CCONFIG_EXAMPLES_COMPOSITE_SERDEV - The string corresponding to
- CONFIG_EXAMPLES_COMPOSITE_TTYUSB. The default is "/dev/ttyUSB0".
+ CONFIG_EXAMPLES_COMPOSITE_TTYUSB. The default is "/dev/ttyUSB0" (for the PL2303
+ emulation) or "/dev/ttyACM0" (for the CDC/ACM serial device).
CONFIG_EXAMPLES_COMPOSITE_BUFSIZE - The size of the serial I/O buffer in
bytes. Default 256 bytes.
@@ -1274,7 +1297,8 @@ examples/usbserial
At the end of the dmesg output, you should see the serial
device was successfully idenfied and assigned to a tty device,
- probably /dev/ttyUSB0.
+ probably /dev/ttyUSB0 or /dev/ttyACM0 (depending on the configured
+ USB serial driver).
3. Then start the host application:
@@ -1282,7 +1306,9 @@ examples/usbserial
Where:
- <tty-dev> is the USB TTY device to use. The default is /dev/ttyUSB0.
+ <tty-dev> is the USB TTY device to use. The default is
+ "/dev/ttyUSB0" (for the PL2303 emulation) or "/dev/ttyACM0" (for
+ the CDC/ACM serial device).
The host and target will exchange are variety of very small and very large
serial messages.
diff --git a/apps/examples/cdcacm/cdcacm.h b/apps/examples/cdcacm/cdcacm.h
index 60eada896..ce40e1a93 100644
--- a/apps/examples/cdcacm/cdcacm.h
+++ b/apps/examples/cdcacm/cdcacm.h
@@ -41,12 +41,14 @@
****************************************************************************/
#include <nuttx/config.h>
+
#include <stdlib.h>
+#include <nuttx/usb/usbdev_trace.h>
+
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
-
/* Configuration ************************************************************/
/* Prerequisites */
@@ -68,6 +70,44 @@
# define CONFIG_EXAMPLES_CDCACM_DEVMINOR 0
#endif
+/* Trace Configuration ******************************************************/
+
+#ifdef CONFIG_EXAMPLES_CDCACM_TRACEINIT
+# define TRACE_INIT_BITS (TRACE_INIT_BIT)
+#else
+# define TRACE_INIT_BITS (0)
+#endif
+
+#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT)
+
+#ifdef CONFIG_EXAMPLES_CDCACM_TRACECLASS
+# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT)
+#else
+# define TRACE_CLASS_BITS (0)
+#endif
+
+#ifdef CONFIG_EXAMPLES_CDCACM_TRACETRANSFERS
+# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|TRACE_READ_BIT|\
+ TRACE_WRITE_BIT|TRACE_COMPLETE_BIT)
+#else
+# define TRACE_TRANSFER_BITS (0)
+#endif
+
+#ifdef CONFIG_EXAMPLES_CDCACM_TRACECONTROLLER
+# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT)
+#else
+# define TRACE_CONTROLLER_BITS (0)
+#endif
+
+#ifdef CONFIG_EXAMPLES_CDCACM_TRACEINTERRUPTS
+# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|TRACE_INTEXIT_BIT)
+#else
+# define TRACE_INTERRUPT_BITS (0)
+#endif
+
+#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|TRACE_CLASS_BITS|\
+ TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS)
+
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
diff --git a/apps/examples/cdcacm/cdcacm_main.c b/apps/examples/cdcacm/cdcacm_main.c
index 94afe3a58..aeb7a9e74 100644
--- a/apps/examples/cdcacm/cdcacm_main.c
+++ b/apps/examples/cdcacm/cdcacm_main.c
@@ -81,7 +81,6 @@ struct cdcacm_state_s g_cdcacm;
int sercon_main(int argc, char *argv[])
{
- FAR void *handle;
int ret;
/* Check if there is a non-NULL USB mass storage device handle (meaning that the
@@ -94,7 +93,13 @@ int sercon_main(int argc, char *argv[])
return EXIT_FAILURE;
}
- /* Initialize the USB serial driver */
+ /* Then, in any event, enable trace data collection as configured BEFORE
+ * enabling the CDC/ACM device.
+ */
+
+ usbtrace_enable(TRACE_BITSET);
+
+ /* Initialize the USB CDC/ACM serial driver */
message("sercon: Registering CDC/ACM serial driver\n");
ret = cdcacm_initialize(CONFIG_EXAMPLES_CDCACM_DEVMINOR, &g_cdcacm.handle);
@@ -127,6 +132,12 @@ int serdis_main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ /* Then, in any event, disable trace data collection as configured BEFORE
+ * enabling the CDC/ACM device.
+ */
+
+ usbtrace_enable(0);
+
/* Then disconnect the device and uninitialize the USB mass storage driver */
cdcacm_uninitialize(g_cdcacm.handle);
diff --git a/apps/examples/composite/composite.h b/apps/examples/composite/composite.h
index 48e4b155f..fab498c9f 100644
--- a/apps/examples/composite/composite.h
+++ b/apps/examples/composite/composite.h
@@ -120,6 +120,8 @@
#ifndef CONFIG_EXAMPLES_COMPOSITE_SERDEV
# if CONFIG_EXAMPLES_COMPOSITE_TTYUSB != 0
# error "Serial device unknown (CONFIG_EXAMPLES_COMPOSITE_SERDEV)"
+# elif defined(CONFIG_CDCACM)
+# define CONFIG_EXAMPLES_COMPOSITE_SERDEV "/dev/ttyACM0"
# else
# define CONFIG_EXAMPLES_COMPOSITE_SERDEV "/dev/ttyUSB0"
# endif
diff --git a/apps/examples/usbserial/host.c b/apps/examples/usbserial/host.c
index 751b7530c..dfa288f44 100644
--- a/apps/examples/usbserial/host.c
+++ b/apps/examples/usbserial/host.c
@@ -66,7 +66,11 @@
# endif
#endif
-#define DEFAULT_TTYDEV "/dev/ttyUSB0"
+#ifdef CONFIG_CDCACM
+# define DEFAULT_TTYDEV "/dev/ttyACM0"
+#else
+# define DEFAULT_TTYDEV "/dev/ttyUSB0"
+#endif
#define BUFFER_SIZE 1024
/****************************************************************************
diff --git a/apps/examples/usbserial/main.c b/apps/examples/usbserial/main.c
index 7ad9d0d9c..eea905c98 100644
--- a/apps/examples/usbserial/main.c
+++ b/apps/examples/usbserial/main.c
@@ -125,6 +125,12 @@
# endif
#endif
+#ifdef CONFIG_CDCACM
+# define USBSER_DEVNAME "/dev/ttyACM0"
+#else
+# define USBSER_DEVNAME "/dev/ttyUSB0"
+#endif
+
#define IOBUFFER_SIZE 256
/****************************************************************************
@@ -246,11 +252,11 @@ int user_start(int argc, char *argv[])
do
{
message("user_start: Opening USB serial driver\n");
- outfd = open("/dev/ttyUSB0", O_WRONLY);
+ outfd = open(USBSER_DEVNAME, O_WRONLY);
if (outfd < 0)
{
int errcode = errno;
- message("user_start: ERROR: Failed to open /dev/ttyUSB0 for writing: %d\n", errcode);
+ message("user_start: ERROR: Failed to open " USBSER_DEVNAME " for writing: %d\n", errcode);
/* ENOTCONN means that the USB device is not yet connected */
@@ -279,21 +285,21 @@ int user_start(int argc, char *argv[])
#ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY
#ifndef CONFIG_EXAMPLES_USBSERIAL_OUTONLY
- infd = open("/dev/ttyUSB0", O_RDONLY|O_NONBLOCK);
+ infd = open(USBSER_DEVNAME, O_RDONLY|O_NONBLOCK);
if (infd < 0)
{
- message("user_start: ERROR: Failed to open /dev/ttyUSB0 for reading: %d\n", errno);
+ message("user_start: ERROR: Failed to open " USBSER_DEVNAME " for reading: %d\n", errno);
close(outfd);
return 3;
}
#else
do
{
- infd = open("/dev/ttyUSB0", O_RDONLY|O_NONBLOCK);
+ infd = open(USBSER_DEVNAME, O_RDONLY|O_NONBLOCK);
if (infd < 0)
{
int errcode = errno;
- message("user_start: ERROR: Failed to open /dev/ttyUSB0 for reading: %d\n", errno);
+ message("user_start: ERROR: Failed to open " USBSER_DEVNAME " for reading: %d\n", errno);
/* ENOTCONN means that the USB device is not yet connected */
diff --git a/apps/examples/usbterm/usbterm.h b/apps/examples/usbterm/usbterm.h
index 1dc2085dd..a889c886d 100644
--- a/apps/examples/usbterm/usbterm.h
+++ b/apps/examples/usbterm/usbterm.h
@@ -91,6 +91,12 @@
#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|TRACE_CLASS_BITS|\
TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS)
+#ifdef CONFIG_CDCACM
+# define USBTERM_DEVNAME "/dev/ttyACM0"
+#else
+# define USBTERM_DEVNAME "/dev/ttyUSB0"
+#endif
+
/* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
diff --git a/apps/examples/usbterm/usbterm_main.c b/apps/examples/usbterm/usbterm_main.c
index 5bad8fffe..ba723e91b 100644
--- a/apps/examples/usbterm/usbterm_main.c
+++ b/apps/examples/usbterm/usbterm_main.c
@@ -229,11 +229,11 @@ int MAIN_NAME(int argc, char *argv[])
{
message(MAIN_STRING "Opening USB serial driver\n");
- g_usbterm.outstream = fopen("/dev/ttyUSB0", "w");
+ g_usbterm.outstream = fopen(USBTERM_DEVNAME, "w");
if (g_usbterm.outstream == NULL)
{
int errcode = errno;
- message(MAIN_STRING "ERROR: Failed to open /dev/ttyUSB0 for writing: %d\n",
+ message(MAIN_STRING "ERROR: Failed to open " USBTERM_DEVNAME " for writing: %d\n",
errcode);
/* ENOTCONN means that the USB device is not yet connected */
@@ -261,10 +261,10 @@ int MAIN_NAME(int argc, char *argv[])
* should not fail.
*/
- g_usbterm.instream = fopen("/dev/ttyUSB0", "r");
+ g_usbterm.instream = fopen(USBTERM_DEVNAME, "r");
if (g_usbterm.instream == NULL)
{
- message(MAIN_STRING "ERROR: Failed to open /dev/ttyUSB0 for reading: %d\n", errno);
+ message(MAIN_STRING "ERROR: Failed to open " USBTERM_DEVNAME " for reading: %d\n", errno);
goto errout_with_outstream;
}