cancel
Showing results for 
Search instead for 
Did you mean: 

How to use STM32H743ZGT6 I2S & DMA Master Function when I use STM32CubeH7 HAL library

JYUNWEI wu
Associate III

Hi everyone,

when I used STM32CubeMX to generate initial code and would like to use HAL library of HAL_I2S_Transmit_DMA to transmit data to device, I didn't get any signal output from all pins Have someone meet this problem? Could you please give some advance? thanks a lots. My program as below:

void MX_DMA_Init(void) 

{

 /* DMA controller clock enable */

 __HAL_RCC_DMA1_CLK_ENABLE();

 /* DMA interrupt init */

 /* DMA1_Stream0_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);

 HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);

 /* DMA1_Stream1_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 0, 0);

 HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);

 /* DMA1_Stream3_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 0, 0);

 HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);

}

uint16_t DAC_SIGNAL_Sinus[32] = {

    2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056,

    4095, 4056, 3939, 3750, 3495, 3185, 2831, 2447,

    2047, 1647, 1263, 909, 599, 344, 155, 38,

    0, 38, 155, 344, 599, 909, 1263, 1647

  };

/* USER CODE END 0 */

void MX_I2S1_Init(void)

{

 hi2s1.Instance = SPI1;

 hi2s1.Init.Mode = I2S_MODE_MASTER_TX;

 hi2s1.Init.Standard = I2S_STANDARD_PHILIPS;

 hi2s1.Init.DataFormat = I2S_DATAFORMAT_16B;

 hi2s1.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;

 hi2s1.Init.AudioFreq = I2S_AUDIOFREQ_48K;

 hi2s1.Init.CPOL = I2S_CPOL_LOW;

 hi2s1.Init.FirstBit = I2S_FIRSTBIT_MSB;

 hi2s1.Init.WSInversion = I2S_WS_INVERSION_DISABLE;

 hi2s1.Init.IOSwap = I2S_IO_SWAP_DISABLE;

 hi2s1.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT;

 hi2s1.Init.FifoThreshold = I2S_FIFO_THRESHOLD_01DATA;

 hi2s1.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE;

 hi2s1.Init.SlaveExtendFREDetection = I2S_SLAVE_EXTEND_FRE_DETECTION_DISABLE;

 if (HAL_I2S_Init(&hi2s1) != HAL_OK)

 {

  Error_Handler();

 }

}

void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(hi2s->Instance==SPI1)

 {

 /* USER CODE BEGIN SPI1_MspInit 0 */

 /* USER CODE END SPI1_MspInit 0 */

  /* Peripheral clock enable */

  __HAL_RCC_SPI1_CLK_ENABLE();

  

  __HAL_RCC_GPIOC_CLK_ENABLE();

  __HAL_RCC_GPIOD_CLK_ENABLE();

  __HAL_RCC_GPIOG_CLK_ENABLE();

  /**I2S1 GPIO Configuration   

  PC4   ------> I2S1_MCK

  PD7   ------> I2S1_SDO

  PG9   ------> I2S1_SDI

  PG10   ------> I2S1_WS

  PG11   ------> I2S1_CK 

  */

  GPIO_InitStruct.Pin = GPIO_PIN_4;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;

  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_7;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;

  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;

  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

  /* I2S1 DMA Init */

  /* SPI1_TX Init */

  hdma_spi1_tx.Instance = DMA1_Stream0;

  hdma_spi1_tx.Init.Request = DMA_REQUEST_SPI1_TX;

  hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;

  hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;

  hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;

  hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

  hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

  hdma_spi1_tx.Init.Mode = DMA_CIRCULAR;

  hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW;

  hdma_spi1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

  if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK)

  {

   Error_Handler();

  }

  __HAL_LINKDMA(hi2s,hdmatx,hdma_spi1_tx);

  /* I2S1 interrupt Init */

  HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(SPI1_IRQn);

 /* USER CODE BEGIN SPI1_MspInit 1 */

 /* USER CODE END SPI1_MspInit 1 */

 }

}

/**

* @brief I2S MSP De-Initialization

* This function freeze the hardware resources used in this example

* @param hi2s: I2S handle pointer

* @retval None

*/

void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)

{

 if(hi2s->Instance==SPI1)

 {

 /* USER CODE BEGIN SPI1_MspDeInit 0 */

 /* USER CODE END SPI1_MspDeInit 0 */

  /* Peripheral clock disable */

  __HAL_RCC_SPI1_CLK_DISABLE();

  

  /**I2S1 GPIO Configuration   

  PC4   ------> I2S1_MCK

  PD7   ------> I2S1_SDO

  PG9   ------> I2S1_SDI

  PG10   ------> I2S1_WS

  PG11   ------> I2S1_CK 

  */

  HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4);

  HAL_GPIO_DeInit(GPIOD, GPIO_PIN_7);

  HAL_GPIO_DeInit(GPIOG, GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11);

  /* I2S1 DMA DeInit */

  HAL_DMA_DeInit(hi2s->hdmatx);

  /* I2S1 interrupt DeInit */

  HAL_NVIC_DisableIRQ(SPI1_IRQn);

 /* USER CODE BEGIN SPI1_MspDeInit 1 */

 /* USER CODE END SPI1_MspDeInit 1 */

 }

}

 /**

 * @brief The application entry point.

 * @retval int

 */

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

  

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_I2S1_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) != GPIO_PIN_SET)

  {

   HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);

   HAL_Delay(100);

  }

  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);

  HAL_I2S_Transmit_DMA(&hi2s1,(uint16_t *) DAC_SIGNAL_Sinus, 32);

  HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);

  HAL_Delay(50);

 }

 /* USER CODE END 3 */

}

2 REPLIES 2
JYUNWEI wu
Associate III

Have someone know this issue?

JYUNWEI wu
Associate III

I don't what I can solve this issue. have one meet the same issue?