MDK—— Error: L6915E: Library reports error: __use_no_semihosting was requested

环境:

MDK V5.14
main程序所在文件为C++文件,函数体外定义类对象时,出现错误,但是在函数体内定义类对象,不会出错。

错误:

Error: L6915E: Library reports error: __use_no_semihosting was requested, but _ttywrch was referenced

解决:

串口重定位增加

//加入以下代码,支持printf函数,而不需要选择use MicroLIB    
#if 1
#pragma import(__use_no_semihosting)             
//标准库需要的支持函数                 
struct __FILE 
{ 
    int handle; 
}; 

FILE __stdout;       
//定义_sys_exit()以避免使用半主机模式    
_sys_exit(int x) 
{ 
    x = x; 
} 
//__use_no_semihosting was requested, but _ttywrch was 
_ttywrch(int ch)
{
    ch = ch;
}
//重定义fputc函数 
int fputc(int ch, FILE *f)
{   
    serialize8((u8)ch);
    USART_ITConfig(USART1, USART_IT_TXE, ENABLE);   //开启发送中断
    return ch;
}
#endif

如下代码

//__use_no_semihosting was requested, but _ttywrch was 
_ttywrch(int ch)
{
    ch = ch;
}

你可能感兴趣的:(STM32)