cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f1 HAL DAC+DMA DMA interrupt does not work

alexeyabulatov
Associate
Posted on December 25, 2015 at 21:32

Hello!

I'm porting my project from std periph to HAL using Cube to tune HAL. I have a trouble with sound playback on stm32f103ret6 via DAC channel 1 with DMA triggered by TIM6. DMA works well that I can see on my oscilloscope, but there is no interrupt generated when DMA is done. My DMA initialization:

void MX_DMA_Init(void) 
{
/* DMA controller clock enable */
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
HAL_NVIC_SetPriority(DMA2_Channel3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA2_Channel3_IRQn);
}

DAC and TIM6 initialization:

void initDAC()
{
// Configuring timer
TIM_MasterConfigTypeDef sMasterConfig;
htim6.Instance = TIM6;
htim6.Init.Prescaler = HAL_RCC_GetSysClockFreq() / (sampleRate * 2) - 1;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 1;
HAL_TIM_Base_Init(&htim6);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig);
// Configuring DAC
DAC_ChannelConfTypeDef sConfig;
/**DAC Initialization
*/
hdac.Instance = DAC;
HAL_DAC_Init(&hdac);
/**DAC channel OUT1 config
*/
sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1);
}

MSP initialization generated by Cube:

void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(hdac->Instance==DAC)
{
/* USER CODE BEGIN DAC_MspInit 0 */
/* USER CODE END DAC_MspInit 0 */
/* Peripheral clock enable */
__DAC_CLK_ENABLE();
/**DAC GPIO Configuration 
PA4 ------> DAC_OUT1 
*/
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral DMA init*/
hdma_dac_ch1.Instance = DMA2_Channel3;
hdma_dac_ch1.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_dac_ch1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_dac_ch1.Init.MemInc = DMA_MINC_ENABLE;
hdma_dac_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_dac_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_dac_ch1.Init.Mode = DMA_NORMAL;
hdma_dac_ch1.Init.Priority = DMA_PRIORITY_LOW;
HAL_DMA_Init(&hdma_dac_ch1);
__HAL_LINKDMA(hdac,DMA_Handle1,hdma_dac_ch1);
/* USER CODE BEGIN DAC_MspInit 1 */
/* USER CODE END DAC_MspInit 1 */
}
}

And then starting playback:

HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t*) m_buffer, 100, DAC_ALIGN_12B_R);
HAL_TIM_Base_Start(&htim6);

I added debug output to DMA interrupt directly before HAL function call:

void DMA2_Channel3_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Channel3_IRQn 0 */
/* USER CODE END DMA2_Channel3_IRQn 0 */
printf(''\n IRQ!! \n'');
HAL_DMA_IRQHandler(&hdma_dac_ch1);
/* USER CODE BEGIN DMA2_Channel3_IRQn 1 */
/* USER CODE END DMA2_Channel3_IRQn 1 */
}

I have properly configured output system so printf() function works via UART1 even from interrupts. And I see my signal on oscilloscope and no message on debug output. What should I check to fix my issue? #stm32-hal-dac-dma
1 REPLY 1
lucatesta9
Associate
Posted on January 20, 2016 at 16:08

Hello to all,

I have the same problem.

Consider this instruction:

HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t *) &wave_sample, X, DAC_ALIGN_12B_R); 

If I set X=1 I see half complete and complete callback.

If I set X=2 I see only half complete callback.

If I set X=3 I don't see any callback.

And the DAC output is not coherent with the register value

Have you solved this problem?

Any helps?

Thanx