From 2cb26d0787b41ae1dc7607ef11ac11047491d7dc Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 6 Mar 2012 20:21:57 +0000 Subject: Add support for use of a USB serial device to provide NSH console I/O. Verified on the Sure PIPIC32MX board git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4458 42af7a65-404d-4744-a932-0658087f49c3 --- apps/ChangeLog.txt | 2 ++ apps/examples/usbterm/usbterm_main.c | 4 ++++ apps/nshlib/Makefile | 2 +- apps/nshlib/README.txt | 13 +++++++++++++ apps/nshlib/nsh_consolemain.c | 3 ++- apps/nshlib/nsh_usbdev.c | 25 +++++++++++++++++++++++-- 6 files changed, 45 insertions(+), 4 deletions(-) (limited to 'apps') diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 8317f2532..a24e0f1a0 100755 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -200,3 +200,5 @@ may to connected and disconnected through software control. * apps/examples/nsh/nsh_main.c: If available, call up_cxxinitialize() to initialize all statically defined C++ classes. + * apps/nshlib: Now supports a USB serial device for NSH console I/O. This + allows NSH to be used on boards that have USB but no serial connectors. diff --git a/apps/examples/usbterm/usbterm_main.c b/apps/examples/usbterm/usbterm_main.c index b1b6dc34a..6e8e68412 100644 --- a/apps/examples/usbterm/usbterm_main.c +++ b/apps/examples/usbterm/usbterm_main.c @@ -59,6 +59,10 @@ # include #endif +#ifdef CONFIG_CDCACM +# include +#endif + #include "usbterm.h" /**************************************************************************** diff --git a/apps/nshlib/Makefile b/apps/nshlib/Makefile index cbe1c8201..ba162a086 100644 --- a/apps/nshlib/Makefile +++ b/apps/nshlib/Makefile @@ -71,7 +71,7 @@ ifneq ($(CONFIG_NSH_DISABLESCRIPT),y) CSRCS += nsh_test.c endif -ifneq ($(CONFIG_USBDEV),y) +ifeq ($(CONFIG_USBDEV),y) CSRCS += nsh_usbdev.c endif diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index bc496135d..5c29d75bb 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -903,6 +903,19 @@ NSH-Specific Configuration Settings If CONFIG_NSH_CONSOLE is set to 'y', then a serial console front-end is selected. + Normally, the serial console device is a UART and RS-232 + interface. However, if CONFIG_USBDEV is defined, then a USB + serial device may, instead, be used if the one of + the following are defined: + + CONFIG_PL2303 and CONFIG_PL2303_CONSOLE - Sets up the + Prolifics PL2303 emulation as a console device + at /dev/console. + + CONFIG_CDCACM and CONFIG_CDCACM_CONSOLE - Sets up the + CDC/ACM serial device as a console device at + dev/console. + * CONFIG_NSH_CONDEV If CONFIG_NSH_CONSOLE is set to 'y', then CONFIG_NSH_CONDEV may also be set to select the serial device used to support diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c index 372ef5a1f..36ffdab8f 100644 --- a/apps/nshlib/nsh_consolemain.c +++ b/apps/nshlib/nsh_consolemain.c @@ -105,7 +105,8 @@ int nsh_consolemain(int argc, char *argv[]) */ #ifdef HAVE_USB_CONSOLE - DEBUGASSERT(nsh_usbconsole() == OK); + ret = nsh_usbconsole(); + DEBUGASSERT(ret == OK); #endif /* Present a greeting */ diff --git a/apps/nshlib/nsh_usbdev.c b/apps/nshlib/nsh_usbdev.c index c8115bfc7..a784c6b77 100644 --- a/apps/nshlib/nsh_usbdev.c +++ b/apps/nshlib/nsh_usbdev.c @@ -39,7 +39,19 @@ #include +#include #include +#include +#include +#include + +#ifdef CONFIG_CDCACM +# include +#endif + +#ifdef CONFIG_CDCACM +# include +#endif #include "nsh.h" @@ -80,8 +92,8 @@ #ifdef HAVE_USB_CONSOLE int nsh_usbconsole(void) { - int errval; int fd; + int ret; /* Don't start the NSH console until the console device is ready. Chances * are, we get here with no functional console. The USB console will not @@ -89,6 +101,15 @@ int nsh_usbconsole(void) * host-side application opens the connection. */ + /* Initialize the USB serial driver */ + +#ifdef CONFIG_CDCACM + ret = cdcacm_initialize(0, NULL); +#else + ret = usbdev_serialinitialize(0); +#endif + DEBUGASSERT(ret == OK); + /* Make sure the stdin, stdout, and stderr are closed */ (void)fclose(stdin); @@ -131,7 +152,7 @@ int nsh_usbconsole(void) } /* fdopen to get the stdin, stdout and stderr streams. The following logic depends - * on the fact that the library* layer will allocate FILEs in order. And since + * on the fact that the library layer will allocate FILEs in order. And since * we closed stdin, stdout, and stderr above, that is what we should get. * * fd = 0 is stdin (read-only) -- cgit v1.2.3