2026-03-30 9:28 AM
Using STM32CQubeCLT 1.20's libnano:
I am trying to print an uint64_t using inttypes.h via an vsnprintf(line, sizeof(line), fmt, ap) wrapper and the sending the line via UART to a Terminal.
However, using print_wrapped("%" PRIu64"\n", (uint64_t)1) gives only an output of "lu\n".
I know that for floating point support I need to add -u _printf_float to the linker options. Is there something similar for 64bit integers? Or do I have to compile my own version of libnano?
2026-03-31 1:47 AM - edited 2026-03-31 1:49 AM
Yes, 64-bit is not supported in some minimal versions of newlib, similar to float. Try the "full" library or alternative printfs. If you can build your own newlib or picolibc - great. What is print_wrapped?
2026-03-31 3:29 AM
Thanks for the insight. Is there some documentation about this?
Here is the print_wrapped code:
void print_wrapped(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprint_wrapped(fmt, ap);
va_end(ap);
}
void vprint_wrapped(const char *fmt, va_list ap)
{
static char line[PRINTK_LINE_LENGTH];
int len;
if (write_uart == NULL) {
return;
}
line[0] = 0;
len = vsnprintf(line, sizeof(line), fmt, ap);
if (len > 0) {
write_uart(line, len);
}
}
2026-03-31 4:21 PM
IIRC somewhere in the ST git repositories there is a configuration or build script for their newlib-nano.
But the simplest way is just test sprintf( "%lld", ...) with nano and full library.
You can check at build time is the newlib-nano library selected or not, and whether it supports printing 64-bit:
#include <newlib.h>
#pragma message _NEWLIB_VERSION
#if _WANT_IO_LONG_LONG
#pragma message "Print %ll supported"
#endif
#if _WANT_IO_C99_FORMATS
#pragma message "C99 print formats supported"
#endif
#if _NANO_FORMATTED_IO
#pragma message "Using nano lib"
#endif