Questions about FPUs

I found that performing some single precision floating-point calculations in a task can cause errors that cause the program to enter Dummy_ Handler。Then I found the error occurred in the function prvPortStartFirstTask from call stack.If I replace single precision floating-point numbers in these tasks with double precision floating-point numbers, then the error did not occur.

I have noticed that my MCU is based on a 32-bit architecture and has a single precision floating-point arithmetic unit,so I changed - mfloat abi=softfp to - mfloat abi=soft in the compilation settings to turn off the FPU, then this error disappeared.

In the assembly file, I see that when using FPU, the compiler generates instructions that use floating-point registers for “float” operations, while for “double” numbers, the simulation algorithm uses general-purpose registers, so I think there may be a problem with the operation of floating point registers during task scheduling. I wonder if this problem can only be avoided by using “double” numbers.

The two tasks are:

void led(void* param)
{
	while(1)
	{
		float a = 0.2345;
		float b = 0.2345;
		float c = a + b;
		LED_Toggle(LED0);
		vTaskDelay(500);
	}
}
xTaskCreate( led, "Led", 200, NULL, 3, NULL );

void interrupeTask(void *param)
{
	
	while(1)
	{
		float a = 0.2345;
		float b = 0.2345;
		float c = a + b;
		vTaskDelay(10);
	}
}
xTaskCreate( interrupeTask, "Inter", 200, NULL, 3, NULL );

Are you using a Port that understands that you have a FPU?

For some processors there are several ports depending on which features (like the FPU or the MPU) you are choosing to use, and using a feature not supported by your port can cause problems.

Which FreeRTOS port area you using?

My FreeRTOS kernel is automatically imported by the example project in Microchip Studio. The portable file is Cortex-M3/M4, and the FreeRTOS version is 10.0.0 on Atmel SAM4E16E

The M3 file doesn’t support the FPU, since M3s don’t have it as an option. There should be a separate M4F version that does.

Wow ,this is indeed the reason. I really didn’t expect that the routine supporting CM4 officially provided by ASF did not consider the issue of FPU compatibility.