1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 11:59:58 +03:00

Merge pull request #7621 from betaflight/bf-allow-compilation-with-no-serial-ports

Allow compilation of the printf code when no serial ports are used.
This commit is contained in:
Michael Keller 2019-04-14 21:31:31 +12:00 committed by GitHub
commit 65603e49a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 125 additions and 60 deletions

View file

@ -52,6 +52,7 @@ extern uint8_t __config_end;
#include "common/color.h"
#include "common/maths.h"
#include "common/printf.h"
#include "common/printf_serial.h"
#include "common/strtol.h"
#include "common/time.h"
#include "common/typeconversion.h"

View file

@ -38,24 +38,17 @@
#include "build/build_config.h"
#include "common/utils.h"
#include "drivers/serial.h"
#include "io/serial.h"
#include "printf.h"
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
#include "typeconversion.h"
#endif
static serialPort_t *printfSerialPort;
#ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
typedef void (*putcf) (void *, char);
static putcf stdout_putf;
static void *stdout_putp;
putcf stdout_putf;
void *stdout_putp;
// print bf, padded from left to at least n characters.
// padding is zero ('0') if z!=0, space (' ') otherwise
@ -166,16 +159,6 @@ void init_printf(void *putp, void (*putf) (void *, char))
stdout_putp = putp;
}
int tfp_printf(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
int written = tfp_format(stdout_putp, stdout_putf, fmt, va);
va_end(va);
while (!isSerialTransmitBufferEmpty(printfSerialPort));
return written;
}
static void putcp(void *p, char c)
{
*(*((char **) p))++ = c;
@ -192,36 +175,5 @@ int tfp_sprintf(char *s, const char *fmt, ...)
return written;
}
#endif // REQUIRE_CC_ARM_PRINTF_SUPPORT
static void _putc(void *p, char c)
{
UNUSED(p);
serialWrite(printfSerialPort, c);
}
void printfSupportInit(void)
{
init_printf(NULL, _putc);
}
#else
// keil/armcc version
int fputc(int c, FILE *f)
{
// let DMA catch up a bit when using set or dump, we're too fast.
while (!isSerialTransmitBufferEmpty(printfSerialPort));
serialWrite(printfSerialPort, c);
return c;
}
void printfSupportInit(void)
{
// Nothing to do
}
#endif
void setPrintfSerialPort(serialPort_t *serialPort)
{
printfSerialPort = serialPort;
}

View file

@ -106,14 +106,11 @@ regs Kusti, 23.10.2004
#include <stdarg.h>
typedef void (*putcf) (void *, char);
extern putcf stdout_putf;
extern void *stdout_putp;
void init_printf(void *putp, void (*putf) (void *, char));
// Disabling this, in favour of tfp_format to be used in cli.c
//int tfp_printf(const char *fmt, ...);
int tfp_sprintf(char *s, const char *fmt, ...);
int tfp_format(void *putp, void (*putf) (void *, char), const char *fmt, va_list va);
struct serialPort_s;
void setPrintfSerialPort(struct serialPort_s *serialPort);
void printfSupportInit(void);

View file

@ -0,0 +1,86 @@
/*
* This file is part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Cleanflight and Betaflight are distributed in the hope that they
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdlib.h>
#include "platform.h"
#include "common/printf.h"
#include "drivers/serial.h"
#include "io/serial.h"
#include "printf_serial.h"
#ifdef SERIAL_PORT_COUNT
static serialPort_t *printfSerialPort;
void setPrintfSerialPort(serialPort_t *serialPort)
{
printfSerialPort = serialPort;
}
#ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
int tfp_printf(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
int written = tfp_format(stdout_putp, stdout_putf, fmt, va);
va_end(va);
while (!isSerialTransmitBufferEmpty(printfSerialPort));
return written;
}
static void _putc(void *p, char c)
{
UNUSED(p);
serialWrite(printfSerialPort, c);
}
void printfSerialInit(void)
{
init_printf(NULL, _putc);
}
#else // REQUIRE_CC_ARM_PRINTF_SUPPORT
// keil/armcc version
int fputc(int c, FILE *f)
{
// let DMA catch up a bit when using set or dump, we're too fast.
while (!isSerialTransmitBufferEmpty(printfSerialPort));
serialWrite(printfSerialPort, c);
return c;
}
void printfSerialInit(void)
{
// Nothing to do
}
#endif
#endif // SERIAL_PORT_COUNT

View file

@ -0,0 +1,27 @@
/*
* This file is part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Cleanflight and Betaflight are distributed in the hope that they
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
struct serialPort_s;
void printfSerialInit(void);
void setPrintfSerialPort(struct serialPort_s *serialPort);
int tfp_printf(const char *fmt, ...);

View file

@ -32,7 +32,7 @@
#include "common/axis.h"
#include "common/color.h"
#include "common/maths.h"
#include "common/printf.h"
#include "common/printf_serial.h"
#include "config/config_eeprom.h"
#include "config/feature.h"
@ -246,7 +246,9 @@ void init(void)
}
#endif
printfSupportInit();
#ifdef SERIAL_PORT_COUNT
printfSerialInit();
#endif
systemInit();