audio_thread_create failed

dengbq
Posts: 38
Joined: Thu Mar 31, 2022 8:45 am

audio_thread_create failed

Postby dengbq » Wed Jun 08, 2022 1:21 am

IDF V4.4
ADF 2.4
单独写一个程序播放音频,可以正常播放,放到另一个大工程中后,audio_pipeline_run时出错,
I (29) boot: ESP-IDF v4.4-dirty 2nd stage bootloader
I (29) boot: compile time 08:58:58
I (29) boot: chip revision: 3
I (32) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (39) boot.esp32: SPI Speed : 40MHz
I (44) boot.esp32: SPI Mode : DIO
I (49) boot.esp32: SPI Flash Size : 8MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00011000 00006000
I (77) boot: 1 phy_init RF data 01 01 00017000 00001000
I (84) boot: 2 factory factory app 00 00 00020000 00200000
I (92) boot: 3 config Unknown data 01 82 00220000 00010000
I (99) boot: End of partition table
I (103) boot_comm: chip revision: 3, min. application chip revision: 0
I (111) esp_image: segment 0: paddr=00020020 vaddr=3f400020 size=3a4e8h (238824) map
I (206) esp_image: segment 1: paddr=0005a510 vaddr=3ffbdb60 size=05844h ( 22596) load
I (215) esp_image: segment 2: paddr=0005fd5c vaddr=40080000 size=002bch ( 700) load
I (215) esp_image: segment 3: paddr=00060020 vaddr=400d0020 size=1161c8h (1139144) map
I (634) esp_image: segment 4: paddr=001761f0 vaddr=400802bc size=1e808h (124936) load
I (686) esp_image: segment 5: paddr=00194a00 vaddr=50000000 size=00010h ( 16) load
I (701) boot: Loaded app from partition at offset 0x20000
I (701) boot: Disabling RNG early entropy source...
I (713) psram: This chip is ESP32-D0WD
I (715) spiram: Found 64MBit SPI RAM device
I (715) spiram: SPI RAM mode: flash 40m sram 40m
I (718) spiram: PSRAM initialized, cache is in low/high (2-core) mode.
I (726) cpu_start: Pro cpu up.
I (729) cpu_start: Starting app cpu, entry point is 0x400816b4
0x400816b4: call_start_cpu1 at D:/Espressif/frameworks/esp-idf-v4.4/components/esp_system/port/cpu_start.c:156

I (0) cpu_start: App cpu up.
I (1623) spiram: SPI SRAM memory test OK
I (1633) cpu_start: Pro cpu start user code
I (1633) cpu_start: cpu freq: 240000000
I (1633) cpu_start: Application information:
I (1636) cpu_start: Project name: qinlandemo
I (1641) cpu_start: App version: 1
I (1646) cpu_start: Compile time: Jun 8 2022 08:58:49
I (1652) cpu_start: ELF file SHA256: 940be0bb733eddab...
I (1658) cpu_start: ESP-IDF: v4.4-dirty
I (1664) heap_init: Initializing. RAM available for dynamic allocation:
I (1671) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (1677) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (1683) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (1689) heap_init: At 3FFC5B50 len 0001A4B0 (105 KiB): DRAM
I (1696) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (1702) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (1708) heap_init: At 4009EAC4 len 0000153C (5 KiB): IRAM
I (1715) spiram: Adding pool of 4075K of external SPI memory to heap allocator
I (1724) spi_flash: detected chip: generic
I (1727) spi_flash: flash io: dio
I (1733) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (1747) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
I (1756) ESP32: [ 1 ] Start ESP32 main function.
I (1899) ESP32: MAC:0xc, 0xac, 0x7e, 0xc4, 0x97, 0x46
I (1900) ESP32: WIFI_EVENT_STA_START
。。。。
I (1925) ESP32: wifi_init_sta finished.
E (2040) ESP32: Failed to connect ,reason:203,retry to connect to the AP.
I (2041) ESP32: connect to the AP fail
E (4095) ESP32: Failed to connect ,reason:205,retry to connect to the AP.
I (4095) ESP32: connect to the AP fail
W (4249) wifi:<ba-add>idx:0 (ifx:0, 7c:da:c3:13:dc:25), tid:0, ssn:0, winSize:64
I (4789) ESP32: got ip:192.168.1.13
。。。。
I (4794) ESP32: [ 1 ] Start audio codec chip
W (4862) I2C_BUS: i2c_bus_create:57: I2C bus has been already created, [port:0]
es7243_adc_set_voice_volume 70
I (4884) 。。。。。

I (22185) ESP32: [2.0] Create audio pipeline for playback
I (22185) ESP32: [2.1] Create http stream to read data
I (22225) ESP32: [2.2] Create i2s stream to write data to codec chip
I (22230) ESP32: [2.3] Create opus decoder to decode mp3 file
I (22231) ESP32: [2.4] Register all elements to audio pipeline
I (22235) ESP32: [2.5] Link it together http_stream-->mp3_decoder-->i2s_stream-->[codec_chip]
I (22247) ESP32: [ 4 ] Set up event listener
I (22249) ESP32: [4.1] Listening event from all elements of pipeline
I (22256) ESP32: [ 5 ] Start audio_pipeline
E (22262) AUDIO_THREAD: Error creating task opus_dec
E (22267) AUDIO_ELEMENT: [opus_dec] audio_thread_create failed

I (22276) ESP32: [1.0] _voip_ropen
W (22277) AUDIO_ELEMENT: [opus_dec] Element has not create when AUDIO_ELEMENT_RESUME
E (22286) AUDIO_PIPELINE: audio_pipeline_resume failed
W (24291) AUDIO_ELEMENT: [voip_read-0x3f8148f0] Element task destroy timeout[2000]
W (24291) AUDIO_ELEMENT: [opus_dec] Element has not create when AUDIO_ELEMENT_TERMINATE
I (24317) ESP32: esp_event_post start audio
I (24357) ESP32: _voip_rread data:1024
I (24358) ESP32: [1.0] _voip_rclose


跟踪代码
esp_err_t audio_thread_create(audio_thread_t *p_handle, const char *name, void(*main_func)(void *arg), void *arg,
uint32_t stack, int prio, bool stack_in_ext, int core_id)
{
//ESP_LOGE(TAG, "audio_thread_create in");
StackType_t *task_stack = NULL;
if (stack_in_ext && audio_mem_spiram_stack_is_enabled()) {
/*
* Note: 1. ESP32-ECO3 chip support stack on external memory only.
* 2. Make sure selected the `CONFIG_SPIRAM_BOOT_INIT` and `CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY` by `make menuconfig`
* 3. Please apply the $ADF_PATH/idf_patches/idf_v3.3_freertos.patch
*
*/
ESP_LOGI(TAG, "The %s task allocate stack on external memory", name);
/* task_stack freed by freertos*/
task_stack = (StackType_t *) audio_calloc(1, stack);
ESP_LOGE(TAG, "audio_thread_create:%p, size:%d", task_stack, stack);
AUDIO_MEM_CHECK(TAG, task_stack, goto audio_thread_create_error );
TaskParameters_t xRegParameters = {
.pvTaskCode = main_func,
.pcName = name,
.usStackDepth = stack,
.pvParameters = arg,
.uxPriority = prio | portPRIVILEGE_BIT,
.puxStackBuffer = task_stack,
.xRegions = {{
.pvBaseAddress = 0x00,
.ulLengthInBytes = 0x00,
.ulParameters = 0x00,
}
}
};
if (xTaskCreateRestrictedPinnedToCore(&xRegParameters, (xTaskHandle)p_handle, core_id) != pdPASS) {
ESP_LOGE(TAG, "Error creating RestrictedPinnedToCore %s", name);
goto audio_thread_create_error;
}
} else {
if (xTaskCreatePinnedToCore(main_func, name, stack, arg, prio, (xTaskHandle)p_handle, core_id) != pdPASS) {
ESP_LOGE(TAG, "Error creating task %s", name);
goto audio_thread_create_error;
}
}
return ESP_OK;

audio_thread_create_error:
if (task_stack) {
audio_free(task_stack);
}
return ESP_FAIL;
}

xTaskCreatePinnedToCore跟踪不进去,是什么原因,有什么解决办法?

dengbq
Posts: 38
Joined: Thu Mar 31, 2022 8:45 am

Re: audio_thread_create failed

Postby dengbq » Wed Jun 08, 2022 2:11 am

BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
const uint32_t usStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pvCreatedTask,
const BaseType_t xCoreID)
{
TCB_t * pxNewTCB;
BaseType_t xReturn;

/* If the stack grows down then allocate the stack then the TCB so the stack
* does not grow into the TCB. Likewise if the stack grows up then allocate
* the TCB then the stack. */
#if ( portSTACK_GROWTH > 0 )
{
/* Allocate space for the TCB. Where the memory comes from depends on
* the implementation of the port malloc function and whether or not static
* allocation is being used. */
pxNewTCB = ( TCB_t * ) pvPortMallocTcbMem( sizeof( TCB_t ) );

if( pxNewTCB != NULL )
{
/* Allocate space for the stack used by the task being created.
* The base of the stack memory stored in the TCB so the task can
* be deleted later if required. */
pxNewTCB->pxStack = ( StackType_t * ) pvPortMallocStackMem( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */

if( pxNewTCB->pxStack == NULL )
{
/* Could not allocate the stack. Delete the allocated TCB. */
vPortFree( pxNewTCB );
pxNewTCB = NULL;
}
}
}
#else /* portSTACK_GROWTH */
{
StackType_t * pxStack;

/* Allocate space for the stack used by the task being created. */
pxStack = pvPortMallocStackMem( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation is the stack. */

if( pxStack != NULL )
{
/* Allocate space for the TCB. */
pxNewTCB = ( TCB_t * ) pvPortMallocTcbMem( sizeof( TCB_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of TCB_t is always a pointer to the task's stack. */

if( pxNewTCB != NULL )
{
/* Store the stack location in the TCB. */
pxNewTCB->pxStack = pxStack;
}
else
{
/* The stack cannot be used as the TCB was not created. Free
* it again. */
vPortFree( pxStack );
}
}
else
{
pxNewTCB = NULL;
}
}
#endif /* portSTACK_GROWTH */

printf("xTaskCreatePinnedToCore,pvPortMallocTcbMem newTCB,size:%d,return:%p", sizeof( TCB_t ), pxNewTCB);


继续跟进去,是在pvPortMallocTcbMem( sizeof( TCB_t ) )这里出错,创建任务之前已经成功了多个,内存还剩4M左右,难道还有任务数量的限制?

dengbq
Posts: 38
Joined: Thu Mar 31, 2022 8:45 am

Re: audio_thread_create failed

Postby dengbq » Wed Jun 08, 2022 6:20 am

配置 CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
后,问题解决.

ESP_HengYC
Posts: 184
Joined: Fri Dec 15, 2017 2:45 am

Re: audio_thread_create failed

Postby ESP_HengYC » Wed Jun 08, 2022 8:15 am

这个 audio_thread_create failed 问题一般是 内存不足,导致 task 任务无法创建导致的,

如你所述, 打开 psram 的选项,此问题解决.

Who is online

Users browsing this forum: No registered users and 16 guests