[应用相关] stm32 串口通讯 程序编译错误 vfscanf

[复制链接]
1880|23
 楼主| 拉克丝 发表于 2018-5-20 18:56 | 显示全部楼层 |阅读模式
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);
    }
}


请各位大神指教。
yiy 发表于 2018-5-20 20:44 | 显示全部楼层
#include<stdio.h>
yiy 发表于 2018-5-20 20:45 | 显示全部楼层
少了标准输入输出函数头文件。
yiy 发表于 2018-5-20 20:45 | 显示全部楼层
你试试是不是这样的,我查的这个头文件在stdio.h里。你试试吧。
kkzz 发表于 2018-5-20 22:07 | 显示全部楼层
你是不是用了库函数没有包含库文件?
hudi008 发表于 2018-5-20 22:08 | 显示全部楼层
把USB Micro LIB给勾去呢?
lzmm 发表于 2018-5-20 22:08 | 显示全部楼层
是的是哪个编译器?
minzisc 发表于 2018-5-20 22:08 | 显示全部楼层
里面有没有添加头文件
selongli 发表于 2018-5-20 22:09 | 显示全部楼层
一般只要添加相应的头文件即可。
fentianyou 发表于 2018-5-20 22:09 | 显示全部楼层
提示是__vfscanf_char_file(referred from__0scanf.o)符号未定义。
xiaoyaodz 发表于 2018-5-20 22:09 | 显示全部楼层
把USB Micro LIB给勾去
febgxu 发表于 2018-5-20 22:10 | 显示全部楼层
工程文件呢?
sdlls 发表于 2018-5-20 22:10 | 显示全部楼层
编译时出错,语法错误,变量未定义。
pixhw 发表于 2018-5-20 22:11 | 显示全部楼层
没有定义
minzisc 发表于 2018-5-20 22:11 | 显示全部楼层
错误是说你使用的函数没有被定义。
lzmm 发表于 2018-5-20 22:11 | 显示全部楼层
是不是编译器有问题呢?
hudi008 发表于 2018-5-20 22:11 | 显示全部楼层
可以编译和下载吗?
kkzz 发表于 2018-5-20 22:11 | 显示全部楼层
把所有的库函数都添加上。
febgxu 发表于 2018-5-20 22:11 | 显示全部楼层
上传工程文件看看是哪里的问题
xiaoyaodz 发表于 2018-5-20 22:11 | 显示全部楼层
可能定义的代码没有找到。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

150

主题

920

帖子

2

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