Hard fault caused by unaligned access
Hi,
I have an issue when trying to copy a struct by direct assignment on STM32H743;
The code:
void function(const structName_t *incomingStruct) {
Signal_t sendSignal;
sendSignal.desiredStruct = *incomingStruct; // <-- Causes unaligned access
..
}
If desiredStruct consists of only 8 or 16 bits fields, everything works perfectly. If however, one or more of the fields is 32-bits, then the SCB->CFSR->UNALIGNED bit goes high and the programs enters the hard_Fault handler after line 5. I do have a quick fix on this; declaring the desiredStruct as __attribute__((__packed__)). However, as other projects running on STM32F7 use the same library without any issues, I would like to know if anybody has a local solution, or any idea of what's going on. As I understand it, it is the compilers job to add the desired padding to the data to have it aligned, but it doesn't look like it's able to do so? I would assume the compiler ideally don't want any packed attribute, as we remove it's freedom to alter the space between each structure field. I would love to have more input on this specific problem :)
Thanks
EDIT: Copying each struct field one by one also works, it is only the operation above that causes trouble.
