1 #include "RTE_Components.h"
2 #include <stdio.h>
3 
4 #include "Driver_USART.h"
5 #include "stdout_USART.h"
6 
7 
8 
9 
stdin_getc(FILE * file)10 static int stdin_getc(FILE *file) {
11   (void)file;
12   return(0);
13 }
14 
15 
16 // iostream has references to stdin and stderr and there is a link
17 // error if not defined.
18 static FILE __stdin = FDEV_SETUP_STREAM(NULL,
19                                         stdin_getc,
20                                         NULL,
21                                         _FDEV_SETUP_READ);
22 FILE *const stdin = &__stdin;
23 
stderr_putc(char c,FILE * file)24 static int stderr_putc(char c, FILE *file) {
25   (void)file;
26   return(0);
27 }
28 
29 static FILE __stderr = FDEV_SETUP_STREAM(stderr_putc,
30                                          NULL,
31                                          NULL,
32                                          _FDEV_SETUP_WRITE);
33 FILE *const stderr = &__stderr;
34 
35 //-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
36 
37 // <h>STDOUT USART Interface
38 
39 //   <o>Connect to hardware via Driver_USART# <0-255>
40 //   <i>Select driver control block for USART interface
41 #define USART_DRV_NUM           0
42 
43 //   <o>Baudrate
44 #define USART_BAUDRATE          115200
45 
46 // </h>
47 
48 
49 #define _USART_Driver_(n)  Driver_USART##n
50 #define  USART_Driver_(n) _USART_Driver_(n)
51 
52 extern ARM_DRIVER_USART  USART_Driver_(USART_DRV_NUM);
53 #define ptrUSART       (&USART_Driver_(USART_DRV_NUM))
54 
stdout_putchar(const unsigned char ch)55 int stdout_putchar(const unsigned char ch) {
56     uint8_t buf[1];
57 
58     buf[0] = ch;
59     if (ptrUSART->Send(buf, 1) != ARM_DRIVER_OK) {
60       return (-1);
61     }
62     while (ptrUSART->GetTxCount() != 1);
63     return (ch);
64 }
65 
66