nRF52832 unaligned memory access

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);
I replaced the same using a memcpy which will do a byte copy and it does work. 

memcpy(pDstPtr, pSourcePtr, sizeof(Struct A));

Parents
  • 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  ,

    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 ?

Reply Children
Related