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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
4,954 次查看
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 解答
4,174 次查看
Ray_V
Contributor V

you need to define symbol

PRINTF_ADVANCED_ENABLE=1

in your build settings

在原帖中查看解决方案

13 回复数
4,174 次查看
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

4,174 次查看
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 项奖励
4,174 次查看
converse
Senior Contributor V

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

0 项奖励
4,174 次查看
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 项奖励
4,174 次查看
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 项奖励
4,175 次查看
Ray_V
Contributor V

you need to define symbol

PRINTF_ADVANCED_ENABLE=1

in your build settings

4,175 次查看
jerrylian
Contributor IV

Thanks Raymundo,

Your answer works for me!

0 项奖励
4,175 次查看
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 项奖励
4,176 次查看
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 项奖励
4,176 次查看
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 项奖励
4,176 次查看
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 项奖励
4,176 次查看
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 项奖励
4,176 次查看
converse
Senior Contributor V

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

0 项奖励