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 );