Skip to main content
Explorer II
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.

    This topic has been closed for replies.
    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.

    Explorer II
    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.