cancel
Showing results for 
Search instead for 
Did you mean: 

I2S using DMA and HalfCpltCallback and CpltCallback

Adrien Hoffet
Associate
Posted on September 21, 2017 at 17:40

I want to process my buffer in two halves, for this reason I tried the following using semihosting for debug:

void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) {

consume_ptr = Buffer1;

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[0] = 0x%x\n', Buffer1[0]);

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[1] = 0x%x\n', Buffer1[1]);

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[2] = 0x%x\n', Buffer1[2]);

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[3] = 0x%x\n', Buffer1[3]);

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[4] = 0x%x\n', Buffer1[4]);

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[5] = 0x%x\n', Buffer1[5]);

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[6] = 0x%x\n', Buffer1[6]);

printf('HAL_I2S_RxHalfCpltCallback: Buffer1[7] = 0x%x\n', Buffer1[7]);

Ready = 1;

}

void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) {

consume_ptr = &Buffer1[Size / 2];

printf('HAL_I2S_RxCpltCallback: Buffer1[0] = 0x%x\n', Buffer1[0]);

printf('HAL_I2S_RxCpltCallback: Buffer1[1] = 0x%x\n', Buffer1[1]);

printf('HAL_I2S_RxCpltCallback: Buffer1[2] = 0x%x\n', Buffer1[2]);

printf('HAL_I2S_RxCpltCallback: Buffer1[3] = 0x%x\n', Buffer1[3]);

printf('HAL_I2S_RxCpltCallback: Buffer1[4] = 0x%x\n', Buffer1[4]);

printf('HAL_I2S_RxCpltCallback: Buffer1[5] = 0x%x\n', Buffer1[5]);

printf('HAL_I2S_RxCpltCallback: Buffer1[6] = 0x%x\n', Buffer1[6]);

printf('HAL_I2S_RxCpltCallback: Buffer1[7] = 0x%x\n', Buffer1[7]);

Ready = 1;

}

What I get as an output is a correct alternance between

HAL_I2S_RxHalfCpltCallback

 and

HAL_I2S_RxCpltCallback

But the buffer is always changing completely and not only its half first and half second part. 

There is my output with an i2s mems mic:

HAL_I2S_RxCpltCallback: Buffer1[0] = 0xf87c

HAL_I2S_RxCpltCallback: Buffer1[1] = 0x8000

HAL_I2S_RxCpltCallback: Buffer1[2] = 0x0

HAL_I2S_RxCpltCallback: Buffer1[3] = 0x0

HAL_I2S_RxCpltCallback: Buffer1[4] = 0xf87d

HAL_I2S_RxCpltCallback: Buffer1[5] = 0x4000

HAL_I2S_RxCpltCallback: Buffer1[6] = 0x0

HAL_I2S_RxCpltCallback: Buffer1[7] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[0] = 0xf87d

HAL_I2S_RxHalfCpltCallback: Buffer1[1] = 0x8000

HAL_I2S_RxHalfCpltCallback: Buffer1[2] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[3] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[4] = 0xf894

HAL_I2S_RxHalfCpltCallback: Buffer1[5] = 0x4000

HAL_I2S_RxHalfCpltCallback: Buffer1[6] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[7] = 0x0

HAL_I2S_RxCpltCallback: Buffer1[0] = 0xf879

HAL_I2S_RxCpltCallback: Buffer1[1] = 0x4000

HAL_I2S_RxCpltCallback: Buffer1[2] = 0x0

HAL_I2S_RxCpltCallback: Buffer1[3] = 0x0

HAL_I2S_RxCpltCallback: Buffer1[4] = 0xf884

HAL_I2S_RxCpltCallback: Buffer1[5] = 0x4000

HAL_I2S_RxCpltCallback: Buffer1[6] = 0x0

HAL_I2S_RxCpltCallback: Buffer1[7] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[0] = 0xf87f

HAL_I2S_RxHalfCpltCallback: Buffer1[1] = 0x8000

HAL_I2S_RxHalfCpltCallback: Buffer1[2] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[3] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[4] = 0xf881

HAL_I2S_RxHalfCpltCallback: Buffer1[5] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[6] = 0x0

HAL_I2S_RxHalfCpltCallback: Buffer1[7] = 0x0

There is the i2s configuration (from cubeMx file):

I2S3.AudioFreq=I2S_AUDIOFREQ_32K

I2S3.DataFormat=I2S_DATAFORMAT_24B

I2S3.ErrorAudioFreq=-0.26 %

I2S3.FullDuplexMode=I2S_FULLDUPLEXMODE_DISABLE

I2S3.IPParameters=Instance,VirtualMode,FullDuplexMode,RealAudioFreq,ErrorAudioFreq,Mode,DataFormat,AudioFreq

I2S3.Instance=SPI$Index

I2S3.Mode=I2S_MODE_MASTER_RX

I2S3.RealAudioFreq=31.914 KHz

I2S3.VirtualMode=I2S_MODE_MASTER

and the dma (

from cubeMx file

:(

Dma.Request0=SPI3_RX

Dma.RequestsNb=1

Dma.SPI3_RX.0.Direction=DMA_PERIPH_TO_MEMORY

Dma.SPI3_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE

Dma.SPI3_RX.0.Instance=DMA1_Stream0

Dma.SPI3_RX.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD

Dma.SPI3_RX.0.MemInc=DMA_MINC_ENABLE

Dma.SPI3_RX.0.Mode=DMA_CIRCULAR

Dma.SPI3_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD

Dma.SPI3_RX.0.PeriphInc=DMA_PINC_DISABLE

Dma.SPI3_RX.0.Priority=DMA_PRIORITY_LOW

Dma.SPI3_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode

Can you help me understand my mistake?

Thanks a lot

#i2s-dma #stmhal
1 REPLY 1

Sorry, bumping old zombie unanswered questions off my feed

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..