We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
test code: static int buffer[128];
memcpy_test(int * p) { memcpy(buffer, p, 128); }
memcpy_test(0x00000000) ==> OK memcpy_test(0x00000001) ==> unalign fault
use MDK libc memcpy, when dst or src is align, auto higher optimization to used memcpy4.
but use instruction LDM. so, if the arg p is unalign, fault....
info: cortex-M3/M4 MDK 3.x/4.x/5.x
quote arm doc: The Cortex-M4 processor supports unaligned access only for the following instructions: • LDR, LDRT • LDRH, LDRHT • LDRSH, LDRSHT • STR, STRT • STRH, STRHT All other load and store instructions generate a UsageFault exception if they perform an unaligned access, and therefore their accesses must be address aligned
Unaligned LDM, STM, LDRD, and STRD instructions always fault irrespective of whether UNALIGN_TRP is set to 1.
infocenter.arm.com/.../index.jsp
update code: memcpy_test(char * p) { memcpy(buffer, p, 128); }
quote arm: The ARM compiler assumes that all pointers are naturally-aligned (i.e. int* is word-aligned, short* is halfword-aligned, etc.).
:-)
Unless you set your warning level dangerously low, you got a compiler warning about using an integer where a pointer was supposed to be, on the very line that caused the problem.
You should have heeded that warning.