Endianess Problem with 64 bit datatype

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

Endianess Problem with 64 bit datatype

Jump to solution
1,752 Views
karthigeyannata
Contributor III

We are developing software on vybrid processor(A5 core). We are facing issues with the 64 bit data type. When we tried to print the value using printf or sprintf, the values are printed wrongly.

Then we had identified that it is beacause of endian problem. The Lower 32 bit value is placed in upper 32 bit place and so the it is printing big numbers even for small value

for example when we tried to print the value 0x19 of long long int data type, it is printed as 0x1900000000.

Please let us know , how to overcome this issue.

Note : We are using gcc compiler

0 Kudos
Reply
1 Solution
1,412 Views
ioseph_martinez
NXP Employee
NXP Employee

Karthi,

I verified this. Is working fine on my side.

I am using: MQX 4.0.2 Beta 1

Compiler: Sourcery CodeBench Lite Edition for ARM EABI from mentor graphics

Example: Hello

So please do the following:

- download Sourcery CodeBench Lite Edition for ARM EABI from mentor graphics GCC compiler

- obtain from your FAE: MQX 4.0.2 Beta 1

- compile hello example using gcc_cs tool chain mentioned above.

- modify and try using long long type.

Let us know your results. Again, the most important step is the toolchain. If the toolchain you are using does not supports the proper printf it will fail.

On my side, IAR, and gcc from CodeSourcery work correctly.

Best Regards,

Ioseph

code:

unsigned long long my64var;

void hello_task

    (

        uint_32 initial_data

    )

{

  my64var = 0x12345UL;

    printf("Hello World\n");

    printf("Hello World\n");

    printf("%llx", my64var);

    _task_block();

}

output:

Hello World

Hello World

12345

View solution in original post

0 Kudos
Reply
9 Replies
1,412 Views
ioseph_martinez
NXP Employee
NXP Employee

Hello,

I think the problem is printf and not the compiler. I tried this on IAR compiler and the way words are ordered is the same as in your case.

For example:

tst = 0x10;

tst = tst + 0xffffffff;

tst = 0x000000010000000F

The printf I am using does not supports printing 64 bits. Please check if in your case the printf supports that size.

See the attached picture of my debug session and how the 64bit integer is handled correctly.

1,412 Views
karthigeyannata
Contributor III

how to fix this issue in sprintf which is library function?...

How to get rid of this issue?

0 Kudos
Reply
1,412 Views
ioseph_martinez
NXP Employee
NXP Employee

Hi,


Can you please give more details on what tool chain you are using?

Are you using Linux Timesys? OS Less or MQX

From which vendor/where you got your gcc-compiler?

Have you check for any compiler options, flags or documentation notes? Your library seems to support at some degree or may be some port from another system.

This sounds similar: Andrés Moré - Re: printf of unsigned long long in ARM processors, please take a look. If the issue comes from gcc codesourcery they will be the best to answer.

0 Kudos
Reply
1,412 Views
karthigeyannata
Contributor III

Hi,


Please find the details.

We are using MQX and using gcc compiler version 4.5.2

Could you please provide your inputs on this ASAP?

Thanks

karthi

0 Kudos
Reply
1,413 Views
ioseph_martinez
NXP Employee
NXP Employee

Karthi,

I verified this. Is working fine on my side.

I am using: MQX 4.0.2 Beta 1

Compiler: Sourcery CodeBench Lite Edition for ARM EABI from mentor graphics

Example: Hello

So please do the following:

- download Sourcery CodeBench Lite Edition for ARM EABI from mentor graphics GCC compiler

- obtain from your FAE: MQX 4.0.2 Beta 1

- compile hello example using gcc_cs tool chain mentioned above.

- modify and try using long long type.

Let us know your results. Again, the most important step is the toolchain. If the toolchain you are using does not supports the proper printf it will fail.

On my side, IAR, and gcc from CodeSourcery work correctly.

Best Regards,

Ioseph

code:

unsigned long long my64var;

void hello_task

    (

        uint_32 initial_data

    )

{

  my64var = 0x12345UL;

    printf("Hello World\n");

    printf("Hello World\n");

    printf("%llx", my64var);

    _task_block();

}

output:

Hello World

Hello World

12345

0 Kudos
Reply
1,412 Views
karina_valencia
NXP Apps Support
NXP Apps Support

Hi ioseph_martinez can you  continue with   the follow up of this  case?

This is not solved yet.

0 Kudos
Reply
1,412 Views
jeffreycoffman
Contributor III

You data type wouldn't happen to be IEEE754 double?

0 Kudos
Reply
1,412 Views
karina_valencia
NXP Apps Support
NXP Apps Support

ioseph_martinez  / juangutierrez can you  help on this case?

0 Kudos
Reply
1,412 Views
juangutierrez
NXP Employee
NXP Employee

How are you printng?

Have you tried to use %llu?

    printf("%llu", my64var);

0 Kudos
Reply