# I am using FreeRTOS with STM32G0 series. I created two tasks in the beginning it goes to two task but after couple of times it always stuck in one task

**URL:** <https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888>\
**Category:** Kernel\
**Created:** [March 3, 2021, 3:24am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888 "2021-03-03T03:24:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anunalge](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anunalge](https://forums.freertos.org/u/anunalge)\
**Post date:** [March 3, 2021, 3:24am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/1 "2021-03-03T03:24:17Z")

</div>

FreeRTOS task has been stuck with one of them not going to other task. I used STCube to generate the code and created two tasks, i assume idle task is created by RTOS so i have not done. In the beginning it run both the tasks but after 3 or 4 times it always stuck in one task. I am new to using FreeRTOS . Please guide me.

---

<div class="post-metadata">

**Author:** ![jefftenney](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/jefftenney/32/1314_2.png) [@jefftenney](https://forums.freertos.org/u/jefftenney)\
**Post date:** [March 3, 2021, 4:30am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/2 "2021-03-03T04:30:07Z")

</div>

Here are a few “basics” that have helped many new users. Be sure you have [configASSERT()](https://www.freertos.org/a00110.html#configASSERT) defined and that you enable [stack overflow checking](https://www.freertos.org/Stacks-and-stack-overflow-checking.html) and use the [malloc-failed hook](https://www.freertos.org/a00110.html#configUSE_MALLOC_FAILED_HOOK).

And with Cortex M, the FAQ is especially helpful:

> **[FreeRTOS - Open Source RTOS Kernel for small embedded systems](https://freertos.org/FAQHelp.html)**
>
> FreeRTOS is a portable, open source, mini Real Time kernel. A free RTOS for small embedded systems

---

<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:** [March 3, 2021, 5:35am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/3 "2021-03-03T05:35:41Z")

</div>

If you are generating your project using STM32CubeIDE, another thing to keep in mind to change the HAL Tick from SysTick to some other timer (say TIM6): `System Core --> SYS --> Timebase Source`.

Thanks.

---

<div class="post-metadata">

**Author:** ![anunalge](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anunalge](https://forums.freertos.org/u/anunalge)\
**Post date:** [March 3, 2021, 6:43am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/4 "2021-03-03T06:43:16Z")

</div>

/\*\*\*\*\*\* Cortex-M0+ Processor Exceptions Numbers \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_/  
NonMaskableInt\_IRQn = -14, /_!\< 2 Non Maskable Interrupt _/  
HardFault\_IRQn = -13, /_!\< 3 Cortex-M Hard Fault Interrupt _/  
SVC\_IRQn = -5, /_!\< 11 Cortex-M SV Call Interrupt _/  
PendSV\_IRQn = -2, /_!\< 14 Cortex-M Pend SV Interrupt _/  
SysTick\_IRQn = -1, /_!\< 15 Cortex-M System Tick Interrupt \*/

These are generated by STMCube. /\* System interrupt init\*/  
/\* PendSV\_IRQn interrupt configuration \*/  
HAL\_NVIC\_SetPriority(PendSV\_IRQn, 3, 0); this function is called in HAL\_MspInit. Is this is an issue? Memory i am using dynamic allocation so the issue may not be related to stack.

---

<div class="post-metadata">

**Author:** ![anunalge](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anunalge](https://forums.freertos.org/u/anunalge)\
**Post date:** [March 3, 2021, 6:44am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/5 "2021-03-03T06:44:06Z")

</div>

I am using TIM6 as time base for HAL

---

<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:** [March 3, 2021, 8:42am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/6 "2021-03-03T08:42:40Z")

</div>

I afraid a few more details are needed to help.  
Could you post the code of the tasks and where exactly the task is stuck ?  
And also the code where you create the tasks ?  
Did you already take care about Jeff’s hints ? I also strongly recommend doing so during development.

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 8, 2022, 4:20pm UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/7 "2022-11-08T16:20:26Z")

</div>

.Error: L6218E: Undefined symbol vApplicationStackOverflowHook(tskTaskControlBlock\*, char\*) (referred from tasks.o).

the above error pops up if i enable the stack overflow checking and similar when i enable the malloc-failed hook

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 8, 2022, 4:20pm UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/8 "2022-11-08T16:20:59Z")

</div>

is there a way to resolve that

---

<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 8, 2022, 4:23pm UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/9 "2022-11-08T16:23:39Z")

</div>

Functions prefixed with “Application” must be provided by the application writer - in this case it is the function the kernel should call when it detects a stack overflow. If googling vApplicationStackOverlowHook doesn’t immediately provide the answer to your question, then try restricting your google search to the FreeRTOS website by adding “site:FreeRTOS.org” to the end of the search query.

---

<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:** [November 8, 2022, 4:58pm UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/10 "2022-11-08T16:58:25Z")

</div>

Documentation - [FreeRTOS - stacks and stack overflow checking](https://www.freertos.org/Stacks-and-stack-overflow-checking.html)

Example - [FreeRTOS/app\_main.c at main · FreeRTOS/FreeRTOS · GitHub](https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS/Demo/CORTEX_MPU_M7_NUCLEO_H743ZI2_GCC_IAR_Keil/Demo/app_main.c#L49)

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 14, 2022, 8:22am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/11 "2022-11-14T08:22:25Z")

</div>

I have added whatever is told and i still get the SVC 0 hard fault , any other workaround perhaps ?

While this is discussed is freeRTOS not compatible with a project which has cpp files ?  
when i try to add RTOS to my project (which has cpp files ) there is a lot of errors which comes up , i’m using keil micro vision IDE .  
I have even tried changing the Misc controls of only cpp files to “–cpp11” but still no luck .  
I had to change some of the freeRTOS files which were giving errors to work with “–cpp11” to make it compile with out errors , which is why i think i am even getting this above SVC hard fault .  
I’m using the STM32F767 cortexM7 board.

---

<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:** [November 14, 2022, 9:12am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/12 "2022-11-14T09:12:16Z")

</div>

> [@Varsh\_S](#):
>
> While this is discussed is freeRTOS not compatible with a project which has cpp files ?

Are you compiling files using a C compiler?

> [@Varsh\_S](#):
>
> I have added whatever is told and i still get the SVC 0 hard fault , any other workaround perhaps ?

Where do you get this hard fault? Can you share callstack when the fault happens?

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 14, 2022, 9:38am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/13 "2022-11-14T09:38:31Z")

</div>

when i go into the prvStartFirstTask(); in port.c and reach SVC 0 - it doesn’t go further than this  
 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/8/8a813723b7509e860554eb92c13743e258074baa.png)

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 14, 2022, 9:39am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/14 "2022-11-14T09:39:15Z")

</div>

![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/7/71bd4fc4d00135aad3d4c78065e30c450be14e3a.png)

Arm Compiler - default compiler version 5

---

<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:** [November 14, 2022, 9:48am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/15 "2022-11-14T09:48:57Z")

</div>

Is [vPortSVCHandler](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/portable/RVDS/ARM_CM4F/port.c#L245) installed as the SVC handler?

> [@Varsh\_S](#):
>
> Arm Compiler - default compiler version 5

You need to ensure that C++ files are compiled using C++ compiler and C files are compiled using C compiler. For GNU, these translate to g++ and gcc respectively.

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 14, 2022, 9:52am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/16 "2022-11-14T09:52:09Z")

</div>

i have defined the below in freeRTOSconfig.h already - if that is what installing vPostSVCHandler as SVC handler means

/\* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS  
standard names. \*/  
#define vPortSVCHandler SVC\_Handler  
#define xPortPendSVHandler PendSV\_Handler

/\* IMPORTANT: FreeRTOS is using the SysTick as internal time base, thus make sure the system and peripherials are  
using a different time base (TIM based for example).  
\*/  
#define xPortSysTickHandler SysTick\_Handler

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 14, 2022, 9:56am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/17 "2022-11-14T09:56:09Z")

</div>

I tried adding --cpp11 in the Misc controls section of the “C/C++” only for the C++ files and removed it for all the C files . is there any other way to ensure that the files are compiled using the right compiler ?

---

<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:** [November 14, 2022, 9:59am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/18 "2022-11-14T09:59:14Z")

</div>

> [@Varsh\_S](#):
>
> i have defined the below in freeRTOSconfig.h already - if that is what installing vPostSVCHandler as SVC handler means

Take a look at the vector table which must be in the startup code - is it contains entries SVC\_Handler, then you are likely right.

---

<div class="post-metadata">

**Author:** ![Varsh\_S](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@Varsh\_S](https://forums.freertos.org/u/Varsh_S)\
**Post date:** [November 14, 2022, 10:21am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/19 "2022-11-14T10:21:57Z")

</div>

![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/6/6c06167dbed018585bd1504fbac426b2a74637fe.png)  
in startup file

---

<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:** [November 14, 2022, 11:24am UTC](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888/20 "2022-11-14T11:24:31Z")

</div>

That seems correct. When you try to step through the code, does the control take you to this function?

[Next page](https://forums.freertos.org/t/i-am-using-freertos-with-stm32g0-series-i-created-two-tasks-in-the-beginning-it-goes-to-two-task-but-after-couple-of-times-it-always-stuck-in-one-task/11888.md?page=2)
