历史上的今天
今天是:2025年03月08日(星期六)
2020年03月08日 | 如何在mcu上使用printf使串口输出
2020-03-08 来源:eefocus
#ifdef __GNUC__ //另外GNU还有一些公用的扩展出来的宏 比如__GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
把代码加在一个.c文件中。就可以使用printf来进行数据重定向。上面代码适合32,其它的要进行相应替换即可。
printf("123456rn");一定要加rn.
下一篇:51单片机实现printf
史海拾趣
|
R4 launchpad新货New Hercules ARM Cortex-R4 Launchpads 链接:http://www.ti.com/ww/en/launchpad/hercules.html 有两种MCU,分别是TMS570LS04 和RM42 对比: … 查看全部问答> |
|
乱玩BeagleBone4-安装ubuntu镜像到内部eMMC 本帖最后由 shower.xu 于 2014-5-14 12:25 编辑 工欲善其事必先利其器,开工之前先把系统搞好,个人比较喜欢ubuntu的系统,BBB上已经更新到13.10了,当然紧跟形势,let\'s do it.之前集中安装发发都试过,觉得这个安装方便时间短,而且插入带系统 ...… 查看全部问答> |




