usage fault unaligned in structures MC 6.2.0 code
I have a hard fault on startup of my near clone of a B-G431B-ESC1 pcb.
Generated the code using the latest version of MC (6.2.0). Code runs and waits for a start command from Motor Pilot. It then tries to start with a short burst of high current which is not what I expect, then stops on the hard fault.
I enabled the 3 fault handlers, mem, bus and usage, then try and run the code. It stops immediately on UsageFault_Handler I find an unaligned error reported. looking further via msp reg, pushed stack etc. I find an assembly line
"str.w r5, [r12, #22]"
This looks like it is storing a word variable into a location with 22 bytes offset.
Going to the C code I get
FOCVars[bMotor].Vqd = NULL_qd;
Vqd is defined in a structure FOCVars_t, where it is 22nd byte and the var is a structure of 2 int16_t so 4 bytes long.
I put an int16_y dummy, just before the Vqd var in the typedef to push into a 4 byte alignment, then test, and it does not fault there but goes further on to another usage fault unaligned, I do the same and it stops at another, this is a more complicated structure, but still I find in each case the offset is not divisible by 4.
This is odd, because it was obviously not failing on these before I enabled the fault handlers!
Is this normal behavior? Or is it leading to the original hardfault due to mis aligned variables in memory?
All assistance greatly appreciated.
Cheers.
Pete L.
