Getting a hardfault in task.h

-stm32f411RE
-heap1
I’m getting a hardfault that only happens when I strangely add a header file. I’m sure it has nothing to do with the header file because I reduced that file to nothing but a simple foo function that just returns a value. For some reason, When calling that function in that header(from anywhere within main, even before taskscheduler starts), will give me the hardfault that is shown in the pic attached. When not calling that function, hardfault never happens.

the hardfault occurs in task.h on line 2781. you can see the callstack in the picture. What might be the problem. I am unsure of where to even start looking.

The uxPriority value indicates a memory corruption. Given your description of the function, it does not seem related but would you still share the definition of the function.

How many tasks do you have in the system? Can you disable them one by one and try to isolate the offending task?

Also, make sure to define configASSERT and stack overflow check as mentioned here: FreeRTOS - Open Source RTOS Kernel for small embedded systems

Thanks.

So I have disabled all tasks. I call the function before vTaskStartScheduler(); . This is the hardfault shown in picture in file queue.c. Hardfault happens when it leaves that function.

I have `configASSERT’ defined in FreeRtosConfig.h and also
#define configCHECK_FOR_STACK_OVERFLOW 1
with vApplicationStackOverflowHook implemented
This is how my systick handler looks like for handling interrupt

extern "C"
void xPortSysTickHandler(void);
 
extern "C"
	void SysTick_Handler(void)
{
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
	
	//osSystickHandler();
	if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
	{ 
		xPortSysTickHandler(); 
	} 
} 

The function being called is in a header arbitrarily named
FastSinee.h

#pragma once 
float sintest(float x);

FastSinee.cpp
#include "FastSinee.h" 
float sintest(float x)
{return x;
}

Hey Hadi!

Are you trying to use the SysTimer besides FreeRTOS together?

As @Manutronics mentioned, you probably are using the SysTick for both FreeRTOS tick and HAL tick. Change the HAL tick to some other timer. If you are using STM32CubeIDE or CubeMX, you can do that from System Core --> Sys --> Timebase Source.

In addition, just to be sure, can you change float to int to see if the issue is because of FPU being not enabled correctly.

Thanks.

It does seem to have something to do with the fpu. when changing things to floats hardfaults start happening. I am using visualgdb to help setup Freertos and for whichever reason it has defaulted to using the M3 M4 with software FP. I changed it to the one seen in the pic and now it works. Doing this fixed the issue and changed the port from the incorrect
FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
to the correct port of
FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c

Thanks for the help in this.

as for systick, I am unsure about the proper systick config. I am not use cubeMX so am not able to configure it there. I changed it to the following and it sems to work just as the previous I had did.

void SysTick_Handler(void)
{ 
	osSystickHandler();
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler(); 
}

Would this be the better way to do it with stm HAL?

Glad that it worked for you.

For the tick handler - Some of the ST HAL requires the HAL tick to be running at higher priority than what FreeRTOS permits and therefore, they recommend to use a separate timer other than SysTick for HAL timebase. In fact, you get a warning if you use CubeMX or STM32Cube IDE and do not change the HAL timebase.

Thanks.