9
0
Fork 0

Add support for use of a USB serial device to provide NSH console I/O. Verified on the Sure PIPIC32MX board

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4458 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-03-06 20:21:57 +00:00
parent 38977bb0c4
commit adcb07f98c
24 changed files with 1896 additions and 68 deletions

View File

@ -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.

View File

@ -59,6 +59,10 @@
# include <nuttx/usb/cdcacm.h>
#endif
#ifdef CONFIG_CDCACM
# include <nuttx/usb/pl2303.h>
#endif
#include "usbterm.h"
/****************************************************************************

View File

@ -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

View File

@ -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

View File

@ -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 */

View File

@ -39,7 +39,19 @@
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#ifdef CONFIG_CDCACM
# include <nuttx/usb/cdcacm.h>
#endif
#ifdef CONFIG_CDCACM
# include <nuttx/usb/pl2303.h>
#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)

View File

@ -2531,3 +2531,7 @@
include/nuttx into include/nuttx/net.
* arch/mips/src/pic32mx/pic32mx_usbdev.c: The PIC32 USB driver now appears to
be fully functional.
* configs/sure-pic32mx/usbnsh and configs/sure-pic32mx/src: Add support for
NSH using only USB serial I/O to support the console. This is useful on
devices that have USB, but no serial port.

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1>
<p>Last Updated: February 2, 2012</p>
<p>Last Updated: March 6, 2012</p>
</td>
</tr>
</table>
@ -2179,8 +2179,24 @@ nsh>
<tr>
<td valign="top"><b><code>CONFIG_NSH_CONSOLE</code></b></td>
<td>
If <code>CONFIG_NSH_CONSOLE</code> is set to <i>y</i>, then a serial
console front-end is selected.
<p>
If <code>CONFIG_NSH_CONSOLE</code> is set to <i>y</i>, then a serial
console front-end is selected.
</p>
<p>
Normally, the serial console device is a UART and RS-232 interface.
However, if <code>CONFIG_USBDEV</code> is defined, then a USB serial device may, instead, be used if the one of the following are defined:
</p>
<ul>
<li>
<code>CONFIG_PL2303</code> and <code>CONFIG_PL2303_CONSOLE</code>.
Sets up the Prolifics PL2303 emulation as a console device at <code>/dev/console</code>.
</li>
<li>
<code>CONFIG_CDCACM</code> and <code>CONFIG_CDCACM_CONSOLE</code>.
Sets up the CDC/ACM serial device as a console device at <code>/dev/console</code>.
</li>
</ul>
</td>
</tr>
<tr>

View File

@ -1,7 +1,7 @@
/************************************************************************************
* arch/mips/src/pic32mx/pic32mx-config.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -538,7 +538,7 @@
# define HAVE_UART_DEVICE 1
#endif
/* Is there a serial console? There should be at most one defined. It
/* Is there a serial console? There should be no more than one defined. It
* could be on any UARTn, n=1,.. CHIP_NUARTS
*/

View File

@ -1,8 +1,8 @@
/****************************************************************************
* arch/mips/src/pic32mx/pic32mx-head.S
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions

View File

@ -1,7 +1,7 @@
/************************************************************************************
* arch/mips/src/pic32mx/pic32mx-internal.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -181,7 +181,11 @@ EXTERN void pic32mx_lowinit(void);
*
************************************************************************************/
#ifdef HAVE_SERIAL_CONSOLE
EXTERN void pic32mx_consoleinit(void);
#else
# define pic32mx_consoleinit()
#endif
/******************************************************************************
* Name: pic32mx_uartreset

View File

@ -1,7 +1,7 @@
/******************************************************************************
* arch/mips/src/pic32mx/pic32mx-lowconsole.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -57,44 +57,46 @@
/* Select UART parameters for the selected console */
#if defined(CONFIG_UART1_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART1_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART1_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART1_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART1_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART1_2STOP
#elif defined(CONFIG_UART2_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART2_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART2_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART2_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART2_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART2_2STOP
#elif defined(CONFIG_UART3_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART3_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART3_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART3_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART3_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART3_2STOP
#elif defined(CONFIG_UART4_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART4_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART4_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART4_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART4_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART4_2STOP
#elif defined(CONFIG_UART5_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART5_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART5_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART5_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART5_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART5_2STOP
#elif defined(CONFIG_UART6_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART6_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART6_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART6_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART6_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART6_2STOP
#else
# error "No CONFIG_UARTn_SERIAL_CONSOLE Setting"
#ifdef HAVE_SERIAL_CONSOLE
# if defined(CONFIG_UART1_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART1_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART1_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART1_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART1_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART1_2STOP
# elif defined(CONFIG_UART2_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART2_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART2_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART2_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART2_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART2_2STOP
# elif defined(CONFIG_UART3_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART3_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART3_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART3_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART3_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART3_2STOP
# elif defined(CONFIG_UART4_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART4_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART4_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART4_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART4_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART4_2STOP
# elif defined(CONFIG_UART5_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART5_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART5_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART5_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART5_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART5_2STOP
# elif defined(CONFIG_UART6_SERIAL_CONSOLE)
# define PIC32MX_CONSOLE_BASE PIC32MX_UART6_K1BASE
# define PIC32MX_CONSOLE_BAUD CONFIG_UART6_BAUD
# define PIC32MX_CONSOLE_BITS CONFIG_UART6_BITS
# define PIC32MX_CONSOLE_PARITY CONFIG_UART6_PARITY
# define PIC32MX_CONSOLE_2STOP CONFIG_UART6_2STOP
# else
# error "No CONFIG_UARTn_SERIAL_CONSOLE Setting"
# endif
#endif
/******************************************************************************
@ -318,31 +320,32 @@ void pic32mx_uartconfigure(uintptr_t uart_base, uint32_t baudrate,
* Name: pic32mx_consoleinit
*
* Description:
* Initialize a console for debug output. This function is called very
* early in the intialization sequence to configure the serial console uart
* (only).
* Initialize a low-level console for debug output. This function is called
* very early in the intialization sequence to configure the serial console
* UART (only).
*
******************************************************************************/
#ifdef HAVE_SERIAL_CONSOLE
void pic32mx_consoleinit(void)
{
#ifdef HAVE_UART_DEVICE
pic32mx_uartconfigure(PIC32MX_CONSOLE_BASE, PIC32MX_CONSOLE_BAUD,
PIC32MX_CONSOLE_PARITY, PIC32MX_CONSOLE_BITS,
PIC32MX_CONSOLE_2STOP);
#endif
}
#endif
/******************************************************************************
* Name: up_lowputc
*
* Description:
* Output one byte on the serial console
* Output one byte on the serial console.
*
******************************************************************************/
void up_lowputc(char ch)
{
#ifdef HAVE_SERIAL_CONSOLE
/* Wait for the transmit buffer not full */
while ((pic32mx_getreg(PIC32MX_CONSOLE_BASE, PIC32MX_UART_STA_OFFSET) & UART_STA_UTXBF) != 0);
@ -350,5 +353,6 @@ void up_lowputc(char ch)
/* Then write the character to the TX data register */
pic32mx_putreg(PIC32MX_CONSOLE_BASE, PIC32MX_UART_TXREG_OFFSET, (uint32_t)ch);
#endif
}

View File

@ -488,3 +488,35 @@ Where <subdir> is one of the following:
examples/usbstorage - There are some hooks in the appconfig file
to enable the USB mass storage device. However, this device cannot
work until support for the SD card is also incorporated.
usbnsh
This is another NSH example. If differs from the 'nsh' configuration
above in that this configurations uses a USB serial device for console
I/O. This configuration was created to support the "DB-DP11212 PIC32
General Purpose Demo Board" which has no easily accessible serial port.
However, as of this writing, the configuration has set for the
"DB_DP11215 PIC32 Storage Demo Board" and has only be testing on that
board.
Below summarizes the key configuration differences between the 'nsh'
and the 'upnsh' configurations:
CONFIG_USBDEV=y : NuttX USB device support is enabled
CONFIG_PIC32MX_USBDEV=y : The PIC32MX USB device driver is built
CONFIG_UART1_SERIAL_CONSOLE=n : There is no serial console
CONFIG_UART2_SERIAL_CONSOLE=n :
CONFIG_CDCACM=y : The CDC/ACM serial device class is enabled
CONFIG_CDCACM_CONSOLE=y : The CDC/ACM serial device is the console
You could also use the non-standard PL2303 serial device instead of
the standard CDC/ACM serial device by changing:
CONFIG_CDCACM=y : Disable the CDC/ACM serial device class
CONFIG_CDCACM_CONSOLE=y : The CDC/ACM serial device is NOT the console
CONFIG_PL2303=y : The Prolifics PL2303 emulation is enabled
CONFIG_PL2303_CONSOLE=y : The PL2303 serial device is the console
Why would you want to use a non-standard USB serial driver? You might
to use the PL2303 driver with a Windows host because it should
automatically install the PL2303 driver (you might have to go through
some effort to get Windows to recognize the CDC/ACM device).

View File

@ -720,6 +720,8 @@ CONFIG_PL2303_TXBUFSIZE=512
#
# CONFIG_CDCACM
# Enable compilation of the USB serial driver
# CONFIG_CDCACM_CONSOLE
# Configures the CDC/ACM serial port as the console device.
# CONFIG_CDCACM_EP0MAXPACKET
# Endpoint 0 max packet size. Default 64
# CONFIG_CDCACM_EPINTIN
@ -765,6 +767,7 @@ CONFIG_PL2303_TXBUFSIZE=512
# Size of the serial receive/transmit buffers. Default 256.
#
CONFIG_CDCACM=n
CONFIG_CDCACM_CONSOLE=n
#CONFIG_CDCACM_EP0MAXPACKET
#CONFIG_CDCACM_EPINTIN
#CONFIG_CDCACM_EPINTIN_FSSIZE

View File

@ -1,7 +1,7 @@
############################################################################
# configs/sure-pic32mx/src/Makefile
#
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without

View File

@ -2,8 +2,8 @@
* config/sure-pic32mx/src/up_nsh.c
* arch/arm/src/board/up_nsh.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -246,7 +246,7 @@ errout:
* Name: nsh_usbhostinitialize
*
* Description:
* Initialize SPI-based microSD.
* Initialize USB Host
*
****************************************************************************/
@ -293,6 +293,28 @@ static int nsh_usbhostinitialize(void)
# define nsh_usbhostinitialize() (OK)
#endif
/****************************************************************************
* Name: nsh_usbdevinitialize
*
* Description:
* Initialize SPI-based microSD.
*
****************************************************************************/
#ifdef CONFIG_USBDEV
static int nsh_usbdevinitialize(void)
{
/* The Sure board has no way to know when the USB is connected. So we
* will fake it and tell the USB driver that the USB is connected now.
*/
pic32mx_usbattach();
return OK;
}
#else
# define nsh_usbdevinitialize() (OK)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -318,5 +340,12 @@ int nsh_archinitialize(void)
ret = nsh_usbhostinitialize();
}
if (ret == OK)
{
/* Initialize USB device */
ret = nsh_usbdevinitialize();
}
return ret;
}

View File

@ -1,6 +1,6 @@
/************************************************************************************
* configs/sure-pic32mx/src/up_usbdev.c
* arch/arm/src/board/up_usbdev.c
* configs/sure-pic32mx/src/up_usbterm.c
* arch/arm/src/board/up_usbterm.c
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -78,9 +78,14 @@ int usbterm_devinit(void)
{
/* The Sure board has no way to know when the USB is connected. So we
* will fake it and tell the USB driver that the USB is connected now.
*
* If examples/usbterm is built as an NSH built-in application, then
* pic32mx_usbattach() will be called in nsh_archinitialize().
*/
#ifndef CONFIG_EXAMPLES_USBTERM_BUILTIN
pic32mx_usbattach();
#endif
return OK;
}
@ -89,7 +94,7 @@ int usbterm_devinit(void)
*
* Description:
* If CONFIG_EXAMPLES_USBTERM_DEVINIT is defined, then the example will
* call this user provided function as part of its termination sequeunce.
* call this user provided function as part of its termination sequence.
*
****************************************************************************/

View File

@ -0,0 +1,160 @@
############################################################################
# configs/sure-pic32mx/usbnsh/Make.defs
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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_PIC32MX_MICROCHIPW),y)
# Microchip toolchain under Windows
CROSSDEV = pic32-
WINTOOL = y
MAXOPTIMIZATION = -O2
ARCHCPUFLAGS = -mprocessor=elf32pic32mx -mno-float -mlong32 -membedded-data
ARCHPICFLAGS = -fpic -membedded-pic
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_PIC32MX_MICROCHIPW_LITE),y)
# Microchip toolchain under Windows
CROSSDEV = pic32-
WINTOOL = y
# MAXOPTIMIZATION = -O2
ARCHCPUFLAGS = -mprocessor=elf32pic32mx -mno-float -mlong32 -membedded-data
ARCHPICFLAGS = -fpic -membedded-pic
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_PIC32MX_MICROCHIPL),y)
# Microchip toolchain under Linux
CROSSDEV = pic32-
MAXOPTIMIZATION = -O2
ARCHCPUFLAGS = -mprocessor=elf32pic32mx -mno-float -mlong32 -membedded-data
ARCHPICFLAGS = -fpic -membedded-pic
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_PIC32MX_MICROCHIPL_LITE),y)
# Microchip toolchain under Linux
CROSSDEV = pic32-
# MAXOPTIMIZATION = -O2
ARCHCPUFLAGS = -mprocessor=elf32pic32mx -mno-float -mlong32 -membedded-data
ARCHPICFLAGS = -fpic -membedded-pic
LDFLAGS += -nostartfiles -nodefaultlibs
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)/usbnsh/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)/usbnsh/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
ifeq ("${CONFIG_DEBUG_SYMBOLS}","y")
ARCHOPTIMIZATION = -g
else
ARCHOPTIMIZATION = $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
ARCHWARNINGSXX = -Wall -Wshadow
ARCHDEFINES =
CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES)
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 =
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 =

View File

@ -0,0 +1,47 @@
############################################################################
# configs/sure-pic32mx/usbnsh/appconfig
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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.
#
############################################################################
############################################################################
# Path to example in apps/examples containing the user_start entry point
############################################################################
CONFIGURED_APPS += examples/nsh
############################################################################
# The NSH application library
############################################################################
CONFIGURED_APPS += system/readline
CONFIGURED_APPS += nshlib

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,317 @@
/****************************************************************************
* configs/sure-pic32mx/usbnsh/ld.script
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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.
*
****************************************************************************/
/* Memory Regions ***********************************************************/
MEMORY
{
/* The PIC32MX440F512H has 512Kb of program FLASH at physical address
* 0x1d000000 but is always accessed at KSEG0 address 0x9d00:0000
*/
kseg0_progmem (rx) : ORIGIN = 0x9d000000, LENGTH = 512K
/* The PIC32MX440F512H has 12Kb of boot FLASH at physical address
* 0x1fc00000. The initial reset vector is in KSEG1, but all other
* accesses are in KSEG0.
*
* REGION PHYSICAL KSEG SIZE
* DESCRIPTION START ADDR (BYTES)
* ------------- ---------- ------ ----------------------
* Exceptions:*
* Reset 0x1fc00000 KSEG1 512 512
* TLB Refill 0x1fc00200 KSEG1 256 768
* Cache Error 0x1fc00300 KSEG1 128 896
* Others 0x1fc00380 KSEG1 128 1024 (1Kb)
* Interrupt 0x1fc00400 KSEG1 128 1152
* JTAG 0x1fc00480 KSEG1 16 1168
* Exceptions 0x1fc00490 KSEG0 8192-1168 8192 (4Kb)
* Debug code 0x1fc02000 KSEG1 4096-16 12272
* DEVCFG3-0 0x1fc02ff0 KSEG1 16 12288 (12Kb)
*
* Exceptions assume:
*
* STATUS: BEV=0/1 and EXL=0
* CAUSE: IV=1
* JTAG: ProbEn=0
* And multi-vector support disabled
*/
kseg1_reset (rx) : ORIGIN = 0xbfc00000, LENGTH = 384
kseg1_genexcpt (rx) : ORIGIN = 0xbfc00180, LENGTH = 128
kseg1_ebexcpt (rx) : ORIGIN = 0xbfc00200, LENGTH = 128
kseg1_bevexcpt (rx) : ORIGIN = 0xbfc00380, LENGTH = 128
kseg1_intexcpt (rx) : ORIGIN = 0xbfc00400, LENGTH = 128
kseg1_dbgexcpt (rx) : ORIGIN = 0xbfc00480, LENGTH = 16
kseg0_bootmem (rx) : ORIGIN = 0x9fc00490, LENGTH = 8192-1168
kseg1_dbgcode (rx) : ORIGIN = 0xbfc02000, LENGTH = 4096-16
kseg1_devcfg (r) : ORIGIN = 0xbfc02ff0, LENGTH = 16
/* The PIC32MX440F512H has 32Kb of data memory at physical address
* 0x00000000. Since the PIC32MX has no data cache, this memory is
* always accessed through KSEG1.
*
* When used with MPLAB, we need to set aside 512 bytes of memory
* for use by MPLAB.
*/
kseg1_datamem (w!x) : ORIGIN = 0xa0000200, LENGTH = 32K - 512
}
OUTPUT_FORMAT("elf32-tradlittlemips")
OUTPUT_ARCH(pic32mx)
ENTRY(__start)
SECTIONS
{
/* Boot FLASH sections */
.reset :
{
KEEP (*(.reset))
} > kseg1_reset
/* Exception handlers. The following is assumed:
*
* STATUS: BEV=1 and EXL=0
* CAUSE: IV=1
* JTAG: ProbEn=0
* And multi-vector support disabled
*
* In that configuration, the vector locations become:
*
* Reset, Soft Reset bfc0:0000
* TLB Refill bfc0:0200
* Cache Error bfc0:0300
* All others bfc0:0380
* Interrupt bfc0:0400
* EJTAG Debug bfc0:0480
*/
/* KSEG1 exception handler "trampolines" */
.gen_excpt :
{
KEEP (*(.gen_excpt))
} > kseg1_genexcpt
.ebase_excpt :
{
KEEP (*(.ebase_excpt))
} > kseg1_ebexcpt
.bev_excpt :
{
KEEP (*(.bev_excpt))
} > kseg1_bevexcpt
.int_excpt :
{
KEEP (*(.int_excpt))
} > kseg1_intexcpt
.dbg_excpt = ORIGIN(kseg1_dbgexcpt);
.start :
{
/* KSEG0 Reset startup logic */
*(.start)
/* KSEG0 exception handlers */
*(.nmi_handler)
*(.bev_handler)
*(.int_handler)
} > kseg0_bootmem
.dbg_code = ORIGIN(kseg1_dbgcode);
.devcfg :
{
KEEP (*(.devcfg))
} > kseg1_devcfg
/* Program FLASH sections */
.text :
{
_stext = ABSOLUTE(.);
*(.text .text.*)
*(.stub)
KEEP (*(.text.*personality*))
*(.gnu.linkonce.t.*)
*(.gnu.warning)
*(.mips16.fn.*)
*(.mips16.call.*)
/* Read-only data is included in the text section */
*(.rodata .rodata.*)
*(.rodata1)
*(.gnu.linkonce.r.*)
/* Small initialized constant global and static data */
*(.sdata2 .sdata2.*)
*(.gnu.linkonce.s2.*)
/* Uninitialized constant global and static data */
*(.sbss2 .sbss2.*)
*(.gnu.linkonce.sb2.*)
_etext = ABSOLUTE(.);
} > kseg0_progmem
/* Initialization data begins here in progmem */
_data_loaddr = LOADADDR(.data);
.eh_frame_hdr : { *(.eh_frame_hdr) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
/* RAM functions are positioned at the beginning of RAM so that
* they can be guaranteed to satisfy the 2Kb alignment requirement.
*/
/* This causes failures if there are no RAM functions
.ramfunc ALIGN(2K) :
{
_sramfunc = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfunc = ABSOLUTE(.);
} > kseg1_datamem AT > kseg0_progmem
_ramfunc_loadaddr = LOADADDR(.ramfunc);
_ramfunc_sizeof = SIZEOF(.ramfunc);
_bmxdkpba_address = _sramfunc - ORIGIN(kseg1_datamem) ;
_bmxdudba_address = LENGTH(kseg1_datamem) ;
_bmxdupba_address = LENGTH(kseg1_datamem) ;
*/
.data :
{
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
KEEP (*(.gnu.linkonce.d.*personality*))
*(.data1)
} > kseg1_datamem AT > kseg0_progmem
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
_gp = ALIGN(16) + 0x7FF0 ;
.got :
{
*(.got.plt) *(.got)
} > kseg1_datamem AT > kseg0_progmem
.sdata :
{
*(.sdata .sdata.* .gnu.linkonce.s.*)
} > kseg1_datamem AT > kseg0_progmem
.lit8 :
{
*(.lit8)
} > kseg1_datamem AT > kseg0_progmem
.lit4 :
{
*(.lit4)
_edata = ABSOLUTE(.);
} >kseg1_datamem AT>kseg0_progmem
.sbss :
{
_sbss = ABSOLUTE(.);
*(.dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
} >kseg1_datamem
.bss :
{
*(.dynbss)
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
_ebss = ABSOLUTE(.);
} > kseg1_datamem
/* 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) }
/* DWARF debug sections */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/DISCARD/ : { *(.note.GNU-stack) }
}

View File

@ -0,0 +1,61 @@
#!/bin/bash
# configs/sure-pic32mx/usbnsh/setenv.sh
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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 [ "$_" = "$0" ] ; 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`
if [ ! -x "setenv.sh" ]; then
echo "This script must be executed from the top-level NuttX build directory"
exit 1
fi
# This the Cygwin path to the location where I installed the MicroChip
# PIC32MX toolchain under windows. This is *not* the default install
# location so you will probably have to edit this. You will also have
# to edit this if you install a different version of if you install
# the Linux PIC32MX toolchain as well
export TOOLCHAIN_BIN="/cygdrive/c/MicroChip/mplabc32/v1.12/bin"
# This is the path to the toosl subdirectory
export PIC32TOOL_DIR="${WD}/configs/sure-pic32mx/tools"
# Add the path to the toolchain to the PATH varialble
export PATH="${TOOLCHAIN_BIN}:${PIC32TOOL_DIR}:/sbin:/usr/sbin:${PATH_ORIG}"
echo "PATH : ${PATH}"

View File

@ -2046,8 +2046,8 @@ int cdcacm_classobject(int minor, FAR struct usbdevclass_driver_s **classdev)
/* Register the USB serial console */
#ifdef CONFIG_CDCACM_CONSOLE
g_usbserialport.isconsole = true;
ret = uart_register("/dev/console", &pri->serdev);
priv->serdev.isconsole = true;
ret = uart_register("/dev/console", &priv->serdev);
if (ret < 0)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_CONSOLEREGISTER), (uint16_t)-ret);

View File

@ -2203,8 +2203,8 @@ int usbdev_serialinitialize(int minor)
/* Register the USB serial console */
#ifdef CONFIG_PL2303_CONSOLE
g_pl2303ialport.isconsole = true;
ret = uart_register("/dev/console", &pri->serdev);
priv->serdev.isconsole = true;
ret = uart_register("/dev/console", &priv->serdev);
if (ret < 0)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_CONSOLEREGISTER), (uint16_t)-ret);