cancel
Showing results for 
Search instead for 
Did you mean: 

Endian problem on STM32 reading Flash

PGood.1
Associate II

I am  reading 64bit values from flash

uint64_t DATA_read = *(__IO uint64_t *)0x0801E010;

Where THE FLASH ADDERSS 0x0801E010 contains 5A5A5A5A 00440040

DATA_read value afer this read is 0x400044005a5a5a5a

if I read

uint64_t DATA_read = *(__IO uint64_t *)0x0801E010;

Where THE FLASH ADDERSS 0x0801E010 contains 0F00A007 4342A17F DFFEF9B6 3783E0F6

DATA_read value afer this read is Hex:0x7fa1424307a0000f

if I read it in 8 bit chunks is works fine

 uint32_t StartAddress=0x0801C000;

for (int i=0; i<16; i++)

{

Rx_Data[i]= *(uint8_t *)StartAddress++;

}

4 REPLIES 4

Clearly, you are displaying the 64-bit values and whatever THE FLASH ADDERSS is, in different endianity.

I guess, THE FLASH ADDERSS is something coming from a tool (debugger?) displaying in big endian. STM32 is little endian only.

JW

PGood.1
Associate II

The issue is that it reads each uint8_t of the uint64_t but puts the most signnificant Byte at the least significant position so a number that starts with 0F00A007 ends up ending with 07A0000F reversing the bytes.

PGood.1
Associate II

Im using CUBEIDE_1.3.0 downloaded from ST

TDK
Guru

> puts the most signnificant Byte at the least significant position

As JW says, that is what happens on a little endian system. You'll need to adjust how you interpret the value. There is no way to change the STM32 to store values in big endian format.

If you feel a post has answered your question, please click "Accept as Solution".