While using pointers and structures, some times i getting this Fault.
When does this Fault occurs(Unaligned Access) ?
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.
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.
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.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.