cancel
Showing results for 
Search instead for 
Did you mean: 

ADC1 vs. ADC3 behavior

Maor Avni
Associate II
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
1 ACCEPTED SOLUTION

Accepted Solutions
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

View solution in original post

6 REPLIES 6
Imen.D
ST Employee
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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
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. 

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.

Posted on July 30, 2017 at 11:02

I've checked hadc3. The state is static at 0x100 (BUSY) and the ErrorCode is 0.

I get the same behavior when running without the DMA.

Also the error callbacks, both with and without DMA are not called.

I've attached the IOC project.

________________

Attachments :

FEC3.ioc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyXU&d=%2Fa%2F0X0000000b9F%2F5lQ0LQRVsjAzsHJfk94IH6L3qBW3eGk24k5QU9uM5HU&asPdf=false
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
Posted on July 30, 2017 at 15:33

Thanks. That did the trick.