Skip to main content
Associate
November 25, 2025
Solved

i2s_write write data in the buffer

  • November 25, 2025
  • 2 replies
  • 122 views

stack:

Zephyr on stm32n6 (nucleo_n657x0_q)

When sending a buffer over sai via i2s_write data is written into the buffer.

I expected the TX buffer to be treated as read-only and remain unchanged by the driver.

It's only ever the first 2 numbers.

Why is that?

 

 

Example code:
int16_t tx_block_test[96] = {0};
woutervanbastelaere_0-1764066242270.png

 

In attachment a minimal version of a project that displays this issue.

Best answer by wouter-van-bastelaere

(declaring the buffer as const did raise warnings.)

 

I found what the issue is.

I2s_write expect's it's buffer to be from the memory slab that was assigned in I2s's config.

And at the end of i2s_write the memory block is freed to the memory slab.

 

Memory slabs store data about the linked list of all their buffers in the first 4 bytes of empty buffers.

Meaning that when i2s_write finishes the memory slab mistakenly attempts to put it back in it's linked list of buffers. Which writes data into the first 4 bytes.

 

2 replies

Technical Moderator
November 25, 2025

Hello @wouter-van-bastelaere 

Try using a buffer declared as const with i2s_write to check if the compiler issues any warnings or errors.

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question.Saket_Om"
wouter-van-bastelaereAuthorBest answer
Associate
November 25, 2025

(declaring the buffer as const did raise warnings.)

 

I found what the issue is.

I2s_write expect's it's buffer to be from the memory slab that was assigned in I2s's config.

And at the end of i2s_write the memory block is freed to the memory slab.

 

Memory slabs store data about the linked list of all their buffers in the first 4 bytes of empty buffers.

Meaning that when i2s_write finishes the memory slab mistakenly attempts to put it back in it's linked list of buffers. Which writes data into the first 4 bytes.