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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

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

740 次查看
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.

标签 (1)
0 项奖励
回复
1 回复

695 次查看
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 项奖励
回复