2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
29 #include "common/printf.h"
31 #include "drivers/serial.h"
32 #include "io/serial.h"
34 #include "printf_serial.h"
36 #ifdef SERIAL_PORT_COUNT
38 static serialPort_t
*printfSerialPort
;
40 void setPrintfSerialPort(serialPort_t
*serialPort
)
42 printfSerialPort
= serialPort
;
45 #ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
47 int tfp_printf(const char *fmt
, ...)
51 int written
= tfp_format(stdout_putp
, stdout_putf
, fmt
, va
);
53 while (!isSerialTransmitBufferEmpty(printfSerialPort
));
57 static void _putc(void *p
, char c
)
60 serialWrite(printfSerialPort
, c
);
64 void printfSerialInit(void)
66 init_printf(NULL
, _putc
);
69 #else // REQUIRE_CC_ARM_PRINTF_SUPPORT
72 int fputc(int c
, FILE *f
)
74 // let DMA catch up a bit when using set or dump, we're too fast.
75 while (!isSerialTransmitBufferEmpty(printfSerialPort
));
76 serialWrite(printfSerialPort
, c
);
80 void printfSerialInit(void)
86 #endif // SERIAL_PORT_COUNT