# Last Task of freeRTOS reset the stm32l4

**URL:** <https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875>\
**Category:** Kernel\
**Created:** [July 2, 2024, 2:22pm UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875 "2024-07-02T14:22:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qaisar](https://avatars.discourse-cdn.com/v4/letter/q/8797f3/32.png) [@Qaisar](https://forums.freertos.org/u/Qaisar)\
**Post date:** [July 2, 2024, 2:22pm UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/1 "2024-07-02T14:22:22Z")

</div>

hello everyone!

I am working on stm32 with freeRTOS, I created four tasks and they are properly manage but the last task which is “SleepMode” after executing it, the device reset itself why? i know the issue is not in task but once all task execute themselves then the device reset itself which is not good for my appliction, please suggest the solution?

thank you.

---

<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:** [July 2, 2024, 2:30pm UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/2 "2024-07-02T14:30:10Z")

</div>

Can you post the relevant code ?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [July 2, 2024, 2:37pm UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/3 "2024-07-02T14:37:59Z")

</div>

Is that “SleepMode” task putting the processor into a deep sleep? Some of the deepest sleep modes do a reset to wake up, so aren’t really usable in a real time application unless it IS prepared to need a reset.

---

<div class="post-metadata">

**Author:** ![Qaisar](https://avatars.discourse-cdn.com/v4/letter/q/8797f3/32.png) [@Qaisar](https://forums.freertos.org/u/Qaisar)\
**Post date:** [July 2, 2024, 3:07pm UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/4 "2024-07-02T15:07:56Z")

</div>

yes! i am using stop2 mode. but it does not matter because i comnent out those code but still reset.

---

<div class="post-metadata">

**Author:** ![archigup](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/archigup/32/1418_2.png) [@archigup](https://forums.freertos.org/u/archigup)\
**Post date:** [July 3, 2024, 12:25am UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/5 "2024-07-03T00:25:30Z")

</div>

Would you be able to provide sample code that reproduces this issue? That would be helpful in figuring out the cause.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 3, 2024, 5:20am UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/6 "2024-07-03T05:20:08Z")

</div>

> [@Qaisar](#):
>
> the last task which is “SleepMode” after executing it, the device reset itself why?

Have you applied the suggestions provided in this post - [FreeRTOS with stop2 mode using rtc for wakeup](https://forums.freertos.org/t/freertos-with-stop2-mode-using-rtc-for-wakeup/20613/). If yes, please share the complete code as others have asked.

---

<div class="post-metadata">

**Author:** ![Qaisar](https://avatars.discourse-cdn.com/v4/letter/q/8797f3/32.png) [@Qaisar](https://forums.freertos.org/u/Qaisar)\
**Post date:** [July 3, 2024, 6:14am UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/7 "2024-07-03T06:14:26Z")

</div>

```auto
osEventFlagsWait(sleepModeEventHandle,
				SLEEP_CONNECT_AND_SEND_EVENT_FLAG,
				osFlagsWaitAny,
				osWaitForever);

		IterationCount++;
 		power_pre_sleep_processing();

		DeInitEverything(IterationCount<ITERATION_DEBUG_COUNT);
		HAL_SuspendTick();

		HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

		HAL_ResumeTick();

		power_post_sleep_processing();
		InitEverything();
		HAL_WWDG_Refresh(&hwwdg);
		// Notify configuration and adxl tasks to unblock them for the next iteration
		xTaskNotifyGive(configurationAndAdxlHandle);
		taskYIELD();

```

this is the code where it goes to reset. yes, you are right i figure out that it is due to when it goes out from sleep mode. so how can i resolve it?

---

<div class="post-metadata">

**Author:** ![amaracollins](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/amaracollins/32/4748_2.png) [@amaracollins](https://forums.freertos.org/u/amaracollins)\
**Post date:** [July 6, 2024, 9:02am UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/8 "2024-07-06T09:02:04Z")

</div>

Hello,  
I think the SleepMode task exits properly without triggering critical errors or stack overflows. Stack sizes and memory allocations across all tasks to prevent resource exhaustion.

---

<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:** [July 6, 2024, 10:46am UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/9 "2024-07-06T10:46:02Z")

</div>

you are using a watch dog along with sleep mode? Is that supported by the hardware? Have you tried running thd code without an active watch dog?

---

<div class="post-metadata">

**Author:** ![Qaisar](https://avatars.discourse-cdn.com/v4/letter/q/8797f3/32.png) [@Qaisar](https://forums.freertos.org/u/Qaisar)\
**Post date:** [July 6, 2024, 11:02am UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/10 "2024-07-06T11:02:15Z")

</div>

yes it support. i have tried without watch dog.  
thankyou.

---

<div class="post-metadata">

**Author:** ![Qaisar](https://avatars.discourse-cdn.com/v4/letter/q/8797f3/32.png) [@Qaisar](https://forums.freertos.org/u/Qaisar)\
**Post date:** [July 6, 2024, 11:09am UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/11 "2024-07-06T11:09:36Z")

</div>

I posted this query, and I received wonderful responses. I appreciate your help.  
I figured out the reason: if all of the tasks enter to a block state, and there is not other task in process that’s why the device reset itself.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [July 6, 2024, 3:02pm UTC](https://forums.freertos.org/t/last-task-of-freertos-reset-the-stm32l4/20875/12 "2024-07-06T15:02:31Z")

</div>

But the Idle task should not have blocked itself unless you did something wrong in the IdleHook.
