cancel
Showing results for 
Search instead for 
Did you mean: 

Read one byte from Flash memory

giovanni2
Associate II
Posted on May 29, 2014 at 15:46

Hi,

I am working with STM32F303, and I need a suggestion to directly read one byte, in particular, the most significant byte from a flash memory address.

I have tried some code, like the one below but I pick every time the LSB.

For example after a page erase operation I write at the address 0x08036000 the next 32bit value 0xDD0000EE.

After this code:

Address = 0x08036000 ;

 

 var8pointer = (uint8_t*)Address;

 

 var8 = *var8pointer;

in the 8 bit variable var8 I find the value 0xEE, the LSB!

The var8pointer should be a pointer to an 8bit unsigned so i was expected to read the value in the first address (should be 0xDD) and not the one in the first address+4...

This behaviour is related to the endian organizzation of the core?

Or, am I totally wrong?

Is there a solution, excluding >> operation on a 32bit variable?

Thanks

4 REPLIES 4
chen
Associate II
Posted on May 29, 2014 at 16:02

Hi

''This behaviour is related to the endian organizzation of the core?''

Yes, correct.

''For example after a page erase operation I write at the address 0x08036000 the next 32bit value 0xDD0000EE.''

You have assumed Big Endian by doing this.

giovanni2
Associate II
Posted on May 29, 2014 at 16:11

Hi an thanks for you answer.

You say '' You have assumed Big Endian by doing this'', but is something I can change at workbench tools option, in some way or, not?

Posted on May 29, 2014 at 16:22

The endian-ness is defined by the core, the LSB is first

var8pointer[0] = LSB

var8pointer[3] = MSB (of 32-bit)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chen
Associate II
Posted on May 29, 2014 at 16:40

Hi

Adopted a simple methodology:

If you want bytes - always work in bytes

If you want long words (32bit) - always work in long words.

So for example - you want to write 0xDD0000EE to 0x08036000

Then you need to break this up into

0xdd

0x00

0x00

0xee

Then write each as a byte and increment the byte pointer.

Sounds tedious but it gets round the problem of endianess!

''but is something I can change at workbench tools option, in some way or, not?''

Yes, the ARM reference manual says there is a bit in a register which controls endianess.

I have not come across anyone who has reported using it.

I certainly would not change it mid program (if that is what you are considering)!