# System halt after running for a long time

**URL:** <https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327>\
**Category:** Kernel\
**Created:** [November 3, 2015, 8:15am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327 "2015-11-03T08:15:13Z")\
**Posts on this page:** 8\
**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 3, 2015, 8:15am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/1 "2015-11-03T08:15:13Z")

</div>

**[joe\_her](https://sourceforge.net/u/joe_her/)** wrote on [Tuesday, November 03, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#7df4):

I got a PC freertos simulation that looks OK, but after running for a few hours, it freezes.  
I set breakpoints in all tasks, and no BP is hit, the only running loop is the prvSimulatedPeripheralTimer (), infinite for(;😉 loop.  
Any ideas that will help debugging this will be appreciated.  
Thanks.  
Johanan

---

<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 3, 2015, 8:46am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/2 "2015-11-03T08:46:59Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 03, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#607b):

Is this using the [FreeRTOS Windows port](http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html), which is often referred to as the Windows simulator, or is it a simulation you have created yourself?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 3, 2015, 8:53am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/3 "2015-11-03T08:53:35Z")

</div>

**[joe\_her](https://sourceforge.net/u/joe_her/)** wrote on [Tuesday, November 03, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#7563):

Using FreeRTOS windows port.  
Thanks

---

<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 3, 2015, 8:57am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/4 "2015-11-03T08:57:03Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 03, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#7563/0938):

Are you using any Windows system calls, such as printf, or WinSocks?  
Those are known to cause issues, although there are workarounds.

Also, we have noticed strange behaviour when calling rand(), so will  
provide our own version if it is necessary.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 3, 2015, 9:51am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/5 "2015-11-03T09:51:21Z")

</div>

**[joe\_her](https://sourceforge.net/u/joe_her/)** wrote on [Tuesday, November 03, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#f1f5):

Using winsoc for UDP. Actually the simulation is used as development for the STM32F4 target. The same code is used (using compiler #ifdef whenever necessary) for the PC simulation and target. All I/O hardware done by functions calls. In the simulation, it sends and receives UDP packets to an Arduino that activates all I/O, while the target uses the same function calls for real I/O.  
If the problem is with the UDP socket, then I don’t mind too much, as this is just a simulation. How can I verify this?  
My current strategy is to comment out functions, until the one that creates the problem will be found. Whoever this takes a very long time…

---

<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 3, 2015, 10:14am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/6 "2015-11-03T10:14:29Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 03, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#f1f5/4c9c):

If you download the FreeRTOS+TCP source code  
([http://www.freertos.org/tcp](http://www.freertos.org/tcp)) you will see how we get around this.

Some of the demos use FreeRTOS+TCP sockets to communicate with WinSock  
sockets. To do that reliably all use of the WinSock API is done inside  
standard Windows threads (as opposed to Windows threads that are under  
the control of the FreeRTOS scheduler). The standard Windows threads  
then use a stream buffer (thread safe circular buffer with no system  
calls) to pass data to and from the FreeRTOS tasks. The key is not to  
have Windows system calls in FreeRTOS tasks themselves.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 3, 2015, 10:26am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/7 "2015-11-03T10:26:30Z")

</div>

**[joe\_her](https://sourceforge.net/u/joe_her/)** wrote on [Tuesday, November 03, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#d85e):

Yep, commenting out the UDP removed the problem, now I’ll do the workaround.  
Thanks agian, many hours saved…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 11, 2015, 9:25am UTC](https://forums.freertos.org/t/system-halt-after-running-for-a-long-time/5327/8 "2015-11-11T09:25:15Z")

</div>

**[joe\_her](https://sourceforge.net/u/joe_her/)** wrote on [Wednesday, November 11, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/ec640f6c/#e0d5):

Just by running that UDP task from windows thread with \_beginthread ( ) , and communicating to FreeRTOS via a buffer fixed all these issues.  
Thanks again.
