Skip to content

Commit fe11acc

Browse files
VitekSTdkalowsk
authored andcommitted
samples: i2s_codec: Fix i2s API misuse
Replace i2s_write invocation with i2s_buf_write invocation for test sine wave playback. When CONFIG_USE_DMIC=n, this sample attempts to play back a test sine wave encoded in sine.h. As the i2s_write treats the given buffer as a memory slab, it overwrites parts of it, resulting in data corruption and improper playback. i2s_buf_write accepts a buffer existing outside the playback queue (heap). Manually tested on mimxrt595_evk/mimxrt595s/cm33 where it was first observed. Signed-off-by: Vit Stanicek <[email protected]>
1 parent b93dec9 commit fe11acc

File tree

1 file changed

+6
-1
lines changed
  • samples/drivers/i2s/i2s_codec/src

1 file changed

+6
-1
lines changed

samples/drivers/i2s/i2s_codec/src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,21 @@ int main(void)
171171

172172
for (i = 0; i < 2; i++) {
173173
#if CONFIG_USE_DMIC
174+
/* If using DMIC, use a buffer (memory slab) from dmic_read */
174175
ret = dmic_read(dmic_dev, 0, &mem_block, &block_size, TIMEOUT);
175176
if (ret < 0) {
176177
printk("read failed: %d", ret);
177178
break;
178179
}
180+
181+
ret = i2s_write(i2s_dev_codec, mem_block, block_size);
179182
#else
180183
/* If not using DMIC, play a sine wave 440Hz */
181184
mem_block = (void *)&__16kHz16bit_stereo_sine_pcm;
185+
block_size = __16kHz16bit_stereo_sine_pcm_len;
186+
187+
ret = i2s_buf_write(i2s_dev_codec, mem_block, block_size);
182188
#endif
183-
ret = i2s_write(i2s_dev_codec, mem_block, block_size);
184189
if (ret < 0) {
185190
printk("Failed to write data: %d\n", ret);
186191
break;

0 commit comments

Comments
 (0)