This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/CC430F5137:为什么 IAR 可以使用相同的代码将"printf()&quot 重定向到"UART"但 Code Composer Studio 不能这样做?

Guru**** 2024750 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/783438/ccs-cc430f5137-why-is-it-that-iar-can-redirect-printf-to-uart-with-the-same-code-but-code-composer-studio-cannot

器件型号:CC430F5137

工具/软件:Code Composer Studio

1、相同 代码:

#include "msp430.h"
#include "stdio.h"

float A=10.5;

/**
* main.c
*
int main (空)

WDTCTL = WDTPW | WDTHOLD;//停止看门狗计时器
while (1)

printf ("%f"、a);

int fputc (int _c、寄存器文件*_fp)

while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF =(无符号字符)_c;
return ((unsigned char)_c);

2、printf 支持

3、代码大小

4、为什么 CCS 使用大代码量、但仅支持 print ("%s")、而不支持 print ("%f")和 print ("%d")、而 IAR 使用小代码量、但支持所有代码?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    [引用 user="user4324449">为什么 CCS 使用大代码量、但仅支持 print ("%s")、而不支持 print ("%f")和 print ("%d")我查看了使用 TI MSP430编译器 v18.1.5.LTS 的示例

    当调用 printf()来格式化 float "%f"或整数"%d"时,运行时库内部会使用格式化的输出构建一个字符串,然后调用 fputs()来输出格式化的字符串。 因此,在程序中添加 fputs()函数的实现。 例如:

    int fputs (const char *_ptr、file *_fp)
    {
    while ((*_ptr)!='\0')
    {
    fputc (*_ ptr、_fp);
    _PTR++;
    }
    
    返回0;
    } 

    我发现添加 fputs()也减少了程序使用的 RAM 和闪存数量,但仍然使用了更多的 IAR 内存。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    谢谢