How to print 64-bit data type (to UART console)?

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

How to print 64-bit data type (to UART console)?

Jump to solution
6,635 Views
jerrylian
Contributor IV

In MCUXpresso-IDE, when I use CMSIS-DSP function: arm_dot_prod_q15() :

* I got a "q63_t" type data: result = 5 (I debug with break-point)

* But when I print with: 

            PRINTF("data: %X \r\n", result);  ===>  data: 430C0000       (It should be: data: 5)

So what is wrong, how to deal with "q63_t" data type? 

Thanks!

Jerry

1 Solution
5,855 Views
Ray_V
Contributor V

you need to define symbol

PRINTF_ADVANCED_ENABLE=1

in your build settings

View solution in original post

13 Replies
5,855 Views
lpcxpresso_supp
NXP Employee
NXP Employee

Is your PRINTF being vectored onto the SDK DEBUGCONSOLE output (typically output via UART), or the C library's printf function (typically output via semihosting) ? See section 11.5 "Use of printf" of the MCUXpresso IDE v10.0.0 User Guide for more background on this.

Might be useful to see your actual project (use Quickstart Panel -> Export option), or at least see the content of your build console after doing a clean build.

Regards,

MCUXpresso IDE Support

5,855 Views
jerrylian
Contributor IV

Hi, LPCX support:

I export and upload my project (base on "demo hello world" project).

Please check why I can't print 64-bit values to UART console.

Thanks!

Jerry

0 Kudos
Reply
5,855 Views
converse
Senior Contributor V

Sorry, I am not going to debug your project for you.

0 Kudos
Reply
5,855 Views
jerrylian
Contributor IV

no worries. I am providing the project upon the request of the guy "LPCX support", he seems to be NXP staff.

0 Kudos
Reply
5,855 Views
jerrylian
Contributor IV

I am somewhat confused by so many print functions.

But now I have more observations: (I am printing via UART, and just using templates from demo projects)

-----------------------------------------------------------------------------------------------------------

uint64_t v1=12;

uint32_t v2=34;

uint16_t v3=56;

PRINTF("values: %d %d %d \r\n", v2, v2, v3);     ===>  values: 34 34 56
PRINTF("values: %d %d %d \r\n", v1, v2, v3);     ===>  values: 536935956 12 0

-------------------------------------------------------------------------------------------------------------

So obviously (by the way, I am testing on board TWR-K60D100M):

* Printing 64-bit values messes up everything!

So how to fix this bug?

0 Kudos
Reply
5,856 Views
Ray_V
Contributor V

you need to define symbol

PRINTF_ADVANCED_ENABLE=1

in your build settings

5,856 Views
jerrylian
Contributor IV

Thanks Raymundo,

Your answer works for me!

0 Kudos
Reply
5,856 Views
converse
Senior Contributor V

The bug is in your code... %d is trying to print a 32 bit value only. To tell printf that is is a 64-bit value, you need to use %lld. Suggest you read about printf formatting codes.

0 Kudos
Reply
5,857 Views
jerrylian
Contributor IV

Thanks, but I tried both "%ld" and "%lld", all seem to be wrong code, it just print:

PRINTF("values: %lld %d %d \r\n", v1, v2, v3);                 ===>                 values: lld 536935956 12

So what is the correct format code for 64-bit value?

0 Kudos
Reply
5,857 Views
converse
Senior Contributor V

I have just run this code

        uint64_t v1=12;

        uint32_t v2=34;

        uint16_t v3=56;

        printf("values: %lld %d %d \r\n", v1, v2, v3);

        printf("values: %d %d %lld \r\n", v3, v2, v1);

which gives this output

values: 12 34 56

values: 56 34 12

i.e. it works as expected.

0 Kudos
Reply
5,857 Views
jerrylian
Contributor IV

* what IDE did you use?

* And did you print inside IDE? I use PRINTF to print to UART (SDK DEBUG CONSOLE).

(I guess PRINTF == printf if you print inside IDE. BUT it seems that printf can't print to UART!)

0 Kudos
Reply
5,857 Views
converse
Senior Contributor V

I used MCUXpresso IDE. Yes, I printed to the console. Suggest you try the same to track down the issue.

Your previous post was interesting. You said the output was

PRINTF("values: %lld %d %d \r\n", v1, v2, v3);                 ===>                 values: lld 536935956 12

i.e. the (underlying) printf you are using does not understand %lld formatting, which implies that it is incapable of printing 64 bit values. So, try using standard printf to print to the console, then gradually change other things until you find the issue.

0 Kudos
Reply
5,857 Views
converse
Senior Contributor V

What is PRINTF? what is wrong with using just printf?

0 Kudos
Reply