Sorry my English is little.
I am running FreeRTOS on an MSP432 Launchpad, which features a Cortex M4F MCU. For a specific purpose, I need to save all task stacks and TCBs to secondary storage and then load them back. Below is the entire process:
Upon completion of the saving process, the program will enter a forever loop, allowing me to halt the IDE. After rebuilding and restarting the program, the operating system will load the task stacks and TCBs from storage and add them to the ready list.
Initially, I added three tasks to the OS, and everything worked fine. However, upon adding another task that includes a float array, the program encountered a hard fault upon restarting.
All four tasks are from MiBench. The three tasks that worked fine are bitcnt, basicmath, and strsch. Strsch performs string search with a predefined string, thus involving a character array.
The fourth task is FFT, which performs Fourier transform with specific input, building 6 float arrays with these inputs. However, the FFT task enters a hard fault.
I also ran a test task that utilized an integer array for simple math operations, and it worked without any issues. However, when I changed the integer array to a float array, a hard fault occurred.
void testArrrayTask()
{
//change array type to int, this task will work fine.
float a[100];
float b[100];
float c[100];
int i;
int progress = 0;
while(1)
{
for(i=0;i<100;i++)
{
a[i] = rand()%1000;
b[i] = rand()%1000;
c[i] = a[i]*b[i] + a[i]/b[i] + (a[i]-b[i]);
}
progress+=1;
}
}
So I think the issue lies with the float type array. Although basicmath involves float operations, it doesn’t store the results in an array.
For the purpose of simply saving and loading task stacks and TCBs, I opted not to use the built-in heap4 for memory management; instead, I used a large uint8_t array. Task stacks and TCB memory are allocated from this array during task creation.
static unsigned char stackMEM[STACK_SIZE];
static unsigned char tcbMEM[sizeof( tskTCB ) * TASK_NUM];
void * getStackAddr(int taskID)
{
// add switch case to allocate memory for task
switch(taskID)
{
case IDLE:
return &idleMEM[0];
case BASICMATH:
return &stackMEM[0];
case BITCNTS:
return &stackMEM[BASICMATHMEM];
case STRSRCH:
return &stackMEM[BASICMATHMEM+BITCNTSMEM];
case FFT:
return &stackMEM[BASICMATHMEM+BITCNTSMEM+STRSRCHMEM];
}
return &stackMEM[0];
}
void * getTCBAddr(int taskID)
{
return &tcbMEM[sizeof( tskTCB ) * taskID];
}
I am considering reverting to using heap4 in hopes of resolving this issue, but it may entail considerable work to implement the saving and loading process. Apart from this approach, are there any other solutions to address the float array issue?
Thank you for your attention.