IAR瑞萨单片机开发加入printf调试函数
1.关键之处,否则会出现PUTCHAR函数未定义现象。
本文引用地址:https://www.eepw.com.cn/article/201611/318625.htm右键点击工程选择option->General Option->ibrary configuration中library改为full,且General Option->library option->Printf formatter选项中选择full2
2. main.c中加入,其中使用的是串口1,注意如果提示FILE未定义,请在头文件最顶层添加#include
1 /* Privatefunction prototypes --*/2 3 #ifdef __GNUC__4 /* With GCC/RAISONANCE, small printf(option LD Linker->Libraries->Small printf5 set to Yes) calls __io_putchar() */6 #define PUTCHAR_PROTOTYPE int__io_putchar(int ch)7 #else8 #define PUTCHAR_PROTOTYPE int fputc(int ch,FILE *f)9 #endif /* __GNUC__ */10 11 /**12 *@brief Retargets the C library printffunction to the USART.13 *@param None14 *@retval None15 */16 PUTCHAR_PROTOTYPE17 {18 /*Place your implementation of fputc here */19 /*e.g. write a character to the USART */20 USART_SendData(EVAL_COM1, (uint8_t) ch);21 /*Loop until the end of transmission */22 while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET);23 return ch;24 }
printf函数打印字符串,遇到 时才结束。
评论