# Hard Faults in Cortex M3 on unaligned access

**URL:** <https://forums.freertos.org/t/hard-faults-in-cortex-m3-on-unaligned-access/2854>\
**Category:** Kernel\
**Created:** [June 8, 2011, 8:51pm UTC](https://forums.freertos.org/t/hard-faults-in-cortex-m3-on-unaligned-access/2854 "2011-06-08T20:51:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 8, 2011, 8:51pm UTC](https://forums.freertos.org/t/hard-faults-in-cortex-m3-on-unaligned-access/2854/1 "2011-06-08T20:51:44Z")

</div>

**[hsvbailey](https://sourceforge.net/u/hsvbailey/)** wrote on [Wednesday, June 08, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/7dee4ebb/#ebfa):

I am using FreeRTOS V6.1.0 running on a NXP LPC1758 processor (ARM Cortex M3) and compiled using Code Red’s LPCxpresso development suite.&nbsp; This uses a toolchain based on GCC V4.4.1.

# I have been able to integrate FreeRTOS into my application and all works fine except when I enable the UNALIGN\_TRP bit in the System Control Block’s Configuration Control Register.&nbsp; This bit enables unaligned access traps as noted in the NXP LPC1758 tech reference (34.4.3.8 Configuration and Control Register).

Enables unaligned access traps:  
0 = do not trap unaligned halfword and word accesses  
1 = trap unaligned halfword and word accesses.

# If this bit is set to 1, an unaligned access generates a usage fault. Unaligned LDM, STM, LDRD, and STRD instructions always fault irrespective of whether UNALIGN\_TRP is set to 1.

When I enable this bit, I get Hard Fault exceptions at different times in the operation.&nbsp; It appears that they occur within the kernel though the location is not always consistent.

When I disable the bit, I see no anomalous behavior and all seems to works as I expect it.

Is this a known issue for the Cortex M3 port?&nbsp; Any suggestions about how to handle it apart from disabling the bit?

Thanks  
Doug Bailey

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 8, 2011, 9:17pm UTC](https://forums.freertos.org/t/hard-faults-in-cortex-m3-on-unaligned-access/2854/2 "2011-06-08T21:17:13Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Wednesday, June 08, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/7dee4ebb/#8503):

I don’t think I have ever enabled that bit so can’t say if it is normal. The compiler should ensure everything is aligned. The place where the kernel could get it wrong (but doesn’t, at least not in the latest versions) is when the stack is allocated. This should be on an 8 byte boundary. You could check that (check the stack pointer in the task). You could also get a problem if you are packing structures, either explicitly or with a compiler flag. That is something that is often done in protocols such as TCP/IP.
