Skip to main content
Associate II
April 30, 2024
Solved

printf %llu with error

  • April 30, 2024
  • 2 replies
  • 3700 views

Hi guys,

I'm executing the "printf" in CubeIDE to output uint64_t with "%llu", but the printout is wrong.

Why does it not support "%llu"?

However it can work well in Keil.

 

//debug.c
int __io_putchar(int ch) //Redirect printf to uart
{
 HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
 return (ch);
}


//main.c
int main()
{
//***
printf("%llu\r\n", (uint64_t)1 ); //Hope to output "1", but output "lu"
}

 

 

 

 

    Best answer by PeterMu

    Hi,

    Thanks for answering, I found that CubeIDE uses the "reduced C", and the problem can be solved by modifying to "standard C" .

    2 replies

    Pavel A.
    Super User
    April 30, 2024

    This is because the C runtime library in the GNU toolchain supplied with CubeIDE has limited implementation of printf. It does not support %ll and some other formats. Keil MDK provides their own runtime library, high quality and thread aware. This is one of reasons why Keil MDK is worth its price ))

     

    PeterMuAuthorBest answer
    Associate II
    April 30, 2024

    Hi,

    Thanks for answering, I found that CubeIDE uses the "reduced C", and the problem can be solved by modifying to "standard C" .

    AScha.3
    Super User
    April 30, 2024

    Hi,

    just a simple test : what its doing with :  "%lu" ?

    printf("%lu\r\n", (uint64_t)1 ); 

     

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    PeterMuAuthor
    Associate II
    April 30, 2024

    I used a ftp server lib which actually used "%llu",this makes my project cannot work. because it returns wrong message from ftp server.