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.

AM574x sprintf() Function Issue

Hi,

A customer is having an issue with printing the decimal floating point format (%f) and the scientific notation format (%e) using the sprintf() function.

However, they do not have issues printing the signed decimal integer format (%d) or the string format (%s). 

For example, this code:

sprintf((char *)outbuf, "int:%d, double:%f, double:%e, string:%s, end", 12345, 1.2345, 12.345678, "abcde");

Outputs this:

outbuf = "int:12345, double:, double:, string:abcde, end"

What could be a possible issue here and how can they print correctly?

For additional information, they are using CCS v8, GCC GNU v6.3.1(Linaro).

Best regards,

Mari

  • Hi Mari,

    Are you checking for floating point support on the Linux SDK?

    - Keerthy

  • Hi Keerthy,

    Yes. To add on, they are using pdk_am57xx_1_0_11 and bios_6_76_00_08.

    Best regards,

    Mari

  • Hi Mari, 

    How are you printing the outbuf? I am able to print the values with floating point format (%f) and the scientific notation format (%e) and using UART_printf() to print the outbuf. Please find the sample output below:

     

    Also, you can try the sample binary attached below and see if it works on your setup.

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/791/sample_5F00_sprintf_5F00_idkAM574x_5F00_armv7.out

    Regards,

    Parth

  • Hi Parth,

    Thank you for your reply. This is a question from a customer so I'm unable to test it.

    This is the code snippet that they have sent me.

    They are using sprintf and not UART_printf(). Should they not be using sprintf?

    Best regards,

    Mari

  • Hi Mari,

    sprintf will put the string into a buffer, to display that buffer on console I am using UART_printf(). Due to some reason their debugger is not displaying the value of outbuff properly. I tried the same thing on CCS and I am able to read the buffer properly.

      

     

    Can you please ask them to print the buffer and see if it is proper or to try it on CCS and read the value of outbuff? 

  • Hi Parth,

    Thanks for your reply and clarifying for me. In a previous question from Keerthy, I mistakenly replied that the customer is using Linux SDK, but they are using Processor RTOS SDK. Would the sample binary you created before work on Processor RTOS SDK? I could ask the customer to try it on their set up.

    Best regards,

    Mari

  • Hi Mari,

    Yes, that binary will work on RTOS SDK, you can ask them to try it on their setup.

    Regards,

    Parth

  • Hi Parth,

    Thanks for your quick response, I'll ask them to try it.

    Best regards,

    Mari

  • Hi Parth,

    Our customer has yet to try the binary file, but as an update they sent us an image which indicates that it is most likely not a debugger display issue. It appears that it is not writing to the outbuf variable. I've attached the image below for reference.

    What else do you think could be causing this issue?

    Best regards,

    Mari 

  • Hi Mari,


    Can you confirm which core are they using for this test?


    Regards,
    Parth

  • Hi Parth,

    Thank you for your reply. They're using MPU core 0 (Cortex-A15).

    They've tried the sample binary file which you sent. It looks work correctly, but they have some questions as follows.

    1) The floating-point data is not stored in the buffer correctly in the case of their code even though it is stored correctly in the case of your binary sample.
         What's wrong in their code ?
        

    2) There are some differences in the assembly codes between your binary sample and their code.
         The both code jumps into the symbol "svfprintf_r" in the sprintf processing, but jumps into the symbol "__getreent" before jumping to "_svfprintf_r" in their code. What's this difference ?

    3) They tried to add "-u _printf_float" in the option [Properties] -> [Build] -> [GNU Linker] -> [Miscellaneous] of the CCS project, then their code works correctly.
         Did you also added this option ? or set any other similar setting ?
         They want to know this additional setting is correct solution or not.

    4)  Could you share the source code of the binary sample ? The very simple sample code would be appreciated.

    Thanks and regards,
    Hideaki Matsumoto

  • Hi,

    Could we have any update ?

    Regards,
    Hideaki

  • Hi Hideaki,

    Apologies for the delay here.

    In the readme document provided with the GCC compiler at <gccInstallPath>/share/doc/gcc-arm-none-eabi/readme.txt it is mentioned that "-u _printf_float" is needed for floating point numbers. 

    I did not have to explicitly set this flag in my case, which I believe could be because of different compiler version. Could you ask customer to test and try with GCC GNU 7.3.1 and see if that works without explicitly setting the flag.

    Also, please find the sample code here 

    #include <string.h>
    
    #include <ti/drv/uart/UART.h>
    #include <ti/drv/uart/UART_stdio.h>
    
    #include "board.h"
    #include "board_cfg.h
    
    int main(void)
    {
        char buffer[100];
        Board_initCfg boardCfg;
        boardCfg = BOARD_INIT_MODULE_CLOCK |
                   BOARD_INIT_PINMUX_CONFIG |
                   BOARD_INIT_UART_STDIO;
    
        Board_init(boardCfg);
    
        UART_printf("Sample test for sprintf\n");
        sprintf((char *)buffer, "int %d, doublef: %f, double: %e, String: %s end", 12345,1.2345,12.345678, "abcde");
        UART_printf("This is comming from sprintf %s\n", buffer);
    }
    

    Regards,

    Parth

  • Hi Parth,

    Thank you so much for your response. Unfortunately, they can't change the GCC GNU tools. In this case, the following is the correct resolution ?

    They tried to add "-u _printf_float" in the option [Properties] -> [Build] -> [GNU Linker] -> [Miscellaneous] of the CCS project, then their code works correctly.
         Did you also added this option ? or set any other similar setting ?
         They want to know this additional setting is correct solution or not.

    Thanks and regards,
    Hideaki

  • Hi Hideaki,

    They want to know this additional setting is correct solution or not.

    As mentioned in the compiler documentation "-u _printf_float" is needed to input the floating point values, so the additional setting done by them is the correct solution. 

    Did you also added this option ? or set any other similar setting ?

    I did not explicitly set this option as I am using makefiles to build the test which might be including this option somewhere. 

    Regards,
    Parth