1 /******************************************************************************
2 *  Filename:       uart_doc.h
3 *  Revised:        2018-02-09 15:45:36 +0100 (fr, 09 feb 2018)
4 *  Revision:       51470
5 *
6 *  Copyright (c) 2015 - 2020, Texas Instruments Incorporated
7 *  All rights reserved.
8 *
9 *  Redistribution and use in source and binary forms, with or without
10 *  modification, are permitted provided that the following conditions are met:
11 *
12 *  1) Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *
15 *  2) Redistributions in binary form must reproduce the above copyright notice,
16 *     this list of conditions and the following disclaimer in the documentation
17 *     and/or other materials provided with the distribution.
18 *
19 *  3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 *     be used to endorse or promote products derived from this software without
21 *     specific prior written permission.
22 *
23 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 *  POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36 /*!
37 \addtogroup uart_api
38 @{
39 
40 \section sec_uart_printf Use printf()
41 
42 DriverLib only supports writing a single character at a time to the UART buffer but it is
43 possible to utilize the library function \c printf by overriding a few of the functions used by
44 \c printf with a device specific definition. However, the implementation of \c printf is
45 compiler specific and requires different functions to be overridden depending on the compiler.
46 
47 Using \c printf can increase code size significantly but some compilers provide a highly optimized
48 and configurable implementation suitable for embedded systems which makes the code size increase
49 acceptable for most applications. See the compiler's documentation for details about how to
50 configure the \c printf library function.
51 
52 It is required that the application configures and enables the UART module before using \c printf
53 function.
54 
55 \subsection sec_uart_printf_ccs Code Composer Studio
56 
57 In Code Composer Studio the functions \c fputc and \c fputs must be overridden.
58 
59 \code{.c}
60 #include <stdio.h>
61 #include <string.h>
62 
63 #define PRINTF_UART                     UART0_BASE
64 
65 // Override 'fputc' function in order to use printf() to output to UART
66 int fputc(int _c, register FILE *_fp)
67 {
68     UARTCharPut(PRINTF_UART, (uint8_t)_c);
69     return _c;
70 }
71 
72 // Override 'fputs' function in order to use printf() to output to UART
73 int fputs(const char *_ptr, register FILE *_fp)
74 {
75   unsigned int i, len;
76 
77   len = strlen(_ptr);
78 
79   for(i=0 ; i<len ; i++)
80   {
81       UARTCharPut(PRINTF_UART, (uint8_t)_ptr[i]);
82   }
83 
84   return len;
85 }
86 \endcode
87 
88 \subsection sec_uart_printf_iar IAR
89 
90 In IAR the function \c putchar must be overridden.
91 
92 \code{.c}
93 #include <stdio.h>
94 #include <string.h>
95 
96 #define PRINTF_UART                     UART0_BASE
97 
98 // Override 'putchar' function in order to use printf() to output to UART.
99 int putchar(int data)
100 {
101     UARTCharPut(PRINTF_UART, (uint8_t)data);
102     return data;
103 }
104 \endcode
105 
106 @}
107 */
108