cancel
Showing results for 
Search instead for 
Did you mean: 

ADC3 Multichannel Scan Mode using DMA not working.

sbstek
Associate

I tried doing line by line debugging to find out that Error code is being set by:

HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)

To be specific, this line of the code:

else
 
 {
 
   /* Process unlocked */
 
   __HAL_UNLOCK(hdma);
 
 
   /* Set the error code to busy */
 
   hdma->ErrorCode = HAL_DMA_ERROR_BUSY;  // the error code is set here.
 
 
   /* Return error status */
 
   status = HAL_ERROR;
 
 }
 
 return status;
 
}

here is my ADC config:

hadc3.Instance         = ADC3;
 
 if (HAL_ADC_DeInit(&hadc3) != HAL_OK)
 {  Error_Handler();  }
 
 hadc3.Init.ClockPrescaler          = ADC_CLOCK_ASYNC_DIV2;         /* Asynchronous clock mode, input ADC clock divided by 2*/
 hadc3.Init.Resolution              = ADC_RESOLUTION_12B;           /* 16-bit resolution for converted data */
 hadc3.Init.ScanConvMode            = ADC_SCAN_ENABLE;                      /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
 hadc3.Init.EOCSelection            = ADC_EOC_SINGLE_CONV;          /* EOC flag picked-up to indicate conversion end */
 hadc3.Init.LowPowerAutoWait        = DISABLE;    /* Auto-delayed conversion feature disabled */
 hadc3.Init.ContinuousConvMode      = ENABLE;                       /* Continuous mode enabled  */
 hadc3.Init.NbrOfConversion         = 3;   
 hadc3.Init.DiscontinuousConvMode   = DISABLE;    /* Parameter discarded because sequencer is disabled */
 hadc3.Init.ExternalTrigConv        = ADC_SOFTWARE_START;    /* Software start to trig the 1st conversion manually, without external event */
 hadc3.Init.ExternalTrigConvEdge    = ADC_EXTERNALTRIGCONVEDGE_NONE; /* software trigger chosen */
 hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR; /* ADC DMA circular */
 hadc3.Init.Overrun                 = ADC_OVR_DATA_OVERWRITTEN;     /* DR register is overwritten*/
 hadc3.Init.OversamplingMode        = DISABLE;         /* No oversampling */
 /* Initialize ADC peripheral according to the passed parameters */
 
 if (HAL_ADC_Init(&hadc3) != HAL_OK)
 {  Error_Handler();  }
 /* ### - 2 - Start calibration ############################################ */
 if (HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
 {  Error_Handler();  }
 
 

DMA config for ADC 3 is as follows:

__HAL_RCC_GPIOF_CLK_ENABLE();
	  /* ADC Periph clock enable */
	  __HAL_RCC_ADC3_CLK_ENABLE();
	  /* ADC Periph interface clock configuration */
	  /* Enable DMA clock */
	  __HAL_RCC_DMA2_CLK_ENABLE();
 
	  /*##- 2- Configure peripheral GPIO #########################################*/
	  GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_4 | GPIO_PIN_5;
	  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
	  GPIO_InitStruct.Pull = GPIO_NOPULL;
	  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
	  hdma_adc3.Instance = DMA1_Stream2;
	  hdma_adc3.Init.Request = DMA_REQUEST_ADC3;
	  hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY;
	  hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE;
	  hdma_adc3.Init.MemInc = DMA_MINC_ENABLE;
	  hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
	  hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
	  hdma_adc3.Init.Mode = DMA_CIRCULAR;
	  hdma_adc3.Init.Priority = DMA_PRIORITY_HIGH;
	  hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
 
	  __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc3);
	  HAL_NVIC_SetPriority(DMA1_Stream2_IRQn, 0, 1);
	  HAL_NVIC_EnableIRQ(DMA1_Stream2_IRQn);

I have tried looking into other posts about the same issue where one of the issue with D cache enabled was that DMA cant access DTCM section of RAM. But i can confirm i am using RAM from section AXI-RAM starting from 0x24000000.

I have also tried using FIFO mode as suggested by another post but still the error code was set by the HAL_DMA_START_IT(..) function.

0 REPLIES 0