[STM32F1] 串口通讯 程序编译错误

[复制链接]
1923|21
 楼主| liliang9554 发表于 2021-7-7 20:03 | 显示全部楼层 |阅读模式
stm32开发板,在使用串口通讯时,编译程序后显示如下错误。
..\USART.axf: Error: L6218E: Undefined symbol __vfscanf_char_file (referred from __0scanf.o).

程序如下
#include "usart.h"
void SZ_STM32_COMInit(void)
{
          GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;

    /* 使能STM32的USART对应GPIO的Clock时钟 */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

    /* 初始化STM32的USART的TX管脚,配置为复用功能推挽输出 */
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA , &GPIO_InitStructure);

    /* 初始化STM32的USART的RX管脚,配置为复用功能输入 */
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_Init(GPIOA , &GPIO_InitStructure);

        USART_InitStructure.USART_BaudRate = 115200;              //串口的波特率,例如115200 最高达4.5Mbits/s
    USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据字长度(8位或9位)
    USART_InitStructure.USART_StopBits = USART_StopBits_1;      //可配置的停止位-支持1或2个停止位
    USART_InitStructure.USART_Parity = USART_Parity_No;         //无奇偶校验  
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //无硬件流控制
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //双工模式,使能发送和接收

    /* 根据传入的参数初始化STM32的USART配置 */
    USART_Init(USART1, &USART_InitStructure);

    /* 使能STM32的USART功能模块 */
    USART_Cmd(USART1, ENABLE);  
}


/* 重定义fputc函数 如果使用MicroLIB只需要重定义fputc函数即可 */  
int fputc(int ch, FILE *f)
{
    /* e.g. write a character to the USART */
    USART_SendData(USART1, (uint8_t) ch);

    /* Loop until the end of transmission */
    while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);

    return ch;
}

int fgetc(FILE *fp)
{
        int ch = 0;
        
    while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);

    ch = (int)USART1->DR & 0xFF;
        
    putchar(ch); //回显
        
        return ch;
}


#include "usart.h"
#include "stm32f10x.h"
int main(void)
{  
        uint8_t Str[80] = {0};
         
        SZ_STM32_COMInit();         /* 串口初始化 */

        printf("\n\r WWW.ARMJISHU.COM! \n");
    while (1)
    {
                scanf("%s", Str);
                printf("\n\r 输入的字符串是: <%s>\n", Str);
    }
}


请各位大神指教。
bqyj 发表于 2021-7-7 20:05 | 显示全部楼层
有段代码用法不对,改下看看;
heweibig 发表于 2021-7-7 20:11 | 显示全部楼层
最后的printf感觉是做广告一样,真有才。
jiaxw 发表于 2021-7-7 20:12 | 显示全部楼层
是不是都写错了,这个没有下载官方的开发包吗
zhanghqi 发表于 2021-7-7 20:14 | 显示全部楼层
头文件缺失?
jlyuan 发表于 2021-7-7 20:16 | 显示全部楼层
全工程查找一下,哪里调用到了这个符号
llljh 发表于 2021-7-7 20:18 | 显示全部楼层
把USB Micro LIB给勾去就好了
tian111 发表于 2021-7-7 20:20 | 显示全部楼层
使用的函数没有被定义。
chenjunt 发表于 2021-7-7 20:23 | 显示全部楼层
在Options->C/C++->preprocessor Symboles定义
jlyuan 发表于 2021-7-7 20:25 | 显示全部楼层
加入头文件 到你的.c文件中
jiahy 发表于 2021-7-7 20:27 | 显示全部楼层
找一下库里面哪里定义了它
stly 发表于 2021-7-7 20:29 | 显示全部楼层
这个__vfscanf_char_file没有定义
xxmmi 发表于 2021-7-7 20:32 | 显示全部楼层
输入USE_STDPERIPH_DRIVER
zyf部长 发表于 2021-7-7 20:34 | 显示全部楼层

只要添加相应的头文件即可。
renyaq 发表于 2021-7-7 20:36 | 显示全部楼层
这个库没有相关的。
wuhany 发表于 2021-7-7 20:38 | 显示全部楼层
配置问题。
zhenykun 发表于 2021-7-7 20:40 | 显示全部楼层
不是microlib就是semihosting问题。
 楼主| liliang9554 发表于 2021-7-7 20:41 | 显示全部楼层
嗯,我再好好缕一缕吧,有了好消息及时通知大家
xiaoqizi 发表于 2021-8-6 13:58 | 显示全部楼层
报错信息在哪里啊
wowu 发表于 2021-8-6 14:02 | 显示全部楼层
未定义的模块?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

950

主题

11568

帖子

6

粉丝
快速回复 在线客服 返回列表 返回顶部