在保留静态相关功能的前提下,解决FreeRTOS裁剪Error: L6218E: Undefined symbol vApplicationGetTimerTaskMemory 等报错的一种思路
·
废话少说,直接上流程:
我使用的芯片为STM32F407,KEIL开发平台,freertos官网下载后手动移植,没使用cubemx,这些步骤会影响裁剪后的freertos的功能和文件的内容。
先找到vApplicationGetTimerTaskMemory vApplicationGetIdleTaskMemory 这两个函数在裁剪过的freertos里的相关说明(以vApplicationGetTimerTaskMemory为例
):

注释的大意是:这个函数用于为FreeRTOS提供一个静态分配的内存块来保存定时器任务TCB。此功能在以下情况时需要使用。好像说了个寂寞,没啥用。去FREERTOS的官网:Customization - FreeRTOS™找到了相关段落:
这段话的意思大概是:
如果配置支持静态分配若设置为1,则应用程序编写者还必须提供两个回调函数:应用程序获取空闲任务内存()为 RTOS 空闲任务提供内存,并(如果配置定时器设定为1)应用程序获取计时任务内存()为 RTOS 守护进程/计时服务任务提供内存。示例如下。
把对应的示例代码复制下来。
把这段代码复制到timer.c文件的静态创建任务紧挨着下面。这样只要configSUPPORT_STATIC_ALLOCATION == 1,启用静态功能,这段代码就会编译生效。

在博主之前的的工程条件下,2个报错消失了,测试用例也顺利运行。但不知道有没有其他隐患,因为博主的用例很简单,只是一个用静态任务创建函数写的3优先级跑马灯。仅供参考。
代码如下:
/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an
implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
used by the Idle task. */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize )
{
/* If the buffers to be provided to the Idle task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
state will be stored. */
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
/* Pass out the array that will be used as the Idle task's stack. */
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
/*-----------------------------------------------------------*/
/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
application must provide an implementation of vApplicationGetTimerTaskMemory()
to provide the memory that is used by the Timer service task. */
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize )
{
/* If the buffers to be provided to the Timer task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xTimerTaskTCB;
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
/* Pass out a pointer to the StaticTask_t structure in which the Timer
task's state will be stored. */
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
/* Pass out the array that will be used as the Timer task's stack. */
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
更多推荐
所有评论(0)