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.

msp430 printf() fail. why?

Other Parts Discussed in Thread: MSP430F5438A

Hello,

the subject: printf () is incorrect, also printf () of float is incorrect. why??
==================================================
I'm using with the msp430f5438A.
and i encounter with printing problem,
especially when the program print float number.

the environment
IDE: CCS 5.3.
compiler version :  TI v4.1.2
output format: eabi (ELF).
lib: rts430x_sc_sd_eabi.lib ( from the map file)
using jtag: MSP-FET430UIF
CCs is full version licensed.



the compiler option:
--------------------
-vmspx --abi=eabi --code_model=small --data_model=small
 -g --include_path="C:/ti/ccsv5/ccs_base/msp430/include"
--include_path="C:/ti/ccsv5/tools/compiler/msp430_4.1.2/include"
--include_path="H:/Workplace/ImpTest/impT1/hdr"
--include_path="H:/Workplace/ImpTest/impT1/hdr"
--advice:power="all" --define=__MSP430F5438A__
--diag_warning=225 --display_error_number --diag_wrap=off
--silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU23
--silicon_errata=CPU40 --printf_support=full

the linker option:
-----------------
-vmspx --abi=eabi --code_model=small --data_model=small -g
--advice:power="all" --define=__MSP430F5438A__ --diag_warning=225
--display_error_number --diag_wrap=off --silicon_errata=CPU21
--silicon_errata=CPU22 --silicon_errata=CPU23 --silicon_errata=CPU40
--printf_support=full -z --stack_size=1024 -m"impV1.map" --heap_size=1024
--use_hw_mpy=F5 -i"C:/ti/ccsv5/ccs_base/msp430/include"
-i"C:/ti/ccsv5/tools/compiler/msp430_4.1.2/lib"
-i"C:/ti/ccsv5/tools/compiler/msp430_4.1.2/include"
--reread_libs --warn_sections --display_error_number --diag_wrap=off --rom_model


option ( that i sign):
--------------------------
i also follow all the instruction how to use printf().
hence, i sigh the check box:
properties->Debug->enable CIO function use


i start with program 1 with simple printf.
and the printing was incorrect.


===========================================================================
***  example: program 1 : check regular( no float) printf to the console***
===========================================================================
#include <stdio.h>
void main()
{
    printf("this line suppose to be printed just once\n");
    while (1)
    {
        printf("infinite message: Hello world!\n");
    }
}


 result (that was printed to the console):
==========================================
infinite message: Hello world!
infinite message: Hello world!
this line suppose to be printed just once
infinite message: Hello world!
infinite message: Hello world!
infinite message: Hello world!
this line suppose to be printed just once
infinite message: Hello world!
infinite message: Hello world!
=================================

the question #1  is:
----------------
1. the message  that supposed to be printed just once,
is printed periodically.
 why??

================================================================
***  example: program 2 : check float printf ( to console)   ***
================================================================
#include <stdio.h>
float fnum = 1.3;
void main()
{
    fnum = 1.9;
    printf("print once: fnum = %f\n",fnum);
    while (1)
    {
        printf("infinite printing: fnum = %f\n",fnum);
    }
}

 result:
==========
nothing is printed.

 question #2 is:
----------------
what is worng with float printing??


============================================================
***  example: program 3 : check regular sprintf to buffer **
============================================================
in order to eliminate the effects of rtdx
i print the messages to buffer

#include <stdio.h>
#include <string.h>
#define SIZE 120
char buf[SIZE];
int cnt = 5;
const char *str[] = {"start\n",
        "infinite printing\n",
        "END\n"};
int i = 0;
void main()
{
    sprintf(&buf[0], str[0]);
    i += strlen (str[0]);
    if (i > SIZE)
    {
        i = 0;
    }
    while (cnt--)
    {
        sprintf(&buf[i], str[1]);
        i += strlen (str[1]);
        if (i > SIZE-20)
        {
            i = 0;
        }
    }
    sprintf(&buf[i], str[2]);
    if (i > SIZE-20)
    {
        i = 0;
    }
    while (1)
    {;}
    return;
}

the result:
the buffer look fine.
all the strings were printed correctly

===============================================================
***  example: program 4 : check sprintf of float into buffer **
===============================================================

now , i add the the previous program float printing.

 #include <stdio.h>
#include <string.h>
#define SIZE 120
char buf[SIZE];
int cnt = 5;
float fnum = 1.3;
const char *str[] = {"start, %f\n",
        "infinite printing %f\n",
        "END %f\n"};
int i = 0;
void main()
{
    fnum = 1.9;
    sprintf(&buf[0], str[0], fnum);
    i += strlen (str[0]);
    if (i > SIZE)
    {
        i = 0;
    }
    while (cnt--)
    {
        sprintf(&buf[i], str[1], fnum);
        i += strlen (str[1]);
        if (i > SIZE-20)
        {
            i = 0;
        }
    }
    sprintf(&buf[i], str[2], fnum);
    if (i > SIZE-20)
    {
        i = 0;
    }
    while (1)
    {;}
    return;
}

the result:
----------
the printing was wrong.
except the first string ("start") . nothing
was printing. no float and no other strings.

so , it's obvious the the rtdx is not the reason to the
printing malfunction.

 question #3 is:
----------------
3. what get wrong with the float printing?

thanks.

**Attention** This is a public forum