freeRTOS stack size configuration

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

freeRTOS stack size configuration

跳至解决方案
4,481 次查看
Relas
Contributor I

I am currently learning FreeRTOS on the LPC51U68 development board (OM40005). I have created 7 tasks for testing and am using the RTOS task list monitor provided by MCUXpresso IDE.

I noticed that the stack sizes displayed in the task list don't match the configurations I set.

Could this be related to memory alignment?

Where can I check the rules for configuration differences?

Below is the code I modified from the freertos_hello example.

 

/*

* Copyright (c) 2015, Freescale Semiconductor, Inc.

* Copyright 2016-2017 NXP

* All rights reserved.

*

* SPDX-License-Identifier: BSD-3-Clause

*/

 

/* FreeRTOS kernel includes. */

#include "FreeRTOS.h"

#include "task.h"

#include "queue.h"

#include "timers.h"

 

/* Freescale includes. */

#include "fsl_device_registers.h"

#include "fsl_debug_console.h"

#include "pin_mux.h"

#include "board.h"

 

#include <stdbool.h>

/*******************************************************************************

* Definitions

******************************************************************************/

 

/* Task priorities. */

#define hello_task_PRIORITY (configMAX_PRIORITIES - 1)

/*******************************************************************************

* Prototypes

******************************************************************************/

static void task1(void *pvParameters);

static void task2(void *pvParameters);

static void task3(void *pvParameters);

static void task4(void *pvParameters);

static void task5(void *pvParameters);

static void task6(void *pvParameters);

static void task7(void *pvParameters);

/*******************************************************************************

* Code

******************************************************************************/

/*!

* @brief Application entry point.

*/

int main(void)

{

/* Init board hardware. */

/* attach 12 MHz clock to FLEXCOMM0 (debug console) */

CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

 

BOARD_InitBootPins();

BOARD_InitBootClocks();

BOARD_InitDebugConsole();

if (xTaskCreate(task1, "task1", configMINIMAL_STACK_SIZE + 50, NULL, hello_task_PRIORITY, NULL) !=

pdPASS)

{

PRINTF("Task creation failed!.\r\n");

while (1)

;

}

if (xTaskCreate(task2, "task2", configMINIMAL_STACK_SIZE + 100, NULL, hello_task_PRIORITY, NULL) !=

pdPASS)

{

PRINTF("Task creation failed!.\r\n");

while (1)

;

}

if (xTaskCreate(task3, "task3", configMINIMAL_STACK_SIZE + 160, NULL, hello_task_PRIORITY, NULL) !=

pdPASS)

{

PRINTF("Task creation failed!.\r\n");

while (1)

;

}

if (xTaskCreate(task4, "task4", configMINIMAL_STACK_SIZE + 161, NULL, hello_task_PRIORITY, NULL) !=

pdPASS)

{

PRINTF("Task creation failed!.\r\n");

while (1)

;

}

if (xTaskCreate(task5, "task5", configMINIMAL_STACK_SIZE + 170, NULL, hello_task_PRIORITY, NULL) !=

pdPASS)

{

PRINTF("Task creation failed!.\r\n");

while (1)

;

}

if (xTaskCreate(task6, "task6", configMINIMAL_STACK_SIZE + 200, NULL, hello_task_PRIORITY, NULL) !=

pdPASS)

{

PRINTF("Task creation failed!.\r\n");

while (1)

;

}

if (xTaskCreate(task7, "task7", configMINIMAL_STACK_SIZE + 300, NULL, hello_task_PRIORITY, NULL) !=

pdPASS)

{

PRINTF("Task creation failed!.\r\n");

while (1)

;

}

vTaskStartScheduler();

for (;;)

;

}

 

/*!

* @brief Task responsible for printing of "Hello world." message.

*/

static void task1(void *pvParameters)

{

for (;;)

{

PRINTF("Hello world.\r\n");

vTaskSuspend(NULL);

}

}

 

static void task2(void *pvParameters)

{

for (;;)

{

PRINTF("H\r\n");

vTaskSuspend(NULL);

}

}

 

static void task3(void *pvParameters)

{

for (;;)

{

PRINTF("H\r\n");

vTaskSuspend(NULL);

}

}

 

static void task4(void *pvParameters)

{

for (;;)

{

PRINTF("H\r\n");

vTaskSuspend(NULL);

}

}

 

static void task5(void *pvParameters)

{

for (;;)

{

PRINTF("H\r\n");

vTaskSuspend(NULL);

}

}

 

static void task6(void *pvParameters)

{

for (;;)

{

PRINTF("H\r\n");

vTaskSuspend(NULL);

}

}

 

static void task7(void *pvParameters)

{

for (;;)

{

PRINTF("H\r\n");

vTaskSuspend(NULL);

}

}

 

标记 (1)
0 项奖励
回复
1 解答
4,446 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Relas 

In FreeRTOS, the stack size specified in xTaskCreate() is measured in words (not bytes). For the LPC51U68, which uses a 32-bit word size, each word is 4 bytes.
For instance, if you specify configMINIMAL_STACK_SIZE + 50, this translates to (configMINIMAL_STACK_SIZE + 50) * 4 bytes of stack space.

The alignment adjustments by FreeRTOS or the compiler can cause discrepancies between the requested stack size and the actual allocated size.

BR

Hang

在原帖中查看解决方案

1 回复
4,447 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Relas 

In FreeRTOS, the stack size specified in xTaskCreate() is measured in words (not bytes). For the LPC51U68, which uses a 32-bit word size, each word is 4 bytes.
For instance, if you specify configMINIMAL_STACK_SIZE + 50, this translates to (configMINIMAL_STACK_SIZE + 50) * 4 bytes of stack space.

The alignment adjustments by FreeRTOS or the compiler can cause discrepancies between the requested stack size and the actual allocated size.

BR

Hang