DbgConsole_PrintfFormattedData() does not implement width and precision as specified in Kinetis SDK v.2.0 API Reference Manual

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DbgConsole_PrintfFormattedData() does not implement width and precision as specified in Kinetis SDK v.2.0 API Reference Manual

769 Views
dan_teodorescu
Contributor III

Hello,

 

I am trying to print a string of a width specified as an argument using the following syntax, as described on cppreference.com (std::printf, std::fprintf, std::sprintf, std::snprintf - cppreference.com )

 

`

 const char* s = "Hello";
 PRINTF("\t[%10s]\n\t[%-10s]\n\t[%*s]\n\t[%-10.*s]\n\t[%-*.*s]\n",
 s, s, 10, s, 4, s, 10, 4, s);

`

 

According to the Kinetis SDK v.2.0 API Reference Manual, I expect to see the same result as the reference output on cppreference.com, which is the following

`

 [ Hello]
 [Hello ]
 [ Hello]
 [Hell ]
 [Hell ]
`

 

Instead I see the following output.
`
 [ Hello]
 [Hello ]
 [*s]
 [*s]
 [*.*s]
`

I verified that PRINTF_ADVANCED_ENABLE is defined and that code is included in my executable, by stepping through DbgConsole_PrintfFormattedData(). Preliminary analysis seems to indicate that support for argument-based (`*`) width or precision is not implemented, contrary to the SDK API Reference Manual.

 

Please confirm if I am overlooking any compilation setting that corrects this issue, or if you plan on addressing this in an upcoming SDK release.

 

Thank you,

Dan

Labels (1)
0 Kudos
2 Replies

514 Views
isaacavila
NXP Employee
NXP Employee

Hello Dan,

I've made a quick review on this fsl_debug_console.c file and in fact, it seems that width and .precision are not supported when an argument is passed (documentation is wrong on this point). I will ask KSDK team if this is supposed to be added in next releases.

For now, If you want to add these feature (it is not difficult), you need to add some extra logic to current DbgConsole_PrintfFormattedData function. I am attaching fsl_debug_console.c with this modifications where you can locate preprocessor conditionals for all logic needed to implement these parameters. (You can enable this macro (PRINTF_WIDTH_AS_PARAMETER = 1) on preprocessor's definitions to enable this extra logic). I modified the hello_world example and added these printing messages:

    PRINTF("\t[%10s]\n\r", s);
    PRINTF("\t[%-10s]\n\r", s);
    PRINTF("\t[%*s]\n\r", 10, s);
    PRINTF("\t[%-10.*s]\n\r", 4, s);
    PRINTF("\t[%-*.*s]\n\r", 10, 4, s);‍‍‍‍‍

And this is what I got:

Console.jpg

I hope this can help you!

Regards,

Isaac

514 Views
dan_teodorescu
Contributor III

Hi Isaac,

I am getting the same results as you are with the attached fix.

Thank you for the response and for providing the fix.

Best regards,

Dan

0 Kudos