自己回答:
浏览网站和案例集 找到一段代码,有点像STM中CubeMX生成工程无法运行printf相似,拿来之后可以了,代码如下:
#if (__ARMCC_VERSION > 6000000)
__asm (".global __use_no_semihosting\n\t");
void _sys_exit(int x){x = x;}
//__use_no_semihosting was requested, but _ttywrch was
void _ttywrch(int ch){ch = ch;}
FILE __stdout;
#else
#ifdef __CC_ARM
#pragma import(__use_no_semihosting)
struct __FILE
{int handle;};
FILE __stdout;
void _sys_exit(int x){x = x;}
#endif
#endif
#if defined ( __GNUC__ ) && !defined (__clang__)
//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
PUTCHAR_PROTOTYPE{
while(usart_flag_get(USART1, USART_TDBE_FLAG) == RESET);
usart_data_transmit(USART1, ch);
return ch;
}
将这段代码拷贝到main.c文档的最后,再给个空格即可。 |