cancel
Showing results for 
Search instead for 
Did you mean: 

The callback function HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac) with STM32U575CGU6 doesn't work

Pavel D
Associate II

Could someone assist and clarify how to configure GPDMA for DAC for use the callback function HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac) with STM32U575CGU6.

I caught:

/* Data Transfer Error Interrupt management */

 if ((__HAL_DMA_GET_FLAG(hdma, DMA_FLAG_DTE) != 0U))

/* Update the DMA channel error code */

   hdma->ErrorCode |= HAL_DMA_ERROR_DTE;

My goal is to catch the callback functions:

HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac) and HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)

and integrate mp3 player with STM32U575CGU6.

Before STM32U575CGU6 I worked with STM32F413 and my the code worked.

Please assist.

Thanks!

Please see some parts of the code for explaining.

//////////////////////////////////////////////////////////this is a configuration of DMA //////////////

/* Includes ------------------------------------------------------------------*/

#include "gpdma.h"

/* GPDMA1 init function */

void MX_GPDMA1_Init(void)

{

/* Peripheral clock enable */

__HAL_RCC_GPDMA1_CLK_ENABLE();

/* GPDMA1 interrupt Init */

HAL_NVIC_SetPriority(GPDMA1_Channel10_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(GPDMA1_Channel10_IRQn)

}

////////////////////////////////////////////////////////

//////////////////////////////////////////////////////this is configuration of DAC//////////////

/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/

#include "dac.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

DAC_HandleTypeDef hdac1;

DMA_HandleTypeDef handle_GPDMA1_Channel10;

/* DAC1 init function */

void MX_DAC1_Init(void)

{

DAC_ChannelConfTypeDef sConfig = {0};

DAC_AutonomousModeConfTypeDef sAutonomousMode = {0};

/** DAC Initialization

*/

hdac1.Instance = DAC1;

if (HAL_DAC_Init(&hdac1) != HAL_OK)

{

Error_Handler();

}

/** DAC channel OUT1 config

*/

sConfig.DAC_HighFrequency = DAC_HIGH_FREQUENCY_INTERFACE_MODE_ABOVE_80MHZ;

sConfig.DAC_DMADoubleDataMode = DISABLE;

sConfig.DAC_SignedFormat = DISABLE;

sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;

sConfig.DAC_Trigger = DAC_TRIGGER_T2_TRGO;

sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;

sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_EXTERNAL;

sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;

if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)

{

Error_Handler();

}

/** Configure Autonomous Mode

*/

sAutonomousMode.AutonomousModeState = DAC_AUTONOMOUS_MODE_DISABLE;

if (HAL_DACEx_SetConfigAutonomousMode(&hdac1, &sAutonomousMode) != HAL_OK)

{

Error_Handler();

}

}

void HAL_DAC_MspInit(DAC_HandleTypeDef* dacHandle)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

if(dacHandle->Instance==DAC1)

{

/* USER CODE BEGIN DAC1_MspInit 0 */

/* USER CODE END DAC1_MspInit 0 */

/** Initializes the peripherals clock

*/

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC|RCC_PERIPHCLK_DAC1;

PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSI;

PeriphClkInit.Dac1ClockSelection = RCC_DAC1CLKSOURCE_LSI;

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

{

Error_Handler();

}

/* DAC1 clock enable */

__HAL_RCC_DAC1_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

/**DAC1 GPIO Configuration

PA4 ------> DAC1_OUT1

*/

GPIO_InitStruct.Pin = GPIO_PIN_4;

GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* DAC1 DMA Init */

/* GPDMA1_REQUEST_DAC1_CH1 Init */

handle_GPDMA1_Channel10.Instance = GPDMA1_Channel10;

handle_GPDMA1_Channel10.Init.Request = GPDMA1_REQUEST_DAC1_CH1;

handle_GPDMA1_Channel10.Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;

handle_GPDMA1_Channel10.Init.Direction = DMA_MEMORY_TO_PERIPH;

handle_GPDMA1_Channel10.Init.SrcInc = DMA_SINC_INCREMENTED;

handle_GPDMA1_Channel10.Init.DestInc = DMA_DINC_FIXED;

handle_GPDMA1_Channel10.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_HALFWORD;

handle_GPDMA1_Channel10.Init.DestDataWidth = DMA_DEST_DATAWIDTH_BYTE;

handle_GPDMA1_Channel10.Init.Priority = DMA_LOW_PRIORITY_LOW_WEIGHT;

handle_GPDMA1_Channel10.Init.SrcBurstLength = 1;

handle_GPDMA1_Channel10.Init.DestBurstLength = 1;

handle_GPDMA1_Channel10.Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT1|DMA_DEST_ALLOCATED_PORT0;

handle_GPDMA1_Channel10.Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;

handle_GPDMA1_Channel10.Init.Mode = DMA_NORMAL;

if (HAL_DMA_Init(&handle_GPDMA1_Channel10) != HAL_OK)

{

Error_Handler();

}

/**DAC1 GPIO Configuration

PA4 ------> DAC1_OUT1

*/

HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);

///////////////////////////////////////////

//////////////////////////////////////////////////////this is configuration of the timers //////////////

TIM_HandleTypeDef htim2;

/* TIM2 init function */

void MX_TIM2_Init(void)

{

/* USER CODE BEGIN TIM2_Init 0 */

/* USER CODE END TIM2_Init 0 */

TIM_ClockConfigTypeDef sClockSourceConfig = {0};

TIM_MasterConfigTypeDef sMasterConfig = {0};

/* USER CODE BEGIN TIM2_Init 1 */

/* USER CODE END TIM2_Init 1 */

htim2.Instance = TIM2;

htim2.Init.Prescaler = 0;

htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

htim2.Init.Period = 2999;

htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim2) != HAL_OK)

{

Error_Handler();

}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)

{

Error_Handler();

}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN TIM2_Init 2 */

/* USER CODE END TIM2_Init 2 */

}

void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)

{

if(tim_baseHandle->Instance==TIM2)

{

/* USER CODE BEGIN TIM2_MspInit 0 */

/* USER CODE END TIM2_MspInit 0 */

/* TIM2 clock enable */

__HAL_RCC_TIM2_CLK_ENABLE();

/* TIM2 interrupt Init */

HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(TIM2_IRQn);

/* USER CODE BEGIN TIM2_MspInit 1 */

/* USER CODE END TIM2_MspInit 1 */

}

}

void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)

{

if(tim_baseHandle->Instance==TIM2)

{

/* USER CODE BEGIN TIM2_MspDeInit 0 */

/* USER CODE END TIM2_MspDeInit 0 */

/* Peripheral clock disable */

__HAL_RCC_TIM2_CLK_DISABLE();

/* TIM2 interrupt Deinit */

HAL_NVIC_DisableIRQ(TIM2_IRQn);

/* USER CODE BEGIN TIM2_MspDeInit 1 */

/* USER CODE END TIM2_MspDeInit 1 */

}

}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

///////////////////////////////////////////

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel D
Associate II

Hello Mohamed Aymen HZAMI (ST Employee),

Yes.

The issue was with HAL drivers (stm32u5xx_hal_dac.c).

In the file stm32u5xx_hal_dac.c on line number 869 we have function HAL_delay(1);

We need excepting HAL_delay(1) from the code and callbacks start working and SysTick_Handler() isn't stuck.

I think it's a bug of the drivers and developers will fix it.

**********************************************************************

**********************************************************************

 /* Process Unlocked */

 __HAL_UNLOCK(hdac);

 if (status == HAL_OK)

 {

  /* Enable the Peripheral */

  __HAL_DAC_ENABLE(hdac, Channel);

  /* Ensure minimum wait before using peripheral after enabling it */

   HAL_Delay(1);

 }

 else

 {

  hdac->ErrorCode |= HAL_DAC_ERROR_DMA;

 }

 /* Return function status */

 return status;

}

**************************************************************

**************************************************************

View solution in original post

6 REPLIES 6
Mohamed Aymen HZAMI
ST Employee

Hello @Pavel D​  and welcome to the community,

Did you activated the DAC interruption?

Mohamed Aymen

Pavel D
Associate II

Hello Mohamed Aymen HZAMI (ST Employee),

Yes.

The issue was with HAL drivers (stm32u5xx_hal_dac.c).

In the file stm32u5xx_hal_dac.c on line number 869 we have function HAL_delay(1);

We need excepting HAL_delay(1) from the code and callbacks start working and SysTick_Handler() isn't stuck.

I think it's a bug of the drivers and developers will fix it.

**********************************************************************

**********************************************************************

 /* Process Unlocked */

 __HAL_UNLOCK(hdac);

 if (status == HAL_OK)

 {

  /* Enable the Peripheral */

  __HAL_DAC_ENABLE(hdac, Channel);

  /* Ensure minimum wait before using peripheral after enabling it */

   HAL_Delay(1);

 }

 else

 {

  hdac->ErrorCode |= HAL_DAC_ERROR_DMA;

 }

 /* Return function status */

 return status;

}

**************************************************************

**************************************************************

Pavel D
Associate II

Or replace HAL_Delay(1); by function _NOP();

Mohamed Aymen HZAMI
ST Employee

Hello @Pavel D​,

Can you please share with us your project ?

Mohamed Aymen

Hi Mohamed Aymen HZAMI (ST Employee).

Sure.

Pavel D

Hello,

I can't run your project on my end, is there a specific setup you've done or could you send me a working version?

Mohamed Aymen