RT1021 - Why does unaligned 64-bit access now cause a hard-fault?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RT1021 - Why does unaligned 64-bit access now cause a hard-fault?

730 Views
rshipman
Contributor V

Hi,

I have some test code that regularly checks unaligned access works for 16, 32 and 64 bit words on the RT1021. My understanding was that unaligned access for these word sizes should work on the CM7, with something clever done by the compiler to emulate 64-bit access.

This code worked fine until I upgraded to MCUXpresso 11.8.0 (with SDK 2.14.0).

Now 64-bit unaligned access causes a hardfault.
HFSR = 0x40000000 -> FORCED (30)
UFSR = 0x00000100 -> UNALIGNED bit set.

So my question is, why has this stopped working now? Has the gcc compiler that comes with the new MCUXpresso etc changed its behaviour with regard to 64-bit access?

Many thanks.

Labels (1)
0 Kudos
Reply
1 Reply

685 Views
rshipman
Contributor V

The hard-fault occurs when calling LDRD. This instruction seems to work on 4-byte aligned boundaries only.

I think this might be related to optimisation. It fails in the Debug build (i.e. with optimisation off) but passes in the Release build (-O2). Also, directly accessing the pointer (e.g. reading unaligned uint32_t*) hard-faults in both builds, but dereferencing the pointer at the point of passing the contents into a function does not fail. So perhaps the optimiser is not using LDRD in the latter case.

I'm fairly sure the test worked for both the Debug and Release builds at some point. It doesn't now, for the Debug build. So something has changed. However, this was only an experimental/test piece of code, so not critical to our code base, but I thought it might be worth flagging in case there is a bug somewhere.

0 Kudos
Reply