# STM32 HardFaultException After certain period

**URL:** <https://forums.freertos.org/t/stm32-hardfaultexception-after-certain-period/4319>\
**Category:** Kernel\
**Created:** [January 20, 2011, 1:21pm UTC](https://forums.freertos.org/t/stm32-hardfaultexception-after-certain-period/4319 "2011-01-20T13:21:26Z")\
**Posts on this page:** 4\
**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:** [January 20, 2011, 1:21pm UTC](https://forums.freertos.org/t/stm32-hardfaultexception-after-certain-period/4319/1 "2011-01-20T13:21:26Z")

</div>

**[irvind](https://sourceforge.net/u/irvind/)** wrote on [Thursday, January 20, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/be8e5781/#4ec8):

Hi,

Currently I am using STM32 Cortex M3, compiler IAR 4.x & FreeRTOS v6.1.0.

I have a firmware that send some data through GSM module to PC.

Before I start implement FreeRTOS, everything worked properly.

After I implement FreeRTOS to my code, I facing HardFaultException problem after sending certain bytes of string. I try debug and narrow down the posibility so I have only 1 task running.

I found that if I send a long string which mean more bytes in 1 message, then it crash earlier. If I reduce the string size that I am sending per message, then it take longer time to crash.

Could anyone please guide me on this? If I need to clear any buffer etc? But this firmware running without RTOS and it work properly. I also tried to put enter critical before I do and strcpy or memcpy, I thought interrupt might causing this problem but still the same problem. I really run out of idea. So please give me a hand on this.

Thank you so much.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 20, 2011, 6:36pm UTC](https://forums.freertos.org/t/stm32-hardfaultexception-after-certain-period/4319/2 "2011-01-20T18:36:42Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Thursday, January 20, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/be8e5781/#28e1):

To save Richard the trouble. Have you read number three of this faq?  
[www.freertos.org/FAQHelp.html](http://www.freertos.org/FAQHelp.html)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 21, 2011, 2:59am UTC](https://forums.freertos.org/t/stm32-hardfaultexception-after-certain-period/4319/3 "2011-01-21T02:59:00Z")

</div>

**[irvind](https://sourceforge.net/u/irvind/)** wrote on [Friday, January 21, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/be8e5781/#d1ca):

yes. I read the FAQ before and also I bought their e-bbok. But I can’t find my problem related to any of the FAQ.

By the way, I found that it not caused by create string etc. It caused by the stack size I assigned to the task, before I post the previous thread. I set my task stack as 2048. Then today I tried to increase higher stack size to 3072 just in case overflow check failed to trigger. But it go worst, it crashed&nbsp; faster than before. So I reduced my stack size to 1024, and it could run longer than before. But it still enter hardfaultexception at the end. Anyone have any idea that could solve this?

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 21, 2011, 10:47am UTC](https://forums.freertos.org/t/stm32-hardfaultexception-after-certain-period/4319/4 "2011-01-21T10:47:46Z")

</div>

**[irvind](https://sourceforge.net/u/irvind/)** wrote on [Friday, January 21, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/be8e5781/#e29f):

Problem solved.

Just in case anyone having this problem, I wrote down my problem and solution here hope it could help other.

When using FreeRTOS, instead of using malloc, we are using pvPortMalloc(). But I forgot to use vPortFree to free all memory which I am still using free function. So it crash when memory only alloc but not freed.
