野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 23493|回复: 4

学习 scanf 开发板范例 链接 出错 Undefined symbol __vfscanf_char_file (referred

[复制链接]
发表于 2014-4-18 17:07:36 | 显示全部楼层 |阅读模式
linking...
.\Obj\output.axf: Error: L6218E: Undefined symbol __vfscanf_char_file (referred from __0scanf.o).
.\Obj\output.axf: Not enough information to list image symbols.
.\Obj\output.axf: Finished: 1 information, 0 warning and 1 error messages.
Target not created

为什么编译出现上述错误?初学scanf,希望得到指点,不胜感激...

main.c

#include "stm32f10x.h"
#include <stdio.h>
#include "usart_printf.h"

#define EXAMPLE_NAME        "printf & scanf Testing"
#define EXAMPLE_DATE        "2010-01-02"

/*******************************************************************************
        函数名:main
        输  入:
        输  出:
        功能说明:用户程序入口
*/
int main(void)
{
        /*
                这个函数是ST库中的函数,函数实体在
                Libraries\CMSIS\Core\CM3\system_stm32f10x.c

                配置内部Flash接口,初始化PLL,配置系统频率
                系统时钟缺省配置为72MHz,你如果需要更改,则需要去修改相关的头文件中的宏定义
        */
        SystemInit();

        /* 配置串口, 该函数在usart_printf.c */
        USART_Configuration();

        /* 通过串口输出例程名和更新日期 */
        PrintfLogo(EXAMPLE_NAME, EXAMPLE_DATE);

        /* KEIL 下,编译scanf,功能正确,但是在IAR下编译,scanf会遗漏首字符(原因待查) */
        while (1)
        {
                int a,b,c;
                char str[200];

                printf("input 3 number a,b,c :\r\n");

                scanf("%d", &a);
                scanf("%d", &b);
                scanf("%d", &c);
                printf("a=%d, b=%d, c=%d\r\n",a,b,c);

                printf("input a sting :\r\n");
                scanf("%s", str);

                printf("str = %s\r\n", str);
                printf("\r\n");
        }
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/


uart.c

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include <stdio.h>

/*******************************************************************************
        函数名:PrintfLogo
        输  入: 例程名称和例程最后更新日期
        输  出:
        功能说明:
*/
void PrintfLogo(char *strName, char *strDate)
{
        printf("*************************************************************\n\r");
        printf("* Example Name : %s\r\n", strName);
        printf("* Update Date  : %s\r\n", strDate);
        printf("* StdPeriph_Lib Version : V3.1.2\n\r");
        printf("* \n\r");
        printf("* Copyright www.armfly.com \r\n");
        printf("* QQ    : 1295744630 \r\n");
        printf("* Email : armfly@qq.com \r\n");
        printf("*************************************************************\n\r");
}

/*******************************************************************************
        函数名:USART_Configuration
        输  入:
        输  出:
        功能说明:
        初始化串口硬件设备,未启用中断。
        配置步骤:
        (1)打开GPIO和USART的时钟
        (2)设置USART两个管脚GPIO模式
        (3)配置USART数据格式、波特率等参数
        (4)最后使能USART功能
*/
void USART_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;

        /* 第1步:打开GPIO和USART部件的时钟 */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

        /* 第2步:将USART Tx的GPIO配置为推挽复用模式 */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        /* 第3步:将USART Rx的GPIO配置为浮空输入模式
                由于CPU复位后,GPIO缺省都是浮空输入模式,因此下面这个步骤不是必须的
                但是,我还是建议加上便于阅读,并且防止其它地方修改了这个口线的设置参数
        */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        /*  第3步已经做了,因此这步可以不做
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        */
        GPIO_Init(GPIOA, &GPIO_InitStructure);


        /* 第4步:配置USART参数
            - BaudRate = 115200 baud
            - Word Length = 8 Bits
            - One Stop Bit
            - No parity
            - Hardware flow control disabled (RTS and CTS signals)
            - Receive and transmit enabled
        */
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_Init(USART1, &USART_InitStructure);

        /* 第5步:使能 USART, 配置完毕 */
        USART_Cmd(USART1, ENABLE);

        /* CPU的小缺陷:串口配置好,如果直接Send,则第1个字节发送不出去
                如下语句解决第1个字节无法正确发送出去的问题 */
        USART_ClearFlag(USART1, USART_FLAG_TC);     /* 清发送外城标志,Transmission Complete flag */
}

/*******************************************************************************
        函数名:fputc
        输  入:
        输  出:
        功能说明:
        重定义putc函数,这样可以使用printf函数从串口1打印输出
*/
int fputc(int ch, FILE *f)
{
        /* Place your implementation of fputc here */
        /* 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;
}

/*******************************************************************************
        函数名:fputc
        输  入:
        输  出:
        功能说明:
        重定义getc函数,这样可以使用scanff函数从串口1输入数据
*/
int fgetc(FILE *f)
{
        /* 等待串口1输入数据 */
        while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
        {}

        return (int)USART_ReceiveData(USART1);
}







回复

使用道具 举报

发表于 2014-4-18 17:10:05 | 显示全部楼层
在工程选项里把微库勾上看看

K{FN613F2`AL@HVB(]KY`BS.jpg
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-4-18 17:14:41 | 显示全部楼层
勾了。也是这样。
回复 支持 反对

使用道具 举报

发表于 2014-4-18 17:33:59 | 显示全部楼层
mingguo001 发表于 2014-4-18 17:14
勾了。也是这样。

勾了之后,清理工程整个工程重新编译一下
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-4-19 11:13:51 | 显示全部楼层
弄好了 是MDK的版本问题 换了一个4.72就没问题了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-23 00:25 , Processed in 0.036915 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表