BaseFlight printf - FabLabSeoul/WingProject GitHub Wiki

์ด ๊ธ€์€ MultiWii BaseFlight ์†Œ์Šค๋ฅผ ๋ถ„์„ํ•œ ๊ธ€์ด๋‹ค. ์›๋ณธ ์†Œ์Šค๋Š” https://github.com/multiwii/baseflight ์—์„œ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ์ œ๋Š” STM32\stm32vldiscovery_package\Project\Examples\Printf_Baseflight ๊ฒฝ๋กœ์— ์žˆ๋‹ค.

Stm32๋Š” ๋””๋ฒ„๊น…์„ ์œ„ํ•ด, ์ž์ฒด printf ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค. c ํ•จ์ˆ˜์˜ printf ๊ธฐ๋Šฅ๊ณผ ๊ฑฐ์˜ ๊ฐ™๊ณ , ์‹œ๋ฆฌ์–ผํ†ต์‹ ์œผ๋กœ stm32์—์„œ pc๋กœ ์ „๋‹ฌ๋˜๊ฒŒํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ฐ€์ง„๋‹ค.

BaseFlight ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์ด๋ฅผ ์œ„ํ•ด printf.c, printf.h ๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค. ์‹œ๋ฆฌ์–ผ ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•œ ํ™˜๊ฒฝ์ด๋ผ๋ฉด printf.c,h ์†Œ์Šค๋ฅผ ๊ฐ€์ ธ์™€ ๊ฑฐ์˜ ์ˆ˜์ •์—†์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

baseflight์˜ drv_usart, drv_serial ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฐ€์ ธ์™”๋‹ค๋ฉด USE_LAME_PRINTF๋ฅผ ์„ ์–ธํ•˜์ง€ ์•Š๊ณ , ๋ฐ”๋กœ fputc()ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ์— ๋‚˜์˜ค๋Š” g_mainport ๋Š” serialPort_t ํƒ€์ž…์˜ ์ „์—ญ ๋ณ€์ˆ˜๋‹ค. USART1 ํฌํŠธ๋ฅผ ๊ฐ€๋ฅดํ‚ค๋‹ค.

baseflight ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์—†์ด printf๋ฅผ ์“ฐ๊ณ  ์‹ถ๋‹ค๋ฉด, USE_LAME_PRINTF ๋ฅผ ์„ ์–ธํ•˜๊ณ , putc()๋ฅผ ๊ตฌํ˜„ํ•œ ํ›„, init_printf() ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด ์ดˆ๊ธฐํ™” ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

#include <stdio.h>

#ifndef __CC_ARM
// only need this garbage on gcc
#define USE_LAME_PRINTF
#include "printf.h"
#endif


#ifdef USE_LAME_PRINTF
// gcc/GNU version
static void _putc(void *p, char c)
{
    (void)p;
    serialWrite(g_mainport, c);
}
#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(g_mainport));
   serialWrite(g_mainport, c);
   return c;
}
#endif
โš ๏ธ **GitHub.com Fallback** โš ๏ธ