Skip to content

Conversation

@mariopaja
Copy link
Contributor

@mariopaja mariopaja commented Aug 20, 2025

This change fixes two issues with the SAI TX Stream (Issue: #94561)

  1. Drain command does not release the last memory buffer
  2. TX Stream status does not change to READY after STOPPING

Application: samples/drivers/i2s/output

DRAIN:
Add the following code at the end of the application:

ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_DRAIN);
if (ret < 0) {
printf("Could not trigger I2S tx\n");
return ret;
}

Before:

*** Booting Zephyr OS build v4.2.0-1295-g93620efc8d23 ***
[00:00:00.001,000] <wrn> i2s_stm32_sai: Free mem slabs: 1
[00:00:00.002,000] <wrn> i2s_stm32_sai: Free mem slabs: 2
[00:00:00.004,000] <wrn> i2s_stm32_sai: Free mem slabs: 3
[00:00:00.005,000] <wrn> i2s_stm32_sai: Free mem slabs: 4
[00:00:00.007,000] <wrn> i2s_stm32_sai: Free mem slabs: 5
[00:00:00.008,000] <wrn> i2s_stm32_sai: Free mem slabs: 6
[00:00:00.010,000] <wrn> i2s_stm32_sai: Free mem slabs: 7
[00:00:00.011,000] <wrn> i2s_stm32_sai: Free mem slabs: 8
[00:00:00.013,000] <wrn> i2s_stm32_sai: Free mem slabs: 9
[00:00:00.014,000] <wrn> i2s_stm32_sai: Free mem slabs: 10
[00:00:00.015,000] <wrn> i2s_stm32_sai: Free mem slabs: 11
[00:00:00.017,000] <wrn> i2s_stm32_sai: Free mem slabs: 12
[00:00:00.018,000] <wrn> i2s_stm32_sai: Free mem slabs: 13
[00:00:00.020,000] <wrn> i2s_stm32_sai: Free mem slabs: 14
[00:00:00.021,000] <wrn> i2s_stm32_sai: Free mem slabs: 15
[00:00:00.023,000] <wrn> i2s_stm32_sai: Free mem slabs: 16
[00:00:00.024,000] <wrn> i2s_stm32_sai: Free mem slabs: 17
[00:00:00.025,000] <wrn> i2s_stm32_sai: Free mem slabs: 18
[00:00:00.027,000] <wrn> i2s_stm32_sai: Free mem slabs: 19
[00:00:00.028,000] <wrn> i2s_stm32_sai: Free mem slabs: 19

After:

*** Booting Zephyr OS build v4.2.0-1296-g4009810cb5c7 ***
[00:00:00.001,000] <wrn> i2s_stm32_sai: Free mem slabs: 1
[00:00:00.002,000] <wrn> i2s_stm32_sai: Free mem slabs: 2
[00:00:00.004,000] <wrn> i2s_stm32_sai: Free mem slabs: 3
[00:00:00.005,000] <wrn> i2s_stm32_sai: Free mem slabs: 4
[00:00:00.007,000] <wrn> i2s_stm32_sai: Free mem slabs: 5
[00:00:00.008,000] <wrn> i2s_stm32_sai: Free mem slabs: 6
[00:00:00.010,000] <wrn> i2s_stm32_sai: Free mem slabs: 7
[00:00:00.011,000] <wrn> i2s_stm32_sai: Free mem slabs: 8
[00:00:00.013,000] <wrn> i2s_stm32_sai: Free mem slabs: 9
[00:00:00.014,000] <wrn> i2s_stm32_sai: Free mem slabs: 10
[00:00:00.015,000] <wrn> i2s_stm32_sai: Free mem slabs: 11
[00:00:00.017,000] <wrn> i2s_stm32_sai: Free mem slabs: 12
[00:00:00.018,000] <wrn> i2s_stm32_sai: Free mem slabs: 13
[00:00:00.020,000] <wrn> i2s_stm32_sai: Free mem slabs: 14
[00:00:00.021,000] <wrn> i2s_stm32_sai: Free mem slabs: 15
[00:00:00.023,000] <wrn> i2s_stm32_sai: Free mem slabs: 16
[00:00:00.024,000] <wrn> i2s_stm32_sai: Free mem slabs: 17
[00:00:00.025,000] <wrn> i2s_stm32_sai: Free mem slabs: 18
[00:00:00.027,000] <wrn> i2s_stm32_sai: Free mem slabs: 19
[00:00:00.028,000] <wrn> i2s_stm32_sai: Free mem slabs: 20

STOP/START:
Add the following code at the end of the application:

ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_STOP);
if (ret < 0) {
printf("Could not trigger I2S tx\n");
return ret;
}

k_msleep(5000);

ret = i2s_trigger(dev_i2s, I2S_DIR_TX, I2S_TRIGGER_START);
if (ret < 0) {
printf("Could not trigger I2S tx\n");
return ret;
}

Before:

*** Booting Zephyr OS build v4.2.0-1295-g93620efc8d23 ***
[00:00:00.001,000] <wrn> i2s_stm32_sai: Free mem slabs: 1
[00:00:00.002,000] <wrn> i2s_stm32_sai: Free mem slabs: 2
[00:00:00.004,000] <wrn> i2s_stm32_sai: Free mem slabs: 3
[00:00:00.005,000] <wrn> i2s_stm32_sai: Free mem slabs: 4
[00:00:00.007,000] <wrn> i2s_stm32_sai: Free mem slabs: 5
[00:00:00.008,000] <wrn> i2s_stm32_sai: Free mem slabs: 6
[00:00:00.010,000] <wrn> i2s_stm32_sai: Free mem slabs: 7
[00:00:00.011,000] <wrn> i2s_stm32_sai: Free mem slabs: 8
[00:00:00.013,000] <wrn> i2s_stm32_sai: Free mem slabs: 9
[00:00:00.014,000] <wrn> i2s_stm32_sai: Free mem slabs: 10
[00:00:00.015,000] <wrn> i2s_stm32_sai: Free mem slabs: 11
[00:00:00.017,000] <wrn> i2s_stm32_sai: Free mem slabs: 12
[00:00:00.018,000] <wrn> i2s_stm32_sai: Free mem slabs: 13
[00:00:00.020,000] <wrn> i2s_stm32_sai: Free mem slabs: 14
[00:00:00.021,000] <wrn> i2s_stm32_sai: Free mem slabs: 15
[00:00:00.023,000] <wrn> i2s_stm32_sai: TX Stopped ...
[00:00:00.023,000] <wrn> i2s_stm32_sai: Free mem slabs: 15
Could not trigger I2S tx
[00:00:05.021,000] <err> i2s_stm32_sai: START trigger: invalid state 3

After:

*** Booting Zephyr OS build v4.2.0-1296-g4009810cb5c7 ***
[00:00:00.001,000] <wrn> i2s_stm32_sai: Free mem slabs: 1
[00:00:00.002,000] <wrn> i2s_stm32_sai: Free mem slabs: 2
[00:00:00.004,000] <wrn> i2s_stm32_sai: Free mem slabs: 3
[00:00:00.005,000] <wrn> i2s_stm32_sai: Free mem slabs: 4
[00:00:00.007,000] <wrn> i2s_stm32_sai: Free mem slabs: 5
[00:00:00.008,000] <wrn> i2s_stm32_sai: Free mem slabs: 6
[00:00:00.010,000] <wrn> i2s_stm32_sai: Free mem slabs: 7
[00:00:00.011,000] <wrn> i2s_stm32_sai: Free mem slabs: 8
[00:00:00.013,000] <wrn> i2s_stm32_sai: Free mem slabs: 9
[00:00:00.014,000] <wrn> i2s_stm32_sai: Free mem slabs: 10
[00:00:00.015,000] <wrn> i2s_stm32_sai: Free mem slabs: 11
[00:00:00.017,000] <wrn> i2s_stm32_sai: Free mem slabs: 12
[00:00:00.018,000] <wrn> i2s_stm32_sai: Free mem slabs: 13
[00:00:00.020,000] <wrn> i2s_stm32_sai: Free mem slabs: 14
[00:00:00.021,000] <wrn> i2s_stm32_sai: Free mem slabs: 15
[00:00:00.023,000] <wrn> i2s_stm32_sai: TX Stopped ...
[00:00:00.023,000] <wrn> i2s_stm32_sai: Free mem slabs: 16
[00:00:05.023,000] <wrn> i2s_stm32_sai: Free mem slabs: 17
[00:00:05.024,000] <wrn> i2s_stm32_sai: Free mem slabs: 18
[00:00:05.026,000] <wrn> i2s_stm32_sai: Free mem slabs: 19
[00:00:05.027,000] <wrn> i2s_stm32_sai: Free mem slabs: 20

@mariopaja mariopaja mentioned this pull request Aug 20, 2025
21 tasks
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you replace "PR" with "change" in the commit log. In the end, what will remains is a commit in the Git history rather that a Github P-R. Note also that imperative mode is usually preferred. Suggestion:

This PR fixes two issues with the SAI TX Stream.
Fix two issues with the SAI TX Stream:

Last, it's usually better to have 1 fix per commit (unless there are related), but that's not a strong opinion since your 2 fixes are rather small.
Otherwise LGTM.

Fix two issues with the SAI TX Stream.

1. Drain command does not release the last memory buffer
2. TX Stream status does not change to READY after STOPPING

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
@mariopaja mariopaja force-pushed the stm32_sai_tx_drain_stop_fix branch from 4009810 to aa83f09 Compare August 21, 2025 09:15
@mariopaja
Copy link
Contributor Author

hi @etienne-lms,

I changed the commit log. Is it better now?

it's usually better to have 1 fix per commit

I know but the changes are small and are related to each other. I could not fix one and let the other one

@sonarqubecloud
Copy link

@kartben kartben merged commit c70aaee into zephyrproject-rtos:main Aug 22, 2025
28 checks passed
mariopaja added a commit to mariopaja/zephyr that referenced this pull request Aug 30, 2025
This change fixes a wrong buffer release on tx callback which
was not correctly fixed by
zephyrproject-rtos#94696.

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
mariopaja added a commit to mariopaja/zephyr that referenced this pull request Aug 30, 2025
This change fixes a wrong buffer release on tx callback which
was not correctly fixed by
zephyrproject-rtos#94696.

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
mariopaja added a commit to mariopaja/zephyr that referenced this pull request Aug 30, 2025
This change fixes a wrong buffer release on tx callback which
was not correctly fixed by
zephyrproject-rtos#94696.

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
kartben pushed a commit that referenced this pull request Sep 2, 2025
This change fixes a wrong buffer release on tx callback which
was not correctly fixed by
#94696.

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
ExaltZephyr pushed a commit to ExaltZephyr/zephyr that referenced this pull request Sep 16, 2025
This change fixes a wrong buffer release on tx callback which
was not correctly fixed by
zephyrproject-rtos#94696.

Signed-off-by: Mario Paja <mariopaja@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants