FreeRTOS报错信息如下:
Error:…\src\freertos\portable\RVDS\ARM_CM4F\port.c,233
根据断言信息,报错位置为port.c文件第233行,查看源代码:
static void prvTaskExitError( void )
{
/* A function that implements a task must not exit or attempt to return to
* its caller as there is nothing to return to. If a task wants to exit it
* should instead call vTaskDelete( NULL ).
*
* Artificially force an assert() to be triggered if configASSERT() is
* defined, then stop here so application writers can catch the error. */
configASSERT( uxCriticalNesting == ~0UL );
portDISABLE_INTERRUPTS();
for( ; ; )
{
}
}
发现是执行了prvTaskExitError函数,再根据官方文件注释,FreeRTOS中规定,任务不能退出,如果要退出只能调用vTaskDelete( NULL ),否则就会异常报错,根据这个提示,检查各个任务,是不是有异常退出。
如果有多个任务,可以对在prvTaskExitError函数中增加调试代码,打印任务名称,如下:
static void prvTaskExitError( void )
{
/* A function that implements a task must not exit or attempt to return to
* its caller as there is nothing to return to. If a task wants to exit it
* should instead call vTaskDelete( NULL ).
*
* Artificially force an assert() to be triggered if configASSERT() is
* defined, then stop here so application writers can catch the error. */
TaskHandle_t xTask=xTaskGetCurrentTaskHandle();
const char *pcTaskName =pcTaskGetName(xTask);
printf("Error:Task %s exited unexpectedly!\r\n",pcTaskName);
configASSERT( uxCriticalNesting == ~0UL );
portDISABLE_INTERRUPTS();
for( ; ; )
{
}
}
再次运行,即可打印出任务名称,从而具体分析某个任务:
Error:Task ftp_server exited unexpectedly!
Error:…\src\freertos\portable\RVDS\ARM_CM4F\port.c,237
可以看出,导致异常退出的任务是ftp_server,分析ftp_server任务,发现是有return返回的地方,导致任务异常退出了。

1万+

被折叠的 条评论
为什么被折叠?



