▶ STM32/개발환경
IAR EWARM 사용자 정의 fputc()함수로 프로젝트 마이그레이션
좋은아침페스츄리
2023. 12. 8. 11:20
IAR 9.20.1 버전 이후 <stdio.h> 에 overriding 되어 있는 fputc() 은 더 이상 동작하지 않습니다.
자세한 내용은 아래 URL을 참조하시기 바랍니다.
사용자 정의 fputc() 함수로 프로젝트 마이그레이션
사용자 정의 fputc() 함수로 프로젝트 마이그레이션 기술노트 220216 아키텍처: Arm 컴포넌트: compiler 업데이트: 2022-07-05 오전 12:10 개요 사용자 정의 함수 fputc()가 있는 일부 프로젝트가 EWARM 9.20.1 이
www.iar.com
위의 Application Note에 따르면 IAR 9.20.1 이상버전 + Full library configuration을 사용하는 경우 _write() 함수를 이용하여야 합니다. _write 함수는 EWARM 이전 버전에서도 이미 지원되고 있었습니다.
#include <stdio.h>
#if defined(__ICCARM__)
#include <LowLevelIOInterface.h>
#endif
#if defined(__ICCARM__)
int iar_fputc(int ch);
#define PUTCHAR_PROTOTYPE int write(int ch)
#elif defined ( __CC_ARM ) || defined(__ARMCC_VERSION)
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#elif defined(__GNUC__)
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#endif /* __ICCARM__ */
#if defined(__ICCARM__)
size_t __write(int file, const unsigned char *ptr, size_t size)
{
const unsigned char const *p= ptr;
for(int i=0; i<len; i++)
{
write((int)*p);
p++;
}
return size;
}
#endif /* __ICCARM__ */
/**
* @brief Retargets the C library printf function to the USART.
*/
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&husartx, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
<끝>