From bfc12bf3a70c6bb9e68240a396ae0ea87506e29a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Oct 2014 09:03:00 -0600 Subject: [PATCH] ARMv7: Add support to use ITM for SYSLOG debug output --- arch/arm/src/armv7-m/Kconfig | 25 ++++- arch/arm/src/armv7-m/arm_item_syslog.c | 148 +++++++++++++++++++++++++ arch/arm/src/armv7-m/itm_syslog.h | 66 +++++++++++ include/nuttx/syslog/syslog.h | 2 +- 4 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 arch/arm/src/armv7-m/arm_item_syslog.c create mode 100644 arch/arm/src/armv7-m/itm_syslog.h diff --git a/arch/arm/src/armv7-m/Kconfig b/arch/arm/src/armv7-m/Kconfig index ca1ff21aec..1149455462 100644 --- a/arch/arm/src/armv7-m/Kconfig +++ b/arch/arm/src/armv7-m/Kconfig @@ -62,5 +62,28 @@ config ARMV7M_OABI_TOOLCHAIN default n depends on ARMV7M_TOOLCHAIN_BUILDROOT ---help--- - Most of the older buildroot toolchains are OABI and are named arm-nuttx-elf- vs. arm-nuttx-eabi- + Most of the older buildroot toolchains are OABI and are named + arm-nuttx-elf- vs. arm-nuttx-eabi- +config ARMV7M_ITMSYSLOG + bool "ITM SYSLOG support" + default n + select SYSLOG + ---help--- + Enable hooks to support ITM syslog output. This requires additional + MCU support in order to be used. See arch/arm/src/armv7-m/itm_syslog.h + for additional initialization information. + +if ARMV7M_ITMSYSLOG + +config ARMV7M_ITMSYSLOG_PORT + int "ITM SYSLOG Port" + default 0 + range 0 31 + +config ARMV7M_ITMSYSLOG_SWODIV + int "ITM SYSLOG SWO divider" + default 15 + range 1 8192 + +endif # ARMV7M_ITMSYSLOG diff --git a/arch/arm/src/armv7-m/arm_item_syslog.c b/arch/arm/src/armv7-m/arm_item_syslog.c new file mode 100644 index 0000000000..0d532e5d98 --- /dev/null +++ b/arch/arm/src/armv7-m/arm_item_syslog.c @@ -0,0 +1,148 @@ +/**************************************************************************** + * arch/arm/src/armv7-m/itm_syslog.c + * + * Copyright (C) 2014 Pierre-noel Bouteville . All rights reserved. + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Authors: Pierre-noel Bouteville + * Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "nvic.h" +#include "up_arch.h" +#include "itm_syslog.h" + +#if defined(CONFIG_SYSLOG) || defined(CONFIG_ARMV7M_ITMSYSLOG) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_ARMV7M_ITMSYSLOG_SWODIV +# define CONFIG_ARMV7M_ITMSYSLOG_SWODIV 15 +#endif + +#if CONFIG_ARMV7M_ITMSYSLOG_SWODIV < 0 +# error CONFIG_ARMV7M_ITMSYSLOG_SWODIV should be at least equal to 1 +#endif + +/* Use Port #0 at default */ + +#ifndef CONFIG_ARMV7M_ITMSYSLOG_PORT +# define CONFIG_ARMV7M_ITMSYSLOG_PORT 0 +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: itm_syslog_initialize + * + * Description: + * Performs ARM-specific initialize for the ITM SYSLOG functions. + * Additional, board specific logic may be required to: + * + * - Enable/configured serial wire output pins + * - Enable debug clocking. + * + * Those operations must be performed by MCU-specific logic before this + * function is called. + * + ****************************************************************************/ + +void itm_syslog_initialize(void) +{ + uint32_t regval; + + /* Enable trace in core debug */ + + regval = getreg32(NVIC_DEMCR); + regval |= NVIC_DEMCR_TRCENA; + putreg32(putreg, NVIC_DEMCR); + + putreg32(0xc5acce55,ITM_LAR); + putreg32(0, ITM_TER); + putreg32(0, ITM_TCR); + putreg32(2, TPI_SPPR); /* Pin protocol: 2=> Manchester (USART) */ + + /* Default 880kbps */ + + regval = CONFIG_ARMV7M_ITMSYSLOG_SWODIV - 1; + putreg32(regval, TPI_ACPR); /* TRACECLKIN/(ACPR+1) SWO speed */ + + putreg32(0, ITM_TPR); + putreg32(0x400003fe, DWT_CTRL); + putreg32(0x0001000d, ITM_TCR); + putreg32(0x00000100, TPI_FFCR); + putreg32(0xffffffff, ITM_TER); /* Enable 32 Ports */ +} + +/**************************************************************************** + * Name: syslog_putc + * + * Description: + * This is the low-level system logging interface. The debugging/syslogging + * interfaces are syslog() and lowsyslog(). The difference is that + * the syslog() internface writes to fd=1 (stdout) whereas lowsyslog() uses + * a lower level interface that works from interrupt handlers. This + * function is the low-level interface used to implement lowsyslog(). + * + ****************************************************************************/ + +int syslog_putc(int ch); +{ + /* ITM enabled */ + + if ((getreg32(ITM_TCR) & ITM_TCR_ITMENA_Msk) == 0) + { + return; + } + + /* ITM Port "CONFIG_ARMV7M_ITMSYSLOG_PORT" enabled */ + + if (getreg32(ITM_TER) & (1 << CONFIG_ARMV7M_ITMSYSLOG_PORT)) + { + while (getreg32(ITM_PORT(CONFIG_ARMV7M_ITMSYSLOG_PORT)) == 0); + putreg8((uint8_t)ch, ITM_PORT(CONFIG_ARMV7M_ITMSYSLOG_PORT)); + } + + return ch; +} + +#endif /* CONFIG_SYSLOG && CONFIG_ARMV7M_ITMSYSLOG */ diff --git a/arch/arm/src/armv7-m/itm_syslog.h b/arch/arm/src/armv7-m/itm_syslog.h new file mode 100644 index 0000000000..b9a5e00936 --- /dev/null +++ b/arch/arm/src/armv7-m/itm_syslog.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * arch/arm/src/armv7-m/itm_syslog.h + * + * Copyright (C) 2014 Pierre-noel Bouteville . All rights reserved. + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Authors: Pierre-noel Bouteville + * Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_ARMV7_M_ITM_SYSLOG_H +#define __ARCH_ARM_SRC_ARMV7_M_ITM_SYSLOG_H + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: itm_syslog_initialize + * + * Description: + * Performs ARM-specific initialize for the ITM SYSLOG functions. + * Additional, board specific logic may be required to: + * + * - Enable/configured serial wire output pins + * - Enable debug clocking. + * + * Those operations must be performed by MCU-specific logic before this + * function is called. + * + ****************************************************************************/ + +#if defined(CONFIG_SYSLOG) || defined(CONFIG_ARMV7M_ITMSYSLOG) +void itm_syslog_initialize(void); +#else +# define itm_syslog_initialize() +#endif + +#endif /* __ARCH_ARM_SRC_ARMV7_M_ITM_SYSLOG_H */ diff --git a/include/nuttx/syslog/syslog.h b/include/nuttx/syslog/syslog.h index 0575f40183..84a56d19cb 100644 --- a/include/nuttx/syslog/syslog.h +++ b/include/nuttx/syslog/syslog.h @@ -119,7 +119,7 @@ EXTERN int syslog_initialize(void); * interfaces are syslog() and lowsyslog(). The difference is that * the syslog() internface writes to fd=1 (stdout) whereas lowsyslog() uses * a lower level interface that works from interrupt handlers. This - * function is a a low-level interface used to implement lowsyslog(). + * function is the low-level interface used to implement lowsyslog(). * ****************************************************************************/