Skip to main content
Pawel Pielorz
Associate
May 7, 2017
Solved

Printf length modifier problem

  • May 7, 2017
  • 2 replies
  • 1122 views
Posted on May 07, 2017 at 23:19

Hello,

I have encountered problem with printf function. I am using CycloneTCP stack, where %hhu identifiers were used and workeg good. I tried to port demo applications to CubeMX etc and I got eferything working well besides printf with %hhu identifiers.

I have created new project with only this function in it, here is the part of code:

size = sprintf(buffer, '%u, %hu, %hhu\n', 123, 123, 123);

HAL_UART_Transmit_IT(&huart3, buffer, size);

What I get is:

123, 123, hu

Doing the same in original demos of stack mentioned above give good results. What I tried is to change language standard to C11 but it didn't make any change.

 Have you met such a problem?

Regards,

Pawel

#printf #stdio
    This topic has been closed for replies.
    Best answer by Pawel Pielorz
    Posted on May 08, 2017 at 16:00

    Hi, 

    Thank you for your reply. As you told, it was connected with toolchain, linker, to be specific. I have found solution:

    Project properties -> C/C++ Build -> Settings -> MCU GCC Linker -> Miscellaneous

    Remove  '-specs=nano.specs' from Linker flags. I don't know whi I didn't notice it earlier...

    Regards

    2 replies

    Max
    ST Employee
    May 8, 2017
    Posted on May 08, 2017 at 11:07

    Hello,

    The standard libraries are coming from the compiler toolchain you are using.

    If you want any relevant answer to your question, you should at least provide the compiler and the revision you are using. 

    You may get better help on the compiler support channel...

    Pawel Pielorz
    Pawel PielorzAuthorBest answer
    Associate
    May 8, 2017
    Posted on May 08, 2017 at 16:00

    Hi, 

    Thank you for your reply. As you told, it was connected with toolchain, linker, to be specific. I have found solution:

    Project properties -> C/C++ Build -> Settings -> MCU GCC Linker -> Miscellaneous

    Remove  '-specs=nano.specs' from Linker flags. I don't know whi I didn't notice it earlier...

    Regards