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