# Cortex M4 hard fault finding root cause on LPC4078

**URL:** <https://forums.freertos.org/t/cortex-m4-hard-fault-finding-root-cause-on-lpc4078/11944>\
**Category:** Kernel\
**Tags:** debug\
**Created:** [March 10, 2021, 9:50am UTC](https://forums.freertos.org/t/cortex-m4-hard-fault-finding-root-cause-on-lpc4078/11944 "2021-03-10T09:50:21Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [March 17, 2021, 4:48pm UTC](https://forums.freertos.org/t/cortex-m4-hard-fault-finding-root-cause-on-lpc4078/11944/14 "2021-03-17T16:48:18Z")

</div>

> [@aggarg](#):
>
> a way to debug can be to create the task statically using `xTaskCreateStatic` so that you control the stack buffer. You can then put a data breakpoint at the last byte of the stack buffer to catch stack overflow.

Unfortunately, that technique doesn’t work reliably for the same reason that the built-in stack overflow cxheck doesn’t work reliably. Assume the stack is close to its end, and the caller task calls a function that does something like that:

```
SomeFn()
{
    unsigned char aBuf[20];
    ....
}

```

That function while executing may not touch all of the 20 bytes it set aside.

Also, you don’t need a static task; you can program the DWT on the fly with any dynamically determined trigger address at runtime.

---

_[View the full topic](https://forums.freertos.org/t/cortex-m4-hard-fault-finding-root-cause-on-lpc4078/11944)._
