Skip to main content
Maor Avni
Associate II
July 26, 2017
Solved

ADC1 vs. ADC3 behavior

  • July 26, 2017
  • 6 replies
  • 3697 views
Posted on July 26, 2017 at 09:50

Hi,

I'm using STM32F427ZI with FreeRTOS.

I am configuring both ADC1 and ADC3 to run using DMA, but I'm getting different behavior between them. 

This is the configuration for ADC3, ADC1 is configuration the same:

0690X00000607gDQAQ.png

ADC1 is configured to use DMA2 Stream 0, and ADC3 is configured to use DMA2 Stream 1.

This is configuration of DMA for ADC3. The configuration is the same for the DMA for ADC1.

0690X00000607gIQAQ.png

After calling all init functions of the ADC and the DMA, I call the ADC Start DMA function:

result = HAL_ADC_Start_DMA(&hadc3, (uint32_t*)(adc3SamplesArray), 3);

If I call the function for ADC1, the DMA performs as expected and the callback is called.

If I call the function for ADC3, no call back is called, and the DMA doesn't seem to be doing anything.

What am I missing?

#adc #dma
This topic has been closed for replies.
Best answer by Vangelis Fortounas
Posted on July 30, 2017 at 14:01

Hello!

I can reproduce your error..

To solve it  put 3/ threshold fifo at both dma channels (or less, depending your config).

Handle DMA overruns by implement HAL_ADC_ErrorCallback.

/**

  * @brief  Error ADC callback.

  * @note   In case of error due to overrun when using ADC with DMA transfer

  *         (HAL ADC handle paramater ''ErrorCode'' to state ''HAL_ADC_ERROR_OVR''):

  *         - Reinitialize the DMA using function ''HAL_ADC_Stop_DMA()''.

  *         - If needed, restart a new ADC conversion using function

  *           ''HAL_ADC_Start_DMA()''

  *           (this function is also clearing overrun flag)

  * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains

  *         the configuration information for the specified ADC.

  * @retval None

  */

__weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)0690X00000603tAQAQ.jpg

6 replies

ST Technical Moderator
July 27, 2017
Posted on July 27, 2017 at 22:48

Hi,

Have you enabled the clock used by ADC3?

Which CubeMx version are you using?  Ensure that you are using the last version.

Regards

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
Maor Avni
Maor AvniAuthor
Associate II
July 30, 2017
Posted on July 30, 2017 at 09:29

I'm using the latest versions of both the CubeMx and the firmware for the MCU I'm using.

I'll check if I enabled the clock for the ADC3, but I don't remember having to enable the clock to ADC1. Isn't that done automatically by CubeMx? I'm using code that was generated completely by CubeMx, without any hand-made changes. 

In addition, my project is a migration of an old project that uses the old Standard Library on our board. I'm migrating the code to use the new HAL and LL API's for future migration to the F7, which doesn't have the old Standard Library API. 

ADC3 worked on that board. 

Vangelis Fortounas
Associate II
July 30, 2017
Posted on July 30, 2017 at 10:44

Hello!

You have the option  to use  HAL_ADC_ErrorCallbackADC_HandleTypeDef* hadc); and to take the error code .(hadc->ErrorCode)

Other option is to put a break to ADC_IRQHandler(); to see if ADC3 ISR is called.

You can also  post your .IOC file (cubemx conf file) to help the community try to solve the problem.

Vangelis Fortounas
Associate II
July 30, 2017
Posted on July 30, 2017 at 14:01

Hello!

I can reproduce your error..

To solve it  put 3/ threshold fifo at both dma channels (or less, depending your config).

Handle DMA overruns by implement HAL_ADC_ErrorCallback.

/**

  * @brief  Error ADC callback.

  * @note   In case of error due to overrun when using ADC with DMA transfer

  *         (HAL ADC handle paramater ''ErrorCode'' to state ''HAL_ADC_ERROR_OVR''):

  *         - Reinitialize the DMA using function ''HAL_ADC_Stop_DMA()''.

  *         - If needed, restart a new ADC conversion using function

  *           ''HAL_ADC_Start_DMA()''

  *           (this function is also clearing overrun flag)

  * @param  hadc: pointer to a ADC_HandleTypeDef structure that contains

  *         the configuration information for the specified ADC.

  * @retval None

  */

__weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc)0690X00000603tAQAQ.jpg
Maor Avni
Maor AvniAuthor
Associate II
July 30, 2017
Posted on July 30, 2017 at 15:33

Thanks. That did the trick.