Misc SYSLOG and STM32 serial fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5576 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
40717da192
commit
328b6d41a0
11
ChangeLog
11
ChangeLog
@ -4057,4 +4057,13 @@
|
||||
Serial was driver was not being built if there is no console
|
||||
device. Obviously, the serial driver may be needed even in
|
||||
this case.
|
||||
|
||||
* arch/arm/src/stm32/stm32_serial.c: If there is a serial console,
|
||||
it would be ttyS0 and the others would be ttyS1-5. If there
|
||||
is not serial console, was labeling them ttyS1-6; now labels them
|
||||
ttyS0-5.
|
||||
* fs/fs_syslog.c: Can't handle SYSLOG output to character device from
|
||||
the IDLE task (because it can't block). syslog_putc now returns EOF
|
||||
on failure and sets errno. Fixed some errors in error handling.
|
||||
* libc/stdio/lib_syslogstream.c: Checking of return value from
|
||||
syslog_putc was bogus. Switching to EOF for all errors solves
|
||||
this.
|
||||
|
@ -1998,7 +1998,8 @@ void up_serialinit(void)
|
||||
{
|
||||
#ifdef HAVE_UART
|
||||
char devname[16];
|
||||
unsigned i, j;
|
||||
unsigned i;
|
||||
unsigned minor = 0;
|
||||
#ifdef CONFIG_PM
|
||||
int ret;
|
||||
#endif
|
||||
@ -2015,6 +2016,7 @@ void up_serialinit(void)
|
||||
#if CONSOLE_UART > 0
|
||||
(void)uart_register("/dev/console", &uart_devs[CONSOLE_UART - 1]->dev);
|
||||
(void)uart_register("/dev/ttyS0", &uart_devs[CONSOLE_UART - 1]->dev);
|
||||
minor = 1;
|
||||
|
||||
/* If we need to re-initialise the console to enable DMA do that here. */
|
||||
|
||||
@ -2028,19 +2030,19 @@ void up_serialinit(void)
|
||||
|
||||
strcpy(devname, "/dev/ttySx");
|
||||
|
||||
for (i = 0, j = 1; i < STM32_NUSART; i++)
|
||||
for (i = 0; i < STM32_NUSART; i++)
|
||||
{
|
||||
|
||||
/* don't create a device for the console - we did that above */
|
||||
/* Don't create a device for the console - we did that above */
|
||||
|
||||
if ((uart_devs[i] == 0) || (uart_devs[i]->dev.isconsole))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* register USARTs as devices in increasing order */
|
||||
/* Register USARTs as devices in increasing order */
|
||||
|
||||
devname[9] = '0' + j++;
|
||||
devname[9] = '0' + minor++;
|
||||
(void)uart_register(devname, &uart_devs[i]->dev);
|
||||
}
|
||||
#endif /* HAVE UART */
|
||||
|
@ -1254,40 +1254,10 @@ Where <subdir> is one of the following:
|
||||
CONFIG_CDCACM=y : The CDC/ACM driver must be built
|
||||
CONFIG_CDCACM_CONSOLE=y : Enable the CDC/ACM USB console.
|
||||
|
||||
However, that configuration does not work. It fails early probably because
|
||||
of some dependency on /dev/console before the USB connection is established.
|
||||
|
||||
But there is a work around for this that works better (but has some side
|
||||
effects). The following configuration will also create a NSH USB console
|
||||
but this version will will use /dev/console. Instead, it will use the
|
||||
normal /dev/ttyACM0 USB serial device for the console:
|
||||
|
||||
CONFIG_STM32_OTGFS=y : STM32 OTG FS support
|
||||
CONFIG_USART2_SERIAL_CONSOLE=n : Disable the USART2 console
|
||||
CONFIG_USBDEV=y : USB device support must be enabled
|
||||
CONFIG_CDCACM=y : The CDC/ACM driver must be built
|
||||
CONFIG_CDCACM_CONSOLE=n : Don't use the CDC/ACM USB console.
|
||||
CONFIG_NSH_USBCONSOLE=y : Instead use some other USB device for the console
|
||||
|
||||
The particular USB device that is used is:
|
||||
|
||||
CONFIG_NSH_USBCONDEV="/dev/ttyACM0"
|
||||
|
||||
NOTE 1: When you first start the USB console, you have hit ENTER a few
|
||||
NOTE: When you first start the USB console, you have hit ENTER a few
|
||||
times before NSH starts. The logic does this to prevent sending USB data
|
||||
before there is anything on the host side listening for USB serial input.
|
||||
|
||||
Now the side effects:
|
||||
|
||||
NOTE 2. When any other device other than /dev/console is used for a user
|
||||
interface, linefeeds (\n) will not be expanded to carriage return /
|
||||
linefeeds (\r\n). You will need to set your terminal program to account
|
||||
for this.
|
||||
|
||||
NOTE 3: /dev/console still exists and still refers to the serial port. So
|
||||
you can still use certain kinds of debug output (see include/debug.h, all
|
||||
of the interfaces based on lib_lowprintf will work in this configuration).
|
||||
|
||||
9. USB OTG FS Host Support. The following changes will enable support for
|
||||
a USB host on the STM32F4Discovery, including support for a mass storage
|
||||
class driver:
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <semaphore.h>
|
||||
@ -282,7 +283,7 @@ int syslog_initialize(void)
|
||||
if (!INODE_IS_DRIVER(inode))
|
||||
#endif
|
||||
{
|
||||
ret = ENXIO;
|
||||
ret = -ENXIO;
|
||||
goto errout_with_inode;
|
||||
}
|
||||
|
||||
@ -290,7 +291,7 @@ int syslog_initialize(void)
|
||||
|
||||
if (!inode->u.i_ops || !inode->u.i_ops->write)
|
||||
{
|
||||
return -EACCES;
|
||||
ret = -EACCES;
|
||||
goto errout_with_inode;
|
||||
}
|
||||
|
||||
@ -346,8 +347,8 @@ int syslog_initialize(void)
|
||||
return OK;
|
||||
|
||||
errout_with_inode:
|
||||
g_sysdev.sl_state = SYSLOG_FAILURE;
|
||||
inode_release(inode);
|
||||
g_sysdev.sl_state = SYSLOG_FAILURE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -366,6 +367,8 @@ int syslog_initialize(void)
|
||||
int syslog_putc(int ch)
|
||||
{
|
||||
ssize_t nbytes;
|
||||
uint8_t uch;
|
||||
int errcode;
|
||||
int ret;
|
||||
|
||||
/* Ignore any output:
|
||||
@ -382,7 +385,10 @@ int syslog_putc(int ch)
|
||||
* (4) Any debug output generated from interrupt handlers. A disadvantage
|
||||
* of using the generic character device for the SYSLOG is that it
|
||||
* cannot handle debug output generated from interrupt level handlers.
|
||||
* (5) If an irrecoverable failure occurred during initialization. In
|
||||
* (5) Any debug output generated from the IDLE loop. The character
|
||||
* driver interface is blocking and the IDLE thread is not permitted
|
||||
* to block.
|
||||
* (6) If an irrecoverable failure occurred during initialization. In
|
||||
* this case, we won't ever bother to try again (ever).
|
||||
*
|
||||
* NOTE: That the third case is different. It applies only to the thread
|
||||
@ -390,11 +396,12 @@ int syslog_putc(int ch)
|
||||
* that is why that case is handled in syslog_semtake().
|
||||
*/
|
||||
|
||||
/* Case (4) */
|
||||
/* Cases (4) and (5) */
|
||||
|
||||
if (up_interrupt_context())
|
||||
if (up_interrupt_context() || getpid() == 0)
|
||||
{
|
||||
return -ENOSYS; /* Not supported */
|
||||
errcode = ENOSYS;
|
||||
goto errout_with_errcode;
|
||||
}
|
||||
|
||||
/* We can save checks in the usual case: That after the SYSLOG device
|
||||
@ -408,14 +415,16 @@ int syslog_putc(int ch)
|
||||
if (g_sysdev.sl_state == SYSLOG_UNINITIALIZED ||
|
||||
g_sysdev.sl_state == SYSLOG_INITIALIZING)
|
||||
{
|
||||
return -EAGAIN; /* Can't access the SYSLOG now... maybe next time? */
|
||||
errcode = EAGAIN; /* Can't access the SYSLOG now... maybe next time? */
|
||||
goto errout_with_errcode;
|
||||
}
|
||||
|
||||
/* Case (5) */
|
||||
/* Case (6) */
|
||||
|
||||
if (g_sysdev.sl_state == SYSLOG_FAILURE)
|
||||
{
|
||||
return -ENXIO; /* There is no SYSLOG device */
|
||||
errcode = ENXIO; /* There is no SYSLOG device */
|
||||
goto errout_with_errcode;
|
||||
}
|
||||
|
||||
/* syslog_initialize() is called as soon as enough of the operating
|
||||
@ -443,7 +452,8 @@ int syslog_putc(int ch)
|
||||
if (ret < 0)
|
||||
{
|
||||
sched_unlock();
|
||||
return ret;
|
||||
errcode = -ret;
|
||||
goto errout_with_errcode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,7 +481,8 @@ int syslog_putc(int ch)
|
||||
* way, we are outta here.
|
||||
*/
|
||||
|
||||
return ret;
|
||||
errcode = -ret;
|
||||
goto errout_with_errcode;
|
||||
}
|
||||
|
||||
/* Pre-pend a newline with a carriage return. */
|
||||
@ -497,19 +508,27 @@ int syslog_putc(int ch)
|
||||
{
|
||||
/* Write the non-newline character (and don't flush) */
|
||||
|
||||
nbytes = syslog_write(&ch, 1);
|
||||
uch = (uint8_t)ch;
|
||||
nbytes = syslog_write(&uch, 1);
|
||||
}
|
||||
|
||||
syslog_givesem();
|
||||
|
||||
/* Check if the write was successful */
|
||||
/* Check if the write was successful. If not, nbytes will be
|
||||
* a negated errno value.
|
||||
*/
|
||||
|
||||
if (nbytes < 0)
|
||||
{
|
||||
return nbytes;
|
||||
errcode = -ret;
|
||||
goto errout_with_errcode;
|
||||
}
|
||||
|
||||
return ch;
|
||||
|
||||
errout_with_errcode:
|
||||
set_errno(errcode);
|
||||
return EOF;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SYSLOG && CONFIG_SYSLOG_CHAR */
|
||||
|
@ -63,6 +63,7 @@
|
||||
|
||||
static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
{
|
||||
int errcode;
|
||||
int ret;
|
||||
|
||||
/* Try writing until the write was successful or until an irrecoverable
|
||||
@ -71,22 +72,23 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
|
||||
do
|
||||
{
|
||||
/* Write the character to the supported logging device */
|
||||
/* Write the character to the supported logging device. On failure,
|
||||
* syslog_putc returns EOF with the errno value set;
|
||||
*/
|
||||
|
||||
ret = syslog_putc(ch);
|
||||
if (ret == OK)
|
||||
if (ret != EOF)
|
||||
{
|
||||
this->nput++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* On failure syslog_putc will return a negated errno value. The
|
||||
* errno variable will not be set. The special value -EINTR means that
|
||||
* syslog_putc() was awakened by a signal. This is not a real error and
|
||||
* must be ignored in this context.
|
||||
/* The special errno value -EINTR means that syslog_putc() was
|
||||
* awakened by a signal. This is not a real error and must be
|
||||
* ignored in this context.
|
||||
*/
|
||||
}
|
||||
while (ret == -EINTR);
|
||||
while (errno == -EINTR);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user