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

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.

Here are a few “basics” that have helped many new users. Be sure you have configASSERT() defined and that you enable stack overflow checking and use the malloc-failed hook .

And with Cortex M, the FAQ is especially helpful:

1 Like

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.

1 Like

/****** 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.

I am using TIM6 as time base for HAL

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.

.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

is there a way to resolve that

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.

Documentation - FreeRTOS - stacks and stack overflow checking

Example - FreeRTOS/app_main.c at main · FreeRTOS/FreeRTOS · GitHub

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.

Are you compiling files using a C compiler?

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

when i go into the prvStartFirstTask(); in port.c and reach SVC 0 - it doesn’t go further than this
image

image

Arm Compiler - default compiler version 5

Is vPortSVCHandler installed as the SVC handler?

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.

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

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 ?

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.


in startup file

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