Freertos + STM32F2 - 将堆栈分配给线程后总堆大小错误
Freertos + STM32F2 - Total heap size is wrong after allocating stack to thread
我目前正在使用 stm32f4 开发 freertos。使用以下配置的 cubemx 创建项目后。
RTOS 似乎有大约 25k 字节供我分配堆栈给线程。但是不知何故,当我创建堆栈大小为 1000 的线程时。它只剩下 20888 字节用于 RTOS 的总堆。如果我分配2000。它还剩下16888。它似乎总是消耗 4 倍的堆栈大小分配。对正在发生的事情真的很困惑。
osThreadDef(Task_Embedded, Task_VATEmbedded, osPriorityNormal, 0, 1000);
VATEmbeddedTaskHandle = osThreadCreate(osThread(Task_Embedded), NULL);
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
{
TaskHandle_t handle;
if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
&handle) != pdPASS) {
return NULL;
}
return handle;
}
正在查看CMSIS man
Configuration of Thread count and Stack Space
osThreadDef defines a thread function.
The parameter stacksz specifies thereby the stack requirements of this thread function. CMSIS-RTOS RTX defines two methods for defining the stack requirements:
when stacksz is 0, a fixed-size memory pool is used to for the thread stack. In this case OS_STKSIZE specifies the stack size for the thread function.
when stacksz is not 0, the thread stack is allocated from a user space. The size of this user space is specified with OS_PRIVSTKSIZE.
(强调我的。)
OS-PRIVSTKSIZE 告诉
Is the combined stack requirement (in words) of all threads that are defined with with osThreadDef stacksz != 0 (excluding main).
(强调我的。)
FreeRTOSAPI上线,xTaskCreate()函数的usStackDepth参数的描述中明确说明栈是用字定义的,不是字节。 FreeRTOS 在 8 位、16 位 32 位和 64 位处理器上运行,因此字长取决于体系结构 - 在您的情况下为 4,这与您的观察相符。 http://www.freertos.org/a00125.html
我目前正在使用 stm32f4 开发 freertos。使用以下配置的 cubemx 创建项目后。
RTOS 似乎有大约 25k 字节供我分配堆栈给线程。但是不知何故,当我创建堆栈大小为 1000 的线程时。它只剩下 20888 字节用于 RTOS 的总堆。如果我分配2000。它还剩下16888。它似乎总是消耗 4 倍的堆栈大小分配。对正在发生的事情真的很困惑。
osThreadDef(Task_Embedded, Task_VATEmbedded, osPriorityNormal, 0, 1000);
VATEmbeddedTaskHandle = osThreadCreate(osThread(Task_Embedded), NULL);
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
{
TaskHandle_t handle;
if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
&handle) != pdPASS) {
return NULL;
}
return handle;
}
正在查看CMSIS man
Configuration of Thread count and Stack Space
osThreadDef defines a thread function.
The parameter stacksz specifies thereby the stack requirements of this thread function. CMSIS-RTOS RTX defines two methods for defining the stack requirements:
when stacksz is 0, a fixed-size memory pool is used to for the thread stack. In this case OS_STKSIZE specifies the stack size for the thread function. when stacksz is not 0, the thread stack is allocated from a user space. The size of this user space is specified with OS_PRIVSTKSIZE.
(强调我的。)
OS-PRIVSTKSIZE 告诉
Is the combined stack requirement (in words) of all threads that are defined with with osThreadDef stacksz != 0 (excluding main).
(强调我的。)
FreeRTOSAPI上线,xTaskCreate()函数的usStackDepth参数的描述中明确说明栈是用字定义的,不是字节。 FreeRTOS 在 8 位、16 位 32 位和 64 位处理器上运行,因此字长取决于体系结构 - 在您的情况下为 4,这与您的观察相符。 http://www.freertos.org/a00125.html