Skip to content

stm32: i2s_stm32_sai driver does not release the last mem_block #94561

@puliceworx

Description

@puliceworx

Describe the bug

While implementing SAI, DRAIN, STOP, unable to refill men_slab completely causing a NOMEM error.
Diagnosis showed that the last men_block is not freed in HAL_SAI_TxCpltCallback. This occurs on last_block check and no more data check.

Only the previous block is free'd at the end of the callback. On last_block or no more blocks in the queue, free the streams mem_block.

Target: STM32U5xx
Board: nucleo_u575zi_q
Diagnose: Modify sample\drivers\i2s\output to print free blocks after waiting a time after triggering the drain.

Regression

  • This is a regression.

Steps to reproduce

Modify the i2s\output sample to loop on free blocks to equal NUM_BLOCKS. This will loop forever.

while(k_mem_slab_num_free_get(&tx_0_mem_slab) != NUM_BLOCKS) {
		
	printf("Waiting for all blocks to be free. %d of %d \n",
		k_mem_slab_num_free_get(&tx_0_mem_slab), NUM_BLOCKS);

	k_msleep(500);
}

west build -b nucleo_u575zi_q samples\drivers\i2s\output

Relevant log output

*** Booting Zephyr OS build v4.2.0 ***
All I2S blocks written
Waiting for all blocks to be free. 16 of 20 
Waiting for all blocks to be free. 19 of 20 
Waiting for all blocks to be free. 19 of 20 
Waiting for all blocks to be free. 19 of 20 
Waiting for all blocks to be free. 19 of 20 
Waiting for all blocks to be free. 19 of 20 
Waiting for all blocks to be free. 19 of 20 
Waiting for all blocks to be free. 19 of 20

Impact

Functional Limitation – Some features not working as expected, but system usable.

Environment

OS: Windows 11
Toolchain: Zephyr SDK 0.17.2
Version: v4.2.0

Additional Context

No response

Metadata

Metadata

Assignees

Labels

area: I2SbugThe issue is a bug, or the PR is fixing a bugplatform: STM32ST Micro STM32priority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions