cancel
Showing results for 
Search instead for 
Did you mean: 

stm32mp1 SAI DMA issue

Sindhu Vadde
Associate III

Hi,

We are using stm32mp157a in our custom board.We are configured SAI for Cortex M in cubemx.But we are unable to get dma interrupt and data through DMA. you can see my code flow below.

In main.

we are calling below functions.

int main()

{

MX_DMA_Init();

MX_SAI2_Init();

 HAL_SAI_Receive_DMA(&hsai_BlockB2,(uint8_t *)AUDIORecvBuf,BUF_SIZE);

while(1)

{

}

}

1.SAI intialization

static void MX_SAI2_Init(void)

{

 /* USER CODE BEGIN SAI2_Init 0 */

 /* USER CODE END SAI2_Init 0 */

 /* USER CODE BEGIN SAI2_Init 1 */

 /* USER CODE END SAI2_Init 1 */

 hsai_BlockA2.Instance = SAI2_Block_A;

 hsai_BlockA2.Init.Protocol = SAI_FREE_PROTOCOL;

 hsai_BlockA2.Init.AudioMode = SAI_MODESLAVE_RX;

 hsai_BlockA2.Init.DataSize = SAI_DATASIZE_16;

 hsai_BlockA2.Init.FirstBit = SAI_FIRSTBIT_MSB;

 hsai_BlockA2.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;

 hsai_BlockA2.Init.Synchro = SAI_ASYNCHRONOUS;

 hsai_BlockA2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;

 hsai_BlockA2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_HF;

 hsai_BlockA2.Init.MckOutput = SAI_MCK_OUTPUT_ENABLE;

 hsai_BlockA2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;

 hsai_BlockA2.Init.MonoStereoMode = SAI_STEREOMODE;

 hsai_BlockA2.Init.CompandingMode = SAI_NOCOMPANDING;

 hsai_BlockA2.Init.TriState = SAI_OUTPUT_NOTRELEASED;

 hsai_BlockA2.Init.PdmInit.Activation = DISABLE;

 hsai_BlockA2.Init.PdmInit.MicPairsNbr = 0;

 hsai_BlockA2.Init.PdmInit.ClockEnable = SAI_PDM_CLOCK1_ENABLE;

 hsai_BlockA2.FrameInit.FrameLength = 64;

 hsai_BlockA2.FrameInit.ActiveFrameLength = 1;

 hsai_BlockA2.FrameInit.FSDefinition = SAI_FS_STARTFRAME;

 hsai_BlockA2.FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH;

 hsai_BlockA2.FrameInit.FSOffset = SAI_FS_FIRSTBIT;

 hsai_BlockA2.SlotInit.FirstBitOffset = 0;

 hsai_BlockA2.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;

 hsai_BlockA2.SlotInit.SlotNumber = 4;

 hsai_BlockA2.SlotInit.SlotActive = 0x0000000F;

 if (HAL_SAI_Init(&hsai_BlockA2) != HAL_OK)

 {

   Error_Handler();

 }

 hsai_BlockB2.Instance = SAI2_Block_B;

 hsai_BlockB2.Init.Protocol = SAI_FREE_PROTOCOL;

 hsai_BlockB2.Init.AudioMode = SAI_MODESLAVE_TX;

 hsai_BlockB2.Init.DataSize = SAI_DATASIZE_16;

 hsai_BlockB2.Init.FirstBit = SAI_FIRSTBIT_MSB;

 hsai_BlockB2.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;

 hsai_BlockB2.Init.Synchro = SAI_SYNCHRONOUS;

 hsai_BlockB2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;

 hsai_BlockB2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_HF;

 hsai_BlockB2.Init.MckOutput = SAI_MCK_OUTPUT_ENABLE;

 hsai_BlockB2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;

 hsai_BlockB2.Init.MonoStereoMode = SAI_STEREOMODE;

 hsai_BlockB2.Init.CompandingMode = SAI_NOCOMPANDING;

 hsai_BlockB2.Init.TriState = SAI_OUTPUT_NOTRELEASED;

 hsai_BlockB2.Init.PdmInit.Activation = DISABLE;

 hsai_BlockB2.Init.PdmInit.MicPairsNbr = 0;

 hsai_BlockB2.Init.PdmInit.ClockEnable = SAI_PDM_CLOCK1_ENABLE;

 hsai_BlockB2.FrameInit.FrameLength = 64;

 hsai_BlockB2.FrameInit.ActiveFrameLength = 1;

 hsai_BlockB2.FrameInit.FSDefinition = SAI_FS_STARTFRAME;

 hsai_BlockB2.FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH;

 hsai_BlockB2.FrameInit.FSOffset = SAI_FS_FIRSTBIT;

 hsai_BlockB2.SlotInit.FirstBitOffset = 0;

 hsai_BlockB2.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;

 hsai_BlockB2.SlotInit.SlotNumber = 4;

 hsai_BlockB2.SlotInit.SlotActive = 0x0000000F;

 if (HAL_SAI_Init(&hsai_BlockB2) != HAL_OK)

 {

   Error_Handler();

 }

 /* USER CODE BEGIN SAI2_Init 2 */

 /* USER CODE END SAI2_Init 2 */

}

2.SAI DMA Configuration.

i)sai2_A :

 hdma_sai2_a.Instance = DMA2_Stream0;

   hdma_sai2_a.Init.Request = DMA_REQUEST_SAI2_A;

   hdma_sai2_a.Init.Direction = DMA_PERIPH_TO_MEMORY;

   hdma_sai2_a.Init.PeriphInc = DMA_PINC_DISABLE;

   hdma_sai2_a.Init.MemInc = DMA_MINC_ENABLE;

   hdma_sai2_a.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

   hdma_sai2_a.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

   hdma_sai2_a.Init.Mode = DMA_CIRCULAR;

   hdma_sai2_a.Init.Priority = DMA_PRIORITY_VERY_HIGH;

   hdma_sai2_a.Init.FIFOMode = DMA_FIFOMODE_ENABLE;

   hdma_sai2_a.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;

   hdma_sai2_a.Init.MemBurst = DMA_MBURST_SINGLE;

   hdma_sai2_a.Init.PeriphBurst = DMA_PBURST_SINGLE;

   if (HAL_DMA_Init(&hdma_sai2_a) != HAL_OK)

   {

     Error_Handler();

   }

   /* Several peripheral DMA handle pointers point to the same DMA handle.

    Be aware that there is only one channel to perform all the requested DMAs. */

   __HAL_LINKDMA(hsai,hdmarx,hdma_sai2_a);

   __HAL_LINKDMA(hsai,hdmatx,hdma_sai2_a);

ii)SAI2_B:

 hdma_sai2_b.Instance = DMA2_Stream1;

   hdma_sai2_b.Init.Request = DMA_REQUEST_SAI2_B;

   hdma_sai2_b.Init.Direction = DMA_MEMORY_TO_PERIPH;

   hdma_sai2_b.Init.PeriphInc = DMA_PINC_DISABLE;

   hdma_sai2_b.Init.MemInc = DMA_MINC_ENABLE;

   hdma_sai2_b.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

   hdma_sai2_b.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

   hdma_sai2_b.Init.Mode = DMA_NORMAL;

   hdma_sai2_b.Init.Priority = DMA_PRIORITY_HIGH;

   hdma_sai2_b.Init.FIFOMode = DMA_FIFOMODE_ENABLE;

   hdma_sai2_b.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;

   hdma_sai2_b.Init.MemBurst = DMA_MBURST_SINGLE;

   hdma_sai2_b.Init.PeriphBurst = DMA_PBURST_SINGLE;

   if (HAL_DMA_Init(&hdma_sai2_b) != HAL_OK)

   {

     Error_Handler();

   }

   /* Several peripheral DMA handle pointers point to the same DMA handle.

    Be aware that there is only one channel to perform all the requested DMAs. */

   __HAL_LINKDMA(hsai,hdmarx,hdma_sai2_b);

   __HAL_LINKDMA(hsai,hdmatx,hdma_sai2_b);

3.DMA intialization

static void MX_DMA_Init(void)

{

 /* DMA controller clock enable */

 __HAL_RCC_DMAMUX_CLK_ENABLE();

 __HAL_RCC_DMA2_CLK_ENABLE();

 /* DMA interrupt init */

 /* DMA2_Stream0_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 1, 0);

 HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);

 /* DMA2_Stream1_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 1, 0);

 HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);

}

How can i resolve this?

0 REPLIES 0