cancel
Showing results for 
Search instead for 
Did you mean: 

ADC-DMA Test can't work on STM32H757 i-EVAL Board

HYeh.2233
Associate II

I want to test ADC-DMA function on STM32H757 i-EVAL Board. But the result is DMA transfer error. I just copy the example code of STM32Cube --- STM32H743I-EVAL\Examples\ADC\ADC_DMA_Transfer to my STM32H757 project.

When execute the code, it occurs only once DMA1_Stream1_IRQHandler.

And the result is DMA transfer error, TEIF1 in DMA_LISR is "1".

My IDE is "System Workbench for STM32"

Can any one help me to solve this problem?

Thanks for your help.

2 REPLIES 2
HYeh.2233
Associate II

The main setting are as bellow:

/* ### - 1 - Initialize ADC peripheral #################################### */

    AdcHandle.Instance          = ADCx;

    if (HAL_ADC_DeInit(&AdcHandle) != HAL_OK)

    {

        /* ADC de-initialization Error */

        Error_Handler();

    }

    AdcHandle.Init.ClockPrescaler           = ADC_CLOCK_ASYNC_DIV2;            /* Asynchronous clock mode, input ADC clock divided by 2*/

    AdcHandle.Init.Resolution               = ADC_RESOLUTION_16B;              /* 16-bit resolution for converted data */

    AdcHandle.Init.ScanConvMode             = DISABLE;                         /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */

    AdcHandle.Init.EOCSelection             = ADC_EOC_SINGLE_CONV;             /* EOC flag picked-up to indicate conversion end */

    AdcHandle.Init.LowPowerAutoWait         = DISABLE;                         /* Auto-delayed conversion feature disabled */

    AdcHandle.Init.ContinuousConvMode       = ENABLE;                          /* Continuous mode enabled (automatic conversion restart after each conversion) */

    AdcHandle.Init.NbrOfConversion          = 1;                               /* Parameter discarded because sequencer is disabled */

    AdcHandle.Init.DiscontinuousConvMode    = DISABLE;                         /* Parameter discarded because sequencer is disabled */

    AdcHandle.Init.NbrOfDiscConversion      = 1;                               /* Parameter discarded because sequencer is disabled */

    AdcHandle.Init.ExternalTrigConv         = ADC_SOFTWARE_START;              /* Software start to trig the 1st conversion manually, without external event */

    AdcHandle.Init.ExternalTrigConvEdge     = ADC_EXTERNALTRIGCONVEDGE_NONE;   /* Parameter discarded because software trigger chosen */

    AdcHandle.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR; /* ADC DMA circular requested */

    AdcHandle.Init.Overrun                  = ADC_OVR_DATA_OVERWRITTEN;        /* DR register is overwritten with the last conversion result in case of overrun */

    AdcHandle.Init.OversamplingMode         = DISABLE;                         /* No oversampling */

    /* Initialize ADC peripheral according to the passed parameters */

    if (HAL_ADC_Init(&AdcHandle) != HAL_OK)

    {

        Error_Handler();

    }

    /* ### - 2 - Start calibration ############################################ */

    if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)

    {

        Error_Handler();

    }

    /* ### - 3 - Channel configuration ######################################## */

    sConfig.Channel      = ADCx_CHANNEL;                /* Sampled channel number */

    sConfig.Rank         = ADC_REGULAR_RANK_1;          /* Rank of sampled channel number ADCx_CHANNEL */

    sConfig.SamplingTime = ADC_SAMPLETIME_810CYCLES_5;   /* Sampling time (number of clock cycles unit) */

    sConfig.SingleDiff   = ADC_SINGLE_ENDED;            /* Single-ended input channel */

    sConfig.OffsetNumber = ADC_OFFSET_NONE;             /* No offset subtraction */ 

    sConfig.Offset = 0;                                 /* Parameter discarded because offset correction is disabled */

    if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)

    {

        Error_Handler();

    }

    /* ### - 4 - Start conversion in DMA mode ################################# */

    if (HAL_ADC_Start_DMA(&AdcHandle,

                        (uint32_t *)aADCxConvertedData,

                        ADC_CONVERTED_DATA_BUFFER_SIZE

                        ) != HAL_OK)

    {

        Error_Handler();

    }

HYeh.2233
Associate II

DMA Setting is :

void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)

{

  GPIO_InitTypeDef          GPIO_InitStruct;

  static DMA_HandleTypeDef         DmaHandle;

  

  /*##-1- Enable peripherals and GPIO Clocks #################################*/

  /* Enable GPIO clock ****************************************/

  __HAL_RCC_GPIOA_CLK_ENABLE();

  /* ADC Periph clock enable */

  ADCx_CLK_ENABLE();

  /* ADC Periph interface clock configuration */

  __HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_CLKP);

  /* Enable DMA clock */

  DMAx_CHANNELx_CLK_ENABLE();

  

  /*##- 2- Configure peripheral GPIO #########################################*/

  /* ADC Channel GPIO pin configuration */

  GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN;

  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT, &GPIO_InitStruct);

  /*##- 3- Configure DMA #####################################################*/ 

  /*********************** Configure DMA parameters ***************************/

  DmaHandle.Instance                 = DMA1_Stream1;

  DmaHandle.Init.Request             = DMA_REQUEST_ADC1;

  DmaHandle.Init.Direction           = DMA_PERIPH_TO_MEMORY;

  DmaHandle.Init.PeriphInc           = DMA_PINC_DISABLE;

  DmaHandle.Init.MemInc              = DMA_MINC_ENABLE;

  DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

  DmaHandle.Init.MemDataAlignment    = DMA_MDATAALIGN_HALFWORD;

  DmaHandle.Init.Mode                = DMA_CIRCULAR;

  DmaHandle.Init.Priority            = DMA_PRIORITY_MEDIUM;

  /* Deinitialize  & Initialize the DMA for new transfer */

  HAL_DMA_DeInit(&DmaHandle);

  HAL_DMA_Init(&DmaHandle);

  

  /* Associate the DMA handle */

  __HAL_LINKDMA(hadc, DMA_Handle, DmaHandle);

  /* NVIC configuration for DMA Input data interrupt */

  HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 1, 0);

  HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);  

}