Hi,
While using pointers and structures, some times i getting this Fault.
When does this Fault occurs(Unaligned Access) ?
Regards,
Vinoth
Hi Vinoth,
unaligned access means, that the pointer you are dereferencing is pointing to a not-aligned adress.
For best performance (to minimize the count of bus accesses) values should be aligned to their natural size, e.g. the pointer of a 16 bit value to 2-byte, 32 bit values to 4-bytes.
Example:
Assume there is a 32 bit value (0x12345678) in memory:
The pointer 0x00000010 is pointing to an aligned adress, because (0x00000010 & 0x03) = 0.
Now the 32 bit value is not aligned, because (0x00000013 & 0x03) != 0.
Cortex M3/M4 cores are able to support unaligned memory accesses, while older ARM cores don't.
Unaligned accesses should not be used in case speed is important (avoid using packed structs/arrays), but will save memory.
The generation of this fault can be turned on or off (Feature of the Cortex core). By default it is disabled, so it is very likely that there is something in your code that enables these faults.
The fault can be disabled in the Configuration Control Register.
Best regards,
Kai
The LDM, STM, LDRD and STRD instructions require aligned addresses, even on the Cortex-M3. For some reason, the compiler may be wanting to generate these instructions - this suggests that you are probably trying to copy chunks of unaligned structures around or have unaligned 64 bit values in your structures.
You are right, i am copying a chunk of data that belong to a structure through pointers. How could I solve this?
Generally memcpy is written to be safe to do memory moves regardless of alignment. Try that.
How are your structures getting unaligned? This usually takes extra effort.
Yes, It worked. Memcpy seems to be a better way to copy chunk of memory.
Thanks..