cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get DMA Setting tab for DAC1 OUT2 for cortex M4 in stm32mp157a.

Sindhu Vadde
Associate III

Hi,

We are using Stm32mp157a Processor in Our custom board.

We are configuring PA5 as DAC1_OUT2.We want to configure DMA for DAC. But we didnot get an DMA setting tab in DAC configuration in stm32 Cube mx.How do i enable DMA for DAC? You can see in below Attachment.

0693W00000NqPAIQA3.png

4 REPLIES 4
PatrickF
ST Employee

Hi @Sindhu Vadde​ ,

you are right, seems missing on STM32CubeMx.

I think feature is available inside STM32CubeMP1 HAL by manually adding relevant inits and function calls in your code.

We are checking this internally and come back to you.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi,

We are adding DMA for DAC Manually But when we Check CR register It is not enabled.You can see my procedure of adding DMA manually to DAC below.

1.DMA initialization Function.

Handler for DAC DMA:

DMA_HandleTypeDef hdma_dac1_ch2;

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);

 /* DMA2_Stream1_IRQn interrupt configuration */

  HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 1, 0);

  HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);

}

Here Stream 0 and 1 used for SAI.Stream 2 is added by us Manually.

2.IRQ handler added by us manually

void DMA2_Stream2_IRQHandler(void)

{

 /* USER CODE BEGIN DMA2_Stream0_IRQn 0 */

 /* USER CODE END DMA2_Stream0_IRQn 0 */

 HAL_DMA_IRQHandler(&hdma_dac1_ch2);

 /* USER CODE BEGIN DMA2_Stream0_IRQn 1 */

 /* USER CODE END DMA2_Stream0_IRQn 1 */

}

3,DAC Msp init:

void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(hdac->Instance==DAC1)

 {

 /* USER CODE BEGIN DAC1_MspInit 0 */

 /* USER CODE END DAC1_MspInit 0 */

   /* Peripheral clock enable */

   __HAL_RCC_DAC12_CLK_ENABLE();

   __HAL_RCC_GPIOA_CLK_ENABLE();

   /**DAC1 GPIO Configuration

   PA5    ------> DAC1_OUT2

   */

   GPIO_InitStruct.Pin = GPIO_PIN_5;

   GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

   /* DAC1 interrupt Init */

//   HAL_NVIC_SetPriority(DAC_IRQn, 1, 0);

 //  HAL_NVIC_EnableIRQ(DAC_IRQn);

 /* USER CODE BEGIN DAC1_MspInit 1 */

      hdma_dac1_ch2.Instance = DMA2_Stream2;

       hdma_dac1_ch2.Init.Request = DMA_REQUEST_DAC1;

       hdma_dac1_ch2.Init.Direction = DMA_MEMORY_TO_PERIPH;

       hdma_dac1_ch2.Init.PeriphInc = DMA_PINC_DISABLE;

       hdma_dac1_ch2.Init.MemInc = DMA_MINC_ENABLE;

       hdma_dac1_ch2.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

       hdma_dac1_ch2.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

       hdma_dac1_ch2.Init.Mode = DMA_CIRCULAR;

       hdma_dac1_ch2.Init.Priority = DMA_PRIORITY_MEDIUM;

       hdma_dac1_ch2.Init.FIFOMode = DMA_FIFOMODE_ENABLE;

       hdma_dac1_ch2.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;

       hdma_dac1_ch2.Init.MemBurst = DMA_MBURST_SINGLE;

       hdma_dac1_ch2.Init.PeriphBurst = DMA_PBURST_SINGLE;

       if (HAL_DMA_Init(&hdma_dac1_ch2) != HAL_OK)

       {

         Error_Handler();

       }

       __HAL_LINKDMA(hdac,DMA_Handle2,hdma_dac1_ch2);

       /* DAC1 interrupt Init */

         HAL_NVIC_SetPriority(DAC_IRQn, 1, 0);

         HAL_NVIC_EnableIRQ(DAC_IRQn);

         HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);

         HAL_NVIC_EnableIRQ(TIM2_IRQn);

 /* USER CODE END DAC1_MspInit 1 */

 }

}

In between  /* USER CODE BEGIN DAC1_MspInit 1 */ and /* USER CODE END DAC1_MspInit 1 */ we added by us.

Is there any mistake in adding DMA manually.

Correct me where i did wrong in my code.

Hi,

No evident mistake.

Did you assign a timer (seems you use TIM6 in first figure) to DAC trigger ?

Did you started the associated timer ?

Did you use HAL_DAC_Start_DMA() ?

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi,

yes we use timer 6 for triggering dac and we started Timer then we used HAL_DAC_Start_DMA() but there is no wave on DAC line.But When we use no trigger withour starting dma and timer we get some wave by using

while(1)

 {

    for(int i=0;i<=31;i++)

    {

           HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_2, DAC_ALIGN_8B_R,sine_wave_array1[i]);

     }

 }

uint16_t sine_wave_array1[32] = {2047, 1648, 1264, 910, 600, 345, 156, 39, 0, 39, 156, 345,600, 910, 1264, 1648, 2048,

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