2014-05-29 06:46 AM
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?Thanks2014-05-29 07:02 AM
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.2014-05-29 07:11 AM
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?2014-05-29 07:22 AM
The endian-ness is defined by the core, the LSB is first
var8pointer[0] = LSB var8pointer[3] = MSB (of 32-bit)2014-05-29 07:40 AM
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)!