AnsweredAssumed Answered

STM32f303 AWD with DMA issue

Question asked by mishaskt on Jan 30, 2017

Hello! I'm working with STM32F303CBT6 and i have an issue there. I'm trying to use analog watchdog on ADC1 with two working channels (channel 1 and channel 2), also i launch DMA1 channel 1 to store read data from these channels in circular mode of DMA and ADC. The problem is when i use AWD and DMA at the same time i always have an interrupt flag on AWD, even when input signal level is within the window, although DMA works fine. But when i turn off DMA requests in ADC(line 94) i get AWD works right. Here i post code for DMA and ADC initialization. I will be thankful for any info.

 

/* Enable DMA1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC_data[0];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* Enable DMA1 Channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);

/* Configure the ADC clock */
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1);

/* Enable ADC1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);

/* ADC Channel configuration */
/* GPIOC Periph clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

/* Configure ADC Channel7 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_StructInit(&ADC_InitStructure);
ADC_DeInit(ADC1);

/* Calibration procedure */
ADC_VoltageRegulatorCmd(ADC1, ENABLE);

/* delay */
for(i= 0; i < 1000; i++){}

ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1) != RESET );

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Clock = ADC_Clock_SynClkModeDiv1;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;
ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_NbrOfRegChannel = 2;
ADC_Init(ADC1, &ADC_InitStructure);

//ADC1 sequencer length
ADC_RegularChannelSequencerLengthConfig(ADC1, 2);

// ADC1 regular channel7 configuration
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_19Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_19Cycles5);

//Configure AWD on all regular channels
ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_AllRegEnable);

//Configure thresholds on AWD1
ADC_AnalogWatchdog1ThresholdsConfig(ADC1, 1000, 0);

/* Configure and enable ADC1 interrupt */
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

/* Enable AWD interrupt */
ADC_ITConfig(ADC1, ADC_IT_AWD1, ENABLE);

/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);

/* wait for ADRDY */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));

/* ADC1 DMA Enable */
ADC_DMACmd(ADC1, ENABLE);
ADC_DMAConfig(ADC1, ADC_DMAMode_Circular);

/* Start ADC1 Software Conversion */
ADC_StartConversion(ADC1);

Outcomes