2016-11-30 12:12 AM
Hello,
In our application for audio codec IC, we have used I2S in full duplex mode with DMA.I have copied code for I2S . Can anyone suggest me what could be wrong with this ?static void I2SInit(){ // Enable PLLI2S __HAL_RCC_PLLI2S_ENABLE(); // DMA controller clock enable __HAL_RCC_DMA1_CLK_ENABLE(); // DMA1_Stream0_IRQn interrupt configuration HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); // DMA1_Stream7_IRQn interrupt configuration HAL_NVIC_SetPriority(DMA1_Stream7_IRQn, 0, 0); HAL_NVIC_EnableIRQ(DMA1_Stream7_IRQn); hi2s3.Instance = SPI3; hi2s3.Init.Mode = I2S_MODE_MASTER_TX; hi2s3.Init.Standard = I2S_STANDARD_PHILIPS; hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B; hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE; hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_8K; hi2s3.Init.CPOL = I2S_CPOL_LOW; hi2s3.Init.ClockSource = I2S_CLOCK_PLL; hi2s3.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_ENABLE; if (HAL_I2S_Init(&hi2s3) != HAL_OK) while(1);}void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s){ GPIO_InitTypeDef gpio; if(hi2s->Instance == SPI3) { // Peripheral clock enable __HAL_RCC_SPI3_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); /**I2S3 GPIO Configuration PA15 ------> I2S3_WS PC10 ------> I2S3_CK PC11 ------> I2S3_ext_SD PC12 ------> I2S3_SD */ gpio.Pin = GPIO_PIN_15; gpio.Mode = GPIO_MODE_AF_PP; gpio.Pull = GPIO_NOPULL; gpio.Speed = GPIO_SPEED_FREQ_LOW; gpio.Alternate = GPIO_AF6_SPI3; HAL_GPIO_Init(GPIOA, &gpio); gpio.Pin = GPIO_PIN_10|GPIO_PIN_12; gpio.Mode = GPIO_MODE_AF_PP; gpio.Pull = GPIO_NOPULL; gpio.Speed = GPIO_SPEED_FREQ_LOW; gpio.Alternate = GPIO_AF6_SPI3; HAL_GPIO_Init(GPIOC, &gpio); gpio.Pin = GPIO_PIN_11; gpio.Mode = GPIO_MODE_AF_PP; gpio.Pull = GPIO_NOPULL; gpio.Speed = GPIO_SPEED_FREQ_LOW; gpio.Alternate = GPIO_AF5_I2S3ext; HAL_GPIO_Init(GPIOC, &gpio); // Peripheral DMA init hdma_spi3_tx.Instance = DMA1_Stream7; hdma_spi3_tx.Init.Channel = DMA_CHANNEL_0; hdma_spi3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_spi3_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi3_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_spi3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_spi3_tx.Init.Mode = DMA_CIRCULAR; hdma_spi3_tx.Init.Priority = DMA_PRIORITY_LOW; hdma_spi3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; if (HAL_DMA_Init(&hdma_spi3_tx) != HAL_OK) while(1); __HAL_LINKDMA(hi2s,hdmatx,hdma_spi3_tx); hdma_i2s3_ext_rx.Instance = DMA1_Stream0; hdma_i2s3_ext_rx.Init.Channel = DMA_CHANNEL_3; hdma_i2s3_ext_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_i2s3_ext_rx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_i2s3_ext_rx.Init.MemInc = DMA_MINC_ENABLE; hdma_i2s3_ext_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_i2s3_ext_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_i2s3_ext_rx.Init.Mode = DMA_CIRCULAR; hdma_i2s3_ext_rx.Init.Priority = DMA_PRIORITY_LOW; hdma_i2s3_ext_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; if (HAL_DMA_Init(&hdma_i2s3_ext_rx) != HAL_OK) while(1); __HAL_LINKDMA(hi2s,hdmarx,hdma_i2s3_ext_rx); } }void DMA1_Stream0_IRQHandler(void){ HAL_DMA_IRQHandler(&hdma_i2s3_ext_rx);}void DMA1_Stream7_IRQHandler(void){ HAL_DMA_IRQHandler(&hdma_spi3_tx);}void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s){ // Task}void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s){ // Task}void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s){ // Task}void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s){ // Task}//Based on User actionstatic void EnableRxDma(){ HAL_I2S_Receive_DMA(&hi2s3, _buffer, (2 * I2S_DMA_BUF_LEN));}static void DisableRxDma(){ HAL_I2S_DMAPause(&hi2s3);}static void EnableTxDma(){ HAL_I2S_Transmit_DMA(&hi2s3, _buffer, (2 * I2S_DMA_BUF_LEN));}static void DisableTxDma(){ HAL_I2S_DMAPause(&hi2s3);} #i2s #-2016-11-30 12:20 AM
In above code, DMA handler is not executed ...:(
2016-11-30 12:55 AM
Hi pinkesh,
Which STM32 device you are using ? Ensure that you have copied from a project of the same STM32 family/device or a compatible one -> check if the used DMA/stream or pin used are correct ( open the datasheet).I propose that you refer to an I2S example inside the STM32Cube library relevent for your device, and compare the code with the generated one from CubeMx : As example: the '' I2S_Audio'' example in at this path: STM32Cube_FW_F4_V1.14.0\Projects\STM324xG_EVAL\Examples\I2S\I2S_Audio-Hannibal-