STM32 SAI加DMA 配置为TDM 4通道循环接收数据,板卡在运行一段时间后,会由正常的1234通道的顺序变为2341或者3412之类的 void MX_SAI1_Init(void) { /* USER CODE BEGIN SAI1_Init 0 */ /* USER CODE END SAI1_Init 0 */ /* USER CODE BEGIN SAI1_Init 1 */ /* USER CODE END SAI1_Init 1 */ hsai_BlockA1.Instance = SAI1_Block_A; hsai_BlockA1.Init.Protocol = SAI_FREE_PROTOCOL; hsai_BlockA1.Init.AudioMode = SAI_MODEMASTER_RX; hsai_BlockA1.Init.DataSize = SAI_DATASIZE_32; hsai_BlockA1.Init.FirstBit = SAI_FIRSTBIT_MSB; hsai_BlockA1.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE; hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS; hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE; hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE; hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY; hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_48K; hsai_BlockA1.Init.SynchroExt = SAI_SYNCEXT_DISABLE; hsai_BlockA1.Init.MonoStereoMode = SAI_STEREOMODE; hsai_BlockA1.Init.CompandingMode = SAI_NOCOMPANDING; hsai_BlockA1.FrameInit.FrameLength = 128; hsai_BlockA1.FrameInit.ActiveFrameLength = 2; hsai_BlockA1.FrameInit.FSDefinition = SAI_FS_STARTFRAME; hsai_BlockA1.FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH; hsai_BlockA1.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT; hsai_BlockA1.SlotInit.FirstBitOffset = 0; hsai_BlockA1.SlotInit.SlotSize = SAI_SLOTSIZE_32B; hsai_BlockA1.SlotInit.SlotNumber = 4; hsai_BlockA1.SlotInit.SlotActive = 0x0000000F; if (HAL_SAI_Init(&hsai_BlockA1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN SAI1_Init 2 */ /* USER CODE END SAI1_Init 2 */ } void HAL_SAI_MspInit(SAI_HandleTypeDef* hsai) { GPIO_InitTypeDef GPIO_InitStruct; /* SAI1 */ if(hsai->Instance==SAI1_Block_A) { /* SAI1 clock enable */ if (SAI1_client == 0) { __HAL_RCC_SAI1_CLK_ENABLE(); } SAI1_client ++; /**SAI1_A_Block_A GPIO Configuration PE4 ------> SAI1_FS_A PE5 ------> SAI1_SCK_A PE6 ------> SAI1_SD_A */ GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF6_SAI1; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_sai1_a.Instance = DMA2_Stream1; hdma_sai1_a.Init.Channel = DMA_CHANNEL_0; hdma_sai1_a.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_sai1_a.Init.PeriphInc = DMA_PINC_DISABLE; hdma_sai1_a.Init.MemInc = DMA_MINC_ENABLE; hdma_sai1_a.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_sai1_a.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_sai1_a.Init.Mode = DMA_CIRCULAR; hdma_sai1_a.Init.Priority = DMA_PRIORITY_LOW; hdma_sai1_a.Init.FIFOMode = DMA_FIFOMODE_DISABLE; if (HAL_DMA_Init(&hdma_sai1_a) != HAL_OK) { Error_Handler(); } /* Several peripheral DMA handle pointers point to the same DMA handle. Be aware that there is only one stream to perform all the requested DMAs. */ __HAL_LINKDMA(hsai,hdmarx,hdma_sai1_a); __HAL_LINKDMA(hsai,hdmatx,hdma_sai1_a); } } |
STM32G030F6 ADC+DMA多通道非连续采样无法正常工作?
stm32f103的uac模式对usb接收的数据实时处理
FATFS到f_mount()卡死,求助,用的野火文件
TIM2输入捕获,DMA开启中断传输输入捕获数据,TIM6计时
stm32编码器模式计数问题
STM32H533RE使用主从定时器产生指定脉冲个数,使用其他定时器进行ETR计数,计数不对?大佬们帮忙看看。
STM32的HAL库,如何对高八位和低八位同时赋值和操作?
STM32L4R9最大支持SD卡的容量是?支持SDXC 64G卡吗?
M24M02 响应时间
STM32H747I-DISCO的LCD固件更新怎么在已有的STM32CubeIDE工程中更新?
结合你的代码来看,传输方向是从外设到内存,不知你的DMA的触发请求具体是什么?
应该是传输过程中DMA请求事件有无需要同步而不发生乱序的问题?