# Hard Fault when using two tasks and suspending debugger

**URL:** <https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276>\
**Category:** Kernel\
**Created:** [November 20, 2019, 7:52am UTC](https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276 "2019-11-20T07:52:59Z")\
**Posts on this page:** 6\
**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:** [November 20, 2019, 7:52am UTC](https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276/1 "2019-11-20T07:52:59Z")

</div>

**[flewz2010](https://sourceforge.net/u/flewz2010/)** wrote on [Wednesday, November 20, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8332dce306/#da56):

I use an STM32F4 µC, with FreeRTOS. Now when I am using two tasks, and suspend the execution in eclipse to debug the Hard Fault Handler triggers, however this primarily happens when I halt for longer than a second or so. Additionally, this only happens, when I add the second task to the application, with one task everything runs fine. Both tasks are set at tskIDLE\_PRIORITY+1 and suspend and resume themselves after a specified time interval.  
The Hard Fault Handler does not show any usable PC, but gives the usage fault: “Attempt to do exception with bad value in EXEC\_RETURN number”. If you need any more info, I’l be happy to provide.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 20, 2019, 8:44pm UTC](https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276/2 "2019-11-20T20:44:30Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, November 20, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8332dce306/#da56/b375):

> I use an STM32F4 µC, with FreeRTOS. Now when I am using two tasks, and  
> suspend the execution in eclipse

do you mean break in the debugger, so stop the program running in the  
debugger?

> to debug the Hard Fault Handler  
> triggers,

So the hard fault triggers after the program was stopped? If so the  
program cannot have stopped running. Do you have the debugger set to  
stop timers when you are stepping through the code?

however this primarily happens when I halt for longer than a

> second or so. Additionally, this only happens, when I add the second  
> task to the application,

…and the second task is the same as the first task? If not, what are  
the differences?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 21, 2019, 8:14am UTC](https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276/3 "2019-11-21T08:14:18Z")

</div>

**[flewz2010](https://sourceforge.net/u/flewz2010/)** wrote on [Thursday, November 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8332dce306/#ed13):

> do you mean break in the debugger, so stop the program running in the  
> debugger?  
> Yep, when I try to stop the program to step through the code, I can make one step in the best case scenario until the hard fault triggers  
> Do you have the debugger set to stop timers when you are stepping through the code?  
> How do I set this? I only have this assert defined per the instructions for the m4

```auto
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}

```

> …and the second task is the same as the first task? If not, what are  
> the differences?  
> The thing about the two tasks was a wrong assumption on my part. I eliminated one task and I still have the problem, I even removed the TaskDelayUntil and Semaphore I used previously to synchronize my tasks, so now it just runs continuously.

```auto
const TickType_t xFrequencySend = 10;
//	xLastWakeTimeSend = xTaskGetTickCount();
	for(;;)
	{
// xLastWakeTimeSend = xTaskGetTickCount();
		if(xQueueReceive(sendCmdQ, &cmd, 0) == pdTRUE)
		{
// if( xSemaphoreTake( xSendSemaphore, (TickType_t) 500) )
// {
				switch(cmd)
				{
				case CONNECT:
					connect();
					break;
				case START:
					start();
					break;
				}
// xSemaphoreGive(xSendSemaphore);
// }
		}
// else
// {
// vTaskDelayUntil( &xLastWakeTimeSend, xFrequencySend );
// }
	}

```

This is my task, although a bit simplified. the connect() and start() functions look a bit like this:

```auto
uint8_t data[2] ={CONNECT, 0x80};
	HAL_UART_Transmit(&huart6, (uint8_t *) pData, size, 5000);
	while(!Connected)
	{
		Connected = connectCheck();
	}

```

the start() function is analogous in sending out data over UART and checking received packages for a response.  
The UART interrupt is set to lowest priority (15,0), although I also had it at (10,0)

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 21, 2019, 7:35pm UTC](https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276/4 "2019-11-21T19:35:14Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, November 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8332dce306/#ed13/662c):

> ```
> do you mean break in the debugger, so stop the program running in the
> debugger?
> Yep, when I try to stop the program to step through the code, I can
> make one step in the best case scenario until the hard fault triggers
> 
> ```

This doesn’t sound like a FreeRTOS issues then, not directly anyway, but  
some interaction between the development tools, the debug interface and  
the target. Most likely scenarios would be something the debugger is  
doing is causing a fault (like it is trying to read values from  
misaligned addresses, or invalid addresses), or timers are continuing to  
run while stepping through code generating interrupts that the debugger  
is preventing from running or are continuously re-entering.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 27, 2019, 7:47am UTC](https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276/5 "2019-11-27T07:47:33Z")

</div>

**[flewz2010](https://sourceforge.net/u/flewz2010/)** wrote on [Wednesday, November 27, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8332dce306/#7e4c):

Just to close this topic. It was indeed a problem with my IDE and not with FreeRTOS. Opening a new workspace solved my problem.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 27, 2019, 7:10pm UTC](https://forums.freertos.org/t/hard-fault-when-using-two-tasks-and-suspending-debugger/8276/6 "2019-11-27T19:10:19Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, November 27, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8332dce306/#7e4c/e739):

Thanks for taking the time to report back.
