TMS320F2808: printf() format specifiers do not work, however they do work in sprintf().

Part Number: TMS320F2808

Tool/software:

The following code snippet...

    unsigned loop_count = 0;
    for (;;loop_count++)
    {
        static char scratch_buffer[40];
        printf("Hello from printf() %u!\n", loop_count);
        unsigned int length = sprintf(scratch_buffer, "Hello from sprintf() %u!\n", loop_count);
        HAL_UART_TX(&keypad_uart, (uint8_t*) scratch_buffer, length, HAL_ms_to_timer_counter(10000));

        stopwatch_delay(stopwatch_s_to_ticks(1));
    }
...produces the following output:
I.e. the format specifier %u doesn't work with printf(), but it does work with sprintf().
A few points:
  • Using CCS Version 20.2.0.12__1.8.0.
  • Simple app.  Pretty much just the above loop in main().
  • fputc() has been replaced to output stdout to SCI.
  • Stack size set to 0x400.
  • Heap size set to 0x800.
Are there any suggestions on how to fix this?
Thanks!
Bruce
  • Hi Bruce,

    We will get back to you on this.

    Best Regards,

    Aishwarya

  • Thanks Aishwarya,

    A few additional notes...

    • Not all format specifiers fail.  %s seems to work OK.  %d and %u don't.
    • Given that sprintf() seems to work OK, as a temporary quick-fix I'll create a printf_replacement() using sprintf() and use a compile time macro to replace instances of printf() with that. 

    Thanks again!

    Bruce

  • Hi Bruce,

    A couple things to check:

    1. Are you using one of the printf_support flags in your project? If not, can you try adding the printf_support=full option and see if it changes the behavior? You can check/add the flag by right clicking on the project and selecting Properties >>  Build >> C2000 Compiler >> Edit Flags.
    2. Also, can you check your .map file and see which function is being linked for printf to see which runtime lib file is being pulled in?

    Best Regards,

    Delaney

  • I'm trying to use 'nofloat'...

    When I select 'minimal', compile time errors result.

    Selecting 'full' has the same behavior.

    Here is the entry from the .map file when 'nofloat' is selected...

    .text      0    003f4000    0000330d     
                      003f4000    00000922     led_control.obj (.text)
                      003f4922    000006ce     processor_tasks.obj (.text)
                      003f4ff0    000005ca     rts2800_ml.lib : _printfi.c.obj (.text:__TI_printfi_nofloat)
                      003f55ba    0000030a     UART.obj (.text)