写在前面:
http://elm-chan.org/fsw/strf/xprintf.html
直接用这个就完了 不用包含stdio 没有库依赖
提供一篇写的很好的文字:
Semihosting真的是嵌入式阑尾么?-腾讯云开发者社区-腾讯云
正文:
网上的教程清一色都是使用MicroLib或切换Arm Compiler 5. 拜托我都吃细糠了没必要回去吃噗噗吧?microliib这种残缺东西效率不行到时候bug找死你。
完成这样一个retarget,并不要修改任何内容:
__asm(".global __ARM_use_no_argv\n\t"); //main函数不含参数 v6编译器默认main含参
__asm(".global __use_no_semihosting\n\t"); // 跟__use_no_semihosting_swi一样
int fputc(int ch,FILE *p)
{
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xF);
return ch;
}
void _sys_exit(int ret)
{
for(;;); // 也有写法是 ret=ret 我参考的是arm manual
}
void _ttywrch(int ch)
{
(void)ch;
}
FILE __stdout; //必要的 不要删除
完结,记得引入<stdio.h>