Neharika
Neharika

Reputation: 21

Getting a Hard Fault when trying to list all tasks using vTaskList()

I am trying to list the state of all the tasks that are currently running using vTaskList().Whenever I call the function I get a HardFault and I have no idea where it faults. I tried increasing the Heap size and stack size. This causes the vTaskList() to work once but for the second time it throws a hard fault again. Following is how I am using vTaskList() in osThreadList()

osStatus osThreadList (uint8_t *buffer)
{
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) )
vTaskList((char *)buffer);
#endif
return osOK;
}

Following is how i use osThreadList() to print all the tasks on my serial terminal.

uint8_t TskBuf[1024];
bool IOParser::TSK(bool print_help)
{
if(print_help)
{
uart_printf("\nTSK: Display list of tasks.\r\n");
}
else
{
uart_printf("\r\nName          State  Priority  Stack   Num\r\n" );
uart_printf("---------------------------------------------\r\n");

/* The list of tasks and their status */
osThreadList(TskBuf);
uart_printf( (char *)TskBuf);
uart_printf("---------------------------------------------\r\n");
uart_printf("B : Blocked, R : Ready, D : Deleted, S : Suspended");
}
return true;
}

When I comment out any one of the tasks I am able to get it working. I am guessing it is something related to memory but I havent been able to find a solution.

Upvotes: 1

Views: 717

Answers (1)

SamR
SamR

Reputation: 399

vTaskList is dependent on sprintf. So, your guess about memory and heap is right. But you have to use malloc and pass that block instead of what you do. Use pvPortmalloc and after you finish, free it up using vportfree. Also, it is worthwhile noting that vTaskList is a blocking function. I do not have a working code example to show this as at now, but this should work. Hard Faults are often (almost all the time) happens due to uninitialised pointer. Above approach will eliminate that.

Upvotes: 1

Related Questions