Hi,
Does not nRF52832 support unaligned memory access ?
I had an instruction like this for which the FW was crashing.
Struct A a= *((Struct A*)pSourcePtr);
memcpy(pDstPtr, pSourcePtr, sizeof(Struct A));
Hi,
Does not nRF52832 support unaligned memory access ?
I had an instruction like this for which the FW was crashing.
Struct A a= *((Struct A*)pSourcePtr);
memcpy(pDstPtr, pSourcePtr, sizeof(Struct A));
Yes and no.
If sizeof(struct A) == sizeof(int64_t), it may fail depending on which CPU instructions the compiler generated. See the documentation for the LDRD instruction(s) on arm.com website - these instructions require 32-bit alignment while normal LDR/STR do not.
Other unaligned access is supported by default, but you can disable it with one of the special register bits (forgot the name though).
Hi Turbo J ,
Thank you for your reply. Yes, the size of the struct is 64 bits.
I checked the disassembly but I do not see the LDRD instruction. I think LDM too does not support unaligned memory access.
Struct A a= *((Struct A*)pSourcePtr);
If that's the case, how can one make sure that the FW does not use LDM/LDRD with unaligned memory access ? What are the best practices ?
Best practise? Call memcpy() or memmove().
One other sort of alignment excpetions I forgot to mention: FPU access (for float and double) always wants alignment.
Thanks