zoukankan      html  css  js  c++  java
  • 在MDK中使用 printf 函数

    microlib 提供了一个有限的 stdio 子系统,它仅支持未缓冲的 stdinstdout 和 stderr。 这样,即可使用 printf() 来显示应用程序中的诊断消息。

    要使用高级 I/O 函数,您必须提供自己实现的以下基本函数,以便与您自己的 I/O 设备配合使用。

    fputc() 

    为所有输出函数实现此基本函数。 例如,fprintf()printf()fwrite()fputs()puts()putc() 和 putchar()

    fgetc() 

    为所有输入函数实现此基本函数。 例如,fscanf()scanf()fread()read()fgets()gets()getc() 和 getchar()

    __backspace() 如果输入函数使用 scanf() 或 fscanf(),则实现此基本函数。Notemicrolib 中不支持的转换为 %lc%ls 和 %a

    下面是完整的资料:

    keil (我用的是realview mdk3.11)建立ARM的工程时其中有一项是选 use MicroLIB

     

    调整 microlib 输入/输出函数microlib 提供了一个有限的 stdio 子系统,它仅支持未缓冲的 stdinstdout 和 stderr。 这样,即可使用 printf() 来显示应用程序中的诊断消息。要使用高级 I/O 函数,您必须提供自己实现的以下基本函数,以便与您自己的 I/O 设备配合使用。fputc() 为所有输出函数实现此基本函数。 例如,fprintf()printf()fwrite()fputs()puts()putc() 和 putchar()fgetc() 为所有输入函数实现此基本函数。 例如,fscanf()scanf()fread()read()fgets()gets()getc() 和 getchar()__backspace() 如果输入函数使用 scanf() 或 fscanf(),则实现此基本函数。Notemicrolib 中不支持的转换为 %lc%ls 和 %a

     

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/laorenshen/archive/2009/11/07/4782339.aspx

     

    想在mdk 3.80a中用printf,需要同时重定义fputc函数和避免使用semihosting(半主机模式), 

    发现在Options里选上microlib之后,就不用关闭半主机模式了。

     

    int fputc(int ch, FILE *f)
     {
         //USART_SendData(USART1, (u8) ch);
         USART1->DR = (u8) ch;
         
         /* Loop until the end of transmission */
         while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
         {
         }

         return ch;
     }

     

     

  • 相关阅读:
    Leetcode---2. Add Two Numbers
    Leetcode---1. Two Sum
    dpkg:处理 xxx (--configure)时出错解决方案
    ubuntu 14.04搭建tensorflow-gpu开发环境
    Leetcode---35. Search Insert Position
    Leetcode---21. Merge Two Sorted Lists
    Leetcode----26. Remove Duplicates from Sorted Array
    Leetcode---28. Implement strStr()
    Leetcode----27 Remove Element
    qemu 安装 ubuntu-server 虚拟机
  • 原文地址:https://www.cnblogs.com/scdyxcc/p/3034821.html
Copyright © 2011-2022 走看看