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/>.
28 #include "common/printf.h"
30 #include "drivers/serial.h"
31 #include "io/serial.h"
33 #include "printf_serial.h"
35 #if SERIAL_PORT_COUNT > 0
37 static serialPort_t
*printfSerialPort
;
39 void setPrintfSerialPort(serialPort_t
*serialPort
)
41 printfSerialPort
= serialPort
;
44 #ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
46 int tfp_printf(const char *fmt
, ...)
50 int written
= tfp_format(stdout_putp
, stdout_putf
, fmt
, va
);
52 while (!isSerialTransmitBufferEmpty(printfSerialPort
));
56 static void _putc(void *p
, char c
)
59 serialWrite(printfSerialPort
, c
);
62 void printfSerialInit(void)
64 init_printf(NULL
, _putc
);
67 #else // REQUIRE_CC_ARM_PRINTF_SUPPORT
70 int fputc(int c
, FILE *f
)
72 // let DMA catch up a bit when using set or dump, we're too fast.
73 while (!isSerialTransmitBufferEmpty(printfSerialPort
));
74 serialWrite(printfSerialPort
, c
);
78 void printfSerialInit(void)
84 #endif // SERIAL_PORT_COUNT