I have encountered a very strange problem recently。I plan to change the data that needs to be read frequently from double type to float type because I am worried about the errors caused by the interruption of data reading and I have already done so on some variables。Then I found this problem:
If I run a task like this:
void float_test(void)
{
const TickType_t delay_time = pdMS_TO_TICKS(10);
TickType_t lastweak = xTaskGetTickCount();
float a = 0.0;
float b = 0.1;
while(1)
{
if(a < 10000)
{
a += 12 * b;
}
vTaskDelayUntil(&lastweak, delay_time);
}
}
xTaskCreate((void*)float_test, "tsp", 100, NULL, 5, NULL);
then my program will be crashed,but if I change the task like this:
void float_test(void)
{
const TickType_t delay_time = pdMS_TO_TICKS(10);
TickType_t lastweak = xTaskGetTickCount();
double a = 0.0;
double b = 0.1;
while(1)
{
if(a < 10000)
{
a += 12 * b;
}
vTaskDelayUntil(&lastweak, delay_time);
}
}
xTaskCreate((void*)float_test, "tsp", 100, NULL, 5, NULL);
or like this:
void float_test(void)
{
const TickType_t delay_time = pdMS_TO_TICKS(10);
TickType_t lastweak = xTaskGetTickCount();
float a = 0.0;
float b = 0.1;
while(1)
{
if(a < 10000)
{
12 * b;
}
vTaskDelayUntil(&lastweak, delay_time);
}
}
xTaskCreate((void*)float_test, "tsp", 100, NULL, 5, NULL);
the program can run normally.
In addition, I tested whether similar codes in the bare metal state return errors, and the result is that all the above conditions can operate normally.
My chip is ATSAM4E16E and the IDE is ATMEL Studio(Microchip Studio)7, and the compilation settings is
-pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
I try to change the FTP settings to soft or hard but it didn’t work。However, when I use the routines in ASF, these tasks can run。
I want to know what settings I am aware of that cause this problem, so that I can avoid this error in the future when there is no routine