[펌웨어] printf 사용법
작성일: 22년 3월 7일
PS. 개발하면서 사용하고 있는 Log를 정리함.
같이 근무하고 있는 박OO 연구원님과 함께함.
pus0319 - Overview
pus0319 has 5 repositories available. Follow their code on GitHub.
github.com
Index
1. 코드 작성
2. printf 코드 보기
3. __io_putchar() 함수 구현하기
4. Logger를 전처리
5. Logger 출력 결과
1. 코드 작성
- STM32CudeIDE에서 main.c 파일 안에 1초마다 printf 를 찍고자 함.
※ 해당 블로그에서는 UART 설정에 대해서는 생략함
2. printf 코드 보기
- printf 함수를 호출하게 되면 컴파일러에 의해서 _write()함수를 호출하게 됨
- _write()함수는 weak 형태로 구현은 되어 있음
- 필자는 _write() 함수를 그대로 사용하면서 __io_putchar() 함수를 구현하기로 함
3. __io_putchar() 함수 구현하기
- 필자는 UART5를 사용했으며 printf("Hello World\n")에서 한 글자씩 UART포트를 통해 Tx 하게 됨
- 출력할때 깔끔하게 보기 위해 "Hello World\r\n"을 하게 되지만 계속 반복 되므로 '\n' 들어오면 자동으로 '\r'를 출력함
4. Logger를 전처리
- 개발하다보면 Log를 찍는것은 기본임
- 아래와 같이 전처리를 통하여 File, Line, Func, Time 등을 찍어서 확인함
5. Logger 출력 결과
- 현재의 파일과 라인, 함수 명, 시간이 나오는 것을 확인할 수 있음
Referece:
https://yesarang.tistory.com/74
고수들이 절대 가르쳐 주지 않는 C/C++ 프로그래밍 팁 #4 - C/C++ 로깅 Facility
고절가주팁 네 번째입니다. 지난 글 마지막에 밝혔던 바와 같이 이번 글부터는 거의 모든 프로그램에서 필요로 하는 로깅(logging) 라이브러리를 구현해 보도록 하겠습니다. 회사에서나 개인적으
yesarang.tistory.com
https://www.cplusplus.com/reference/cstdio/printf/
printf - C++ Reference
function <cstdio> printf int printf ( const char * format, ... ); Print formatted data to stdout Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arg
www.cplusplus.com