cancel
Showing results for 
Search instead for 
Did you mean: 

PRIu64 not wotking using libnano

MGeri.1
Associate II

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?

 

3 REPLIES 3
Pavel A.
Super User

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?

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);
	}
}

 

Pavel A.
Super User

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