This is a FileHandle interface implementation and retarget registration of the stdio interface to the Segger Real-Time Terminal (RTT) instead of the default serial port. Retargeting will automatically take place if this library is added to the project.

Dependents:   3_Test_AFE 1_Test_Flash_ADC_RTT

Committer:
0x6d61726b
Date:
Sat May 18 22:41:10 2019 +0000
Revision:
0:7fca1bf48117
updated to Segger RTT version 6.44i

Who changed what in which revision?

UserRevisionLine numberNew contents of line
0x6d61726b 0:7fca1bf48117 1 /*********************************************************************
0x6d61726b 0:7fca1bf48117 2 * SEGGER Microcontroller GmbH *
0x6d61726b 0:7fca1bf48117 3 * The Embedded Experts *
0x6d61726b 0:7fca1bf48117 4 **********************************************************************
0x6d61726b 0:7fca1bf48117 5 * *
0x6d61726b 0:7fca1bf48117 6 * (c) 1995 - 2019 SEGGER Microcontroller GmbH *
0x6d61726b 0:7fca1bf48117 7 * *
0x6d61726b 0:7fca1bf48117 8 * www.segger.com Support: support@segger.com *
0x6d61726b 0:7fca1bf48117 9 * *
0x6d61726b 0:7fca1bf48117 10 **********************************************************************
0x6d61726b 0:7fca1bf48117 11 * *
0x6d61726b 0:7fca1bf48117 12 * SEGGER RTT * Real Time Transfer for embedded targets *
0x6d61726b 0:7fca1bf48117 13 * *
0x6d61726b 0:7fca1bf48117 14 **********************************************************************
0x6d61726b 0:7fca1bf48117 15 * *
0x6d61726b 0:7fca1bf48117 16 * All rights reserved. *
0x6d61726b 0:7fca1bf48117 17 * *
0x6d61726b 0:7fca1bf48117 18 * SEGGER strongly recommends to not make any changes *
0x6d61726b 0:7fca1bf48117 19 * to or modify the source code of this software in order to stay *
0x6d61726b 0:7fca1bf48117 20 * compatible with the RTT protocol and J-Link. *
0x6d61726b 0:7fca1bf48117 21 * *
0x6d61726b 0:7fca1bf48117 22 * Redistribution and use in source and binary forms, with or *
0x6d61726b 0:7fca1bf48117 23 * without modification, are permitted provided that the following *
0x6d61726b 0:7fca1bf48117 24 * conditions are met: *
0x6d61726b 0:7fca1bf48117 25 * *
0x6d61726b 0:7fca1bf48117 26 * o Redistributions of source code must retain the above copyright *
0x6d61726b 0:7fca1bf48117 27 * notice, this list of conditions and the following disclaimer. *
0x6d61726b 0:7fca1bf48117 28 * *
0x6d61726b 0:7fca1bf48117 29 * o Redistributions in binary form must reproduce the above *
0x6d61726b 0:7fca1bf48117 30 * copyright notice, this list of conditions and the following *
0x6d61726b 0:7fca1bf48117 31 * disclaimer in the documentation and/or other materials provided *
0x6d61726b 0:7fca1bf48117 32 * with the distribution. *
0x6d61726b 0:7fca1bf48117 33 * *
0x6d61726b 0:7fca1bf48117 34 * o Neither the name of SEGGER Microcontroller GmbH *
0x6d61726b 0:7fca1bf48117 35 * nor the names of its contributors may be used to endorse or *
0x6d61726b 0:7fca1bf48117 36 * promote products derived from this software without specific *
0x6d61726b 0:7fca1bf48117 37 * prior written permission. *
0x6d61726b 0:7fca1bf48117 38 * *
0x6d61726b 0:7fca1bf48117 39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
0x6d61726b 0:7fca1bf48117 40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
0x6d61726b 0:7fca1bf48117 41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
0x6d61726b 0:7fca1bf48117 42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
0x6d61726b 0:7fca1bf48117 43 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
0x6d61726b 0:7fca1bf48117 44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
0x6d61726b 0:7fca1bf48117 45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
0x6d61726b 0:7fca1bf48117 46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
0x6d61726b 0:7fca1bf48117 47 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
0x6d61726b 0:7fca1bf48117 48 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
0x6d61726b 0:7fca1bf48117 49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
0x6d61726b 0:7fca1bf48117 50 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
0x6d61726b 0:7fca1bf48117 51 * DAMAGE. *
0x6d61726b 0:7fca1bf48117 52 * *
0x6d61726b 0:7fca1bf48117 53 **********************************************************************
0x6d61726b 0:7fca1bf48117 54 * *
0x6d61726b 0:7fca1bf48117 55 * RTT version: 6.44i *
0x6d61726b 0:7fca1bf48117 56 * *
0x6d61726b 0:7fca1bf48117 57 **********************************************************************
0x6d61726b 0:7fca1bf48117 58 ---------------------------END-OF-HEADER------------------------------
0x6d61726b 0:7fca1bf48117 59 File : SEGGER_RTT_Conf.h
0x6d61726b 0:7fca1bf48117 60 Purpose : Implementation of SEGGER real-time transfer (RTT) which
0x6d61726b 0:7fca1bf48117 61 allows real-time communication on targets which support
0x6d61726b 0:7fca1bf48117 62 debugger memory accesses while the CPU is running.
0x6d61726b 0:7fca1bf48117 63 Revision: Rev: 13430
0x6d61726b 0:7fca1bf48117 64
0x6d61726b 0:7fca1bf48117 65 */
0x6d61726b 0:7fca1bf48117 66
0x6d61726b 0:7fca1bf48117 67 #ifndef SEGGER_RTT_CONF_H
0x6d61726b 0:7fca1bf48117 68 #define SEGGER_RTT_CONF_H
0x6d61726b 0:7fca1bf48117 69
0x6d61726b 0:7fca1bf48117 70 /*********************************************************************
0x6d61726b 0:7fca1bf48117 71 *
0x6d61726b 0:7fca1bf48117 72 * Defines, configurable
0x6d61726b 0:7fca1bf48117 73 *
0x6d61726b 0:7fca1bf48117 74 **********************************************************************
0x6d61726b 0:7fca1bf48117 75 */
0x6d61726b 0:7fca1bf48117 76
0x6d61726b 0:7fca1bf48117 77 #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (1) // Max. number of up-buffers (T->H) available on this target (Default: 3)
0x6d61726b 0:7fca1bf48117 78 #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (1) // Max. number of down-buffers (H->T) available on this target (Default: 3)
0x6d61726b 0:7fca1bf48117 79
0x6d61726b 0:7fca1bf48117 80 // configure SEGGER_RTT_BUFFER_SIZE_* with compiler flags (default: see SEGGER_RTT.c)
0x6d61726b 0:7fca1bf48117 81 //#define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
0x6d61726b 0:7fca1bf48117 82 //#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
0x6d61726b 0:7fca1bf48117 83
0x6d61726b 0:7fca1bf48117 84 // configure SEGGER_RTT_PRINTF_BUFFER_SIZE with compiler flags (default: see SEGGER_RTT_printf.c)
0x6d61726b 0:7fca1bf48117 85 //#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
0x6d61726b 0:7fca1bf48117 86
0x6d61726b 0:7fca1bf48117 87 // configure SEGGER_RTT_MODE_DEFAULT with compiler flags, if needed (default: see SEGGER_RTT.c)
0x6d61726b 0:7fca1bf48117 88 //#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
0x6d61726b 0:7fca1bf48117 89
0x6d61726b 0:7fca1bf48117 90 /*********************************************************************
0x6d61726b 0:7fca1bf48117 91 *
0x6d61726b 0:7fca1bf48117 92 * RTT memcpy configuration
0x6d61726b 0:7fca1bf48117 93 *
0x6d61726b 0:7fca1bf48117 94 * memcpy() is good for large amounts of data,
0x6d61726b 0:7fca1bf48117 95 * but the overhead is big for small amounts, which are usually stored via RTT.
0x6d61726b 0:7fca1bf48117 96 * With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead.
0x6d61726b 0:7fca1bf48117 97 *
0x6d61726b 0:7fca1bf48117 98 * SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions.
0x6d61726b 0:7fca1bf48117 99 * This is may be required with memory access restrictions,
0x6d61726b 0:7fca1bf48117 100 * such as on Cortex-A devices with MMU.
0x6d61726b 0:7fca1bf48117 101 */
0x6d61726b 0:7fca1bf48117 102 #define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
0x6d61726b 0:7fca1bf48117 103 //
0x6d61726b 0:7fca1bf48117 104 // Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
0x6d61726b 0:7fca1bf48117 105 //
0x6d61726b 0:7fca1bf48117 106 //#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__))
0x6d61726b 0:7fca1bf48117 107 // #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes))
0x6d61726b 0:7fca1bf48117 108 //#endif
0x6d61726b 0:7fca1bf48117 109
0x6d61726b 0:7fca1bf48117 110 //
0x6d61726b 0:7fca1bf48117 111 // Target is not allowed to perform other RTT operations while string still has not been stored completely.
0x6d61726b 0:7fca1bf48117 112 // Otherwise we would probably end up with a mixed string in the buffer.
0x6d61726b 0:7fca1bf48117 113 // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
0x6d61726b 0:7fca1bf48117 114 //
0x6d61726b 0:7fca1bf48117 115 // SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
0x6d61726b 0:7fca1bf48117 116 // Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
0x6d61726b 0:7fca1bf48117 117 // When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
0x6d61726b 0:7fca1bf48117 118 // (Higher priority = lower priority number)
0x6d61726b 0:7fca1bf48117 119 // Default value for embOS: 128u
0x6d61726b 0:7fca1bf48117 120 // Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
0x6d61726b 0:7fca1bf48117 121 // In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
0x6d61726b 0:7fca1bf48117 122 // or define SEGGER_RTT_LOCK() to completely disable interrupts.
0x6d61726b 0:7fca1bf48117 123 //
0x6d61726b 0:7fca1bf48117 124
0x6d61726b 0:7fca1bf48117 125 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
0x6d61726b 0:7fca1bf48117 126
0x6d61726b 0:7fca1bf48117 127 /*********************************************************************
0x6d61726b 0:7fca1bf48117 128 *
0x6d61726b 0:7fca1bf48117 129 * RTT lock configuration for SEGGER Embedded Studio,
0x6d61726b 0:7fca1bf48117 130 * Rowley CrossStudio and GCC
0x6d61726b 0:7fca1bf48117 131 */
0x6d61726b 0:7fca1bf48117 132 #if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__) || (defined __clang__)
0x6d61726b 0:7fca1bf48117 133 #if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
0x6d61726b 0:7fca1bf48117 134 #define SEGGER_RTT_LOCK() { \
0x6d61726b 0:7fca1bf48117 135 unsigned int LockState; \
0x6d61726b 0:7fca1bf48117 136 __asm volatile ("mrs %0, primask \n\t" \
0x6d61726b 0:7fca1bf48117 137 "movs r1, $1 \n\t" \
0x6d61726b 0:7fca1bf48117 138 "msr primask, r1 \n\t" \
0x6d61726b 0:7fca1bf48117 139 : "=r" (LockState) \
0x6d61726b 0:7fca1bf48117 140 : \
0x6d61726b 0:7fca1bf48117 141 : "r1" \
0x6d61726b 0:7fca1bf48117 142 );
0x6d61726b 0:7fca1bf48117 143
0x6d61726b 0:7fca1bf48117 144 #define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
0x6d61726b 0:7fca1bf48117 145 : \
0x6d61726b 0:7fca1bf48117 146 : "r" (LockState) \
0x6d61726b 0:7fca1bf48117 147 : \
0x6d61726b 0:7fca1bf48117 148 ); \
0x6d61726b 0:7fca1bf48117 149 }
0x6d61726b 0:7fca1bf48117 150 #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
0x6d61726b 0:7fca1bf48117 151 #ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
0x6d61726b 0:7fca1bf48117 152 #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
0x6d61726b 0:7fca1bf48117 153 #endif
0x6d61726b 0:7fca1bf48117 154 #define SEGGER_RTT_LOCK() { \
0x6d61726b 0:7fca1bf48117 155 unsigned int LockState; \
0x6d61726b 0:7fca1bf48117 156 __asm volatile ("mrs %0, basepri \n\t" \
0x6d61726b 0:7fca1bf48117 157 "mov r1, %1 \n\t" \
0x6d61726b 0:7fca1bf48117 158 "msr basepri, r1 \n\t" \
0x6d61726b 0:7fca1bf48117 159 : "=r" (LockState) \
0x6d61726b 0:7fca1bf48117 160 : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
0x6d61726b 0:7fca1bf48117 161 : "r1" \
0x6d61726b 0:7fca1bf48117 162 );
0x6d61726b 0:7fca1bf48117 163
0x6d61726b 0:7fca1bf48117 164 #define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
0x6d61726b 0:7fca1bf48117 165 : \
0x6d61726b 0:7fca1bf48117 166 : "r" (LockState) \
0x6d61726b 0:7fca1bf48117 167 : \
0x6d61726b 0:7fca1bf48117 168 ); \
0x6d61726b 0:7fca1bf48117 169 }
0x6d61726b 0:7fca1bf48117 170
0x6d61726b 0:7fca1bf48117 171 #elif defined(__ARM_ARCH_7A__)
0x6d61726b 0:7fca1bf48117 172 #define SEGGER_RTT_LOCK() { \
0x6d61726b 0:7fca1bf48117 173 unsigned int LockState; \
0x6d61726b 0:7fca1bf48117 174 __asm volatile ("mrs r1, CPSR \n\t" \
0x6d61726b 0:7fca1bf48117 175 "mov %0, r1 \n\t" \
0x6d61726b 0:7fca1bf48117 176 "orr r1, r1, #0xC0 \n\t" \
0x6d61726b 0:7fca1bf48117 177 "msr CPSR_c, r1 \n\t" \
0x6d61726b 0:7fca1bf48117 178 : "=r" (LockState) \
0x6d61726b 0:7fca1bf48117 179 : \
0x6d61726b 0:7fca1bf48117 180 : "r1" \
0x6d61726b 0:7fca1bf48117 181 );
0x6d61726b 0:7fca1bf48117 182
0x6d61726b 0:7fca1bf48117 183 #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
0x6d61726b 0:7fca1bf48117 184 "mrs r1, CPSR \n\t" \
0x6d61726b 0:7fca1bf48117 185 "bic r1, r1, #0xC0 \n\t" \
0x6d61726b 0:7fca1bf48117 186 "and r0, r0, #0xC0 \n\t" \
0x6d61726b 0:7fca1bf48117 187 "orr r1, r1, r0 \n\t" \
0x6d61726b 0:7fca1bf48117 188 "msr CPSR_c, r1 \n\t" \
0x6d61726b 0:7fca1bf48117 189 : \
0x6d61726b 0:7fca1bf48117 190 : "r" (LockState) \
0x6d61726b 0:7fca1bf48117 191 : "r0", "r1" \
0x6d61726b 0:7fca1bf48117 192 ); \
0x6d61726b 0:7fca1bf48117 193 }
0x6d61726b 0:7fca1bf48117 194 #else
0x6d61726b 0:7fca1bf48117 195 #define SEGGER_RTT_LOCK()
0x6d61726b 0:7fca1bf48117 196 #define SEGGER_RTT_UNLOCK()
0x6d61726b 0:7fca1bf48117 197 #endif
0x6d61726b 0:7fca1bf48117 198 #endif
0x6d61726b 0:7fca1bf48117 199
0x6d61726b 0:7fca1bf48117 200 /*********************************************************************
0x6d61726b 0:7fca1bf48117 201 *
0x6d61726b 0:7fca1bf48117 202 * RTT lock configuration fallback
0x6d61726b 0:7fca1bf48117 203 */
0x6d61726b 0:7fca1bf48117 204 #ifndef SEGGER_RTT_LOCK
0x6d61726b 0:7fca1bf48117 205 #define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
0x6d61726b 0:7fca1bf48117 206 #endif
0x6d61726b 0:7fca1bf48117 207
0x6d61726b 0:7fca1bf48117 208 #ifndef SEGGER_RTT_UNLOCK
0x6d61726b 0:7fca1bf48117 209 #define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
0x6d61726b 0:7fca1bf48117 210 #endif
0x6d61726b 0:7fca1bf48117 211
0x6d61726b 0:7fca1bf48117 212 #endif
0x6d61726b 0:7fca1bf48117 213 /*************************** End of file ****************************/