# HardFault\_Handler - 2 UART channels

**URL:** <https://forums.freertos.org/t/hardfault-handler-2-uart-channels/12261>\
**Category:** Kernel\
**Tags:** debug\
**Created:** [April 11, 2021, 2:54pm UTC](https://forums.freertos.org/t/hardfault-handler-2-uart-channels/12261 "2021-04-11T14:54:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![m-z](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@m-z](https://forums.freertos.org/u/m-z)\
**Post date:** [April 11, 2021, 2:54pm UTC](https://forums.freertos.org/t/hardfault-handler-2-uart-channels/12261/1 "2021-04-11T14:54:49Z")

</div>

Hey,  
I’m new with STM32 and with FREERTOS.

I have 2 tasks (threads):  
thread 1: toggle the blue led.  
thread 2: is receiving NMEA sentences with UART2 and transmit the UART2 output throw the UART3 channel.

I have configured the FREERTOS according to your instructions (with the blink01/02 example).  
but when the threads start to run I get “HardFault\_Handler” error…

I tried to search online for solutions and I see you keep saying to follow those links:

First, debugging a hard fault:  
[http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html](http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html?_ga=2.45768932.1781522665.1618145309-574783919.1617883977)

Third, making use of configASSERT() to find configuration or user  
errors: [http://www.freertos.org/a00110.html#configASSERT](http://www.freertos.org/a00110.html#configASSERT)

but those links don’t explain how to configure clearly and where …

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [April 11, 2021, 5:12pm UTC](https://forums.freertos.org/t/hardfault-handler-2-uart-channels/12261/2 "2021-04-11T17:12:16Z")

</div>

Besides defining [configASSERT](https://www.freertos.org/a00110.html?_ga=2.213540052.1971135108.1609110559-800452554.1575115350#configASSERT) you should also enable [stack overflow checking](https://www.freertos.org/Stacks-and-stack-overflow-checking.html) for development/debugging.  
Using assertions can help to catch a number of HardFaults with the possibility to trace back and identify the problem.  
Having `configASSERT` defined (in FreeRTOSConfig.h as documented) makes debugging a lot easier by stopping the debugger if the application hangs. If the hang is caused by an assertion, the application is halted in the forever loop usually the last part of the assertion code (as in example 2) and check the _call stack_ for the cause of the assertion.  
Except fatal application programming bugs the main reasons for application crashes are

1. stack overflows (see above)
2. wrong interrupt priorities for certain ports/MCUs e.g. with Cortex-M CPUs

STM32 (which one ?) comes with Cortex-M CPUs and the choosen interrupt priorities have to match `configMAX_SYSCALL_INTERRUPT_PRIORITY` in your `FreeRTOSConfig.h`  
See [RTOS for ARM Cortex-M](https://www.freertos.org/RTOS-Cortex-M3-M4.html) and mabe also [this](https://forums.freertos.org/t/understanding-priority-levels-of-isr-and-freertos-apis/10453/16) pretty good picture for details.

---

<div class="post-metadata">

**Author:** ![m-z](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@m-z](https://forums.freertos.org/u/m-z)\
**Post date:** [April 12, 2021, 7:06am UTC](https://forums.freertos.org/t/hardfault-handler-2-uart-channels/12261/3 "2021-04-12T07:06:40Z")

</div>

@hs2

thank you for the quick answer !!!

I’m using STM32F767

I’ll go over the links and try to add everything you mentioned.

thanks 🙂
