Freertos task, required large stack for one ESP_LOG printout

Stipa88
Posts: 25
Joined: Mon May 09, 2022 12:26 pm

Freertos task, required large stack for one ESP_LOG printout

Postby Stipa88 » Thu Jan 25, 2024 7:43 am

Hi.

I am creating a task. In the task function, within the for(;;) loop, I periodically print one LOG message via the ESP_LOGI function-definition.
In order for it to work, without crash and ESP reset, a stack of "1650" (stack is defined in words) size is required. 6.44kB is the task necessary? Why so many? Where is the problem?

Code: Select all

void prvADCNewDataTask( void *);
TaskHandle_t xHandleADCNewDataTask = NULL;

void CreateADC_Task()
{
	ESP_LOGI(TAG, "Create_ADC_Task...");

	xTaskCreate( prvADCNewDataTask, "ADCData_Task", 1650, NULL, tskIDLE_PRIORITY + 1, &xHandleADCNewDataTask);

	ESP_LOGI(TAG, "Success Create_ADC_Task");
}

void prvADCNewDataTask(void * argument)
{
	ESP_LOGI(TAG, "ADCNewDataTask Started");
	volatile uint32_t stackHighWaterMark = 0;

	for(;;)
	{
		vTaskDelay(100);
		stackHighWaterMark = uxTaskGetStackHighWaterMark(xHandleADCNewDataTask);
		ESP_LOGI(TAG, "Free: %u words", stackHighWaterMark);		// stackHighWaterMark = 24
	}
}
Pls help. Tnx

Sprite
Espressif staff
Espressif staff
Posts: 10636
Joined: Thu Nov 26, 2015 4:08 am

Re: Freertos task, required large stack for one ESP_LOG printout

Postby Sprite » Thu Jan 25, 2024 9:37 am

The stack size in ESP-IDF is defined in bytes, see the note at the bottom of this chapter.

lotharyx
Posts: 12
Joined: Fri Dec 13, 2019 4:41 am

Re: Freertos task, required large stack for one ESP_LOG printout

Postby lotharyx » Tue Apr 29, 2025 8:55 pm

Bumping this old thread because the Espressif staff response from Sprite is not helpful.

What is the stack requirement for ESP_LOGx macros? I am also encountering stack overflows caused by the ESP_LOGx calls if the stack is under 2048 (maybe less; I have not tried to determine the exact requirement).

This suggests that the library code is trying to use a stack-based buffer for its calls to _vfprintf_r (the only function named in the panic message). Is there any way to configure the size of that buffer so that tasks with logging need less stack space?

Sample panic message:

Code: Select all

Guru Meditation Error: Core  0 panic'ed (Stack protection fault). 

Detected in task "ptx_u2" at 0x4209a040
--- 0x4209a040: _vfprintf_r at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/vfprintf.c:654

Stack pointer: 0x3fcb3160
Stack bounds: 0x3fcb32a0 - 0x3fcb3690


Setting breakpoint at 0x4209a044 and returning...
--- 0x4209a044: _vfprintf_r at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/vfprintf.c:654

Guru Meditation Error: Core  0 panic'ed (Stack protection fault).

Detected in task "ptx_u2" at 0x4209a040
--- 0x4209a040: _vfprintf_r at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdio/vfprintf.c:654

Stack pointer: 0x3fcb3160
Stack bounds: 0x3fcb32a0 - 0x3fcb3690


Setting breakpoint at 0x4209a044 and returning...
These messages repeat at high speed until the monitor is shut down.

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 3 guests