Page 1 of 1

STM32F3xx 2xADC with DMA Problem

Posted: Wed May 10, 2017 1:27 pm
by relsys
Hi,

When I try to use ADC1 and ADC2 with DMA, after initialization data in DMA section of ADCDriver struct is wrong.
Actually, the data written over DMA pointer is: "DMA failure":

bad_dma.jpg


Regards,
Rado

Re: STM32F3xx 2xADC with DMA Problem

Posted: Wed May 10, 2017 7:36 pm
by Giovanni
Hi,

Are assertions enabled? you could have a DMA conflict and assertions find those.

Giovanni

Re: STM32F3xx 2xADC with DMA Problem

Posted: Thu May 11, 2017 11:11 am
by relsys
Adress: 0x800357C is outside of _stm32_dma_streams scope.

I think may be is bad pointer arithmetic, but don't have time to investigate at the moment.

Workaround:

In file: adc_lld.c change line:

ADCD2.dmastp = STM32_DMA_STREAM(STM32_ADC_ADC2_DMA_STREAM);

with:

ADCD2.dmastp = STM32_DMA_STREAM(STM32_ADC_ADC1_DMA_STREAM);
ADCD2.dmastp += 5; //1..5

And check that DMA stream is not used by another peripheral.

Re: STM32F3xx 2xADC with DMA Problem

Posted: Sat May 13, 2017 7:28 am
by Giovanni
Moving this in "bug reports".

Which device are you using exactly? F303?

Giovanni

Re: STM32F3xx 2xADC with DMA Problem

Posted: Tue May 16, 2017 7:32 am
by relsys
Hi,

The device is STM32F334R8.

I also found that ADC1 did not measure correctly and for ADC2 there's no data written to [&adcsample_t].

Regards,
Rado

Re: STM32F3xx 2xADC with DMA Problem

Posted: Tue May 16, 2017 3:59 pm
by troepman
Hi,

We had the same problem using the second ADC at the stm32f334 but eventually solved it by overriding the DMA stream and channel set by the halInit function.

The low level HAL drivers seemed to expect it to use the second the DMA controller the program in ran into an exception starting the driver. We set it to use DMA2 and stream2. However when reading the datasheet carefully the f334 does not have a second DMA controller and the ADC2 is connected to channel 2 of DMA1(According to the reference manual page 180). Setting this is however not allowed by the lower HAL drivers causing it to not compile. Please correct me if I am wrong but this solved the issue for me.

Therefore in the mcuconf. we now initialize it to

Code: Select all

#define STM32_ADC_ADC2_DMA_STREAM           STM32_DMA_STREAM_ID(2, 1)


At the start of our Main we use:

Code: Select all

   halInit();
   chSysInit();

   ADCD2.dmastp = STM32_DMA_STREAM(STM32_DMA_STREAM_ID(1, 2));


Although this is not a sound solution it works and both our ADC are fully functioning.
Hope this work around helps you in your problem

With kind regards,
Thore Roepman

Re: STM32F3xx 2xADC with DMA Problem

Posted: Tue May 16, 2017 5:28 pm
by Giovanni
Thanks for reports, I will fix this during weekend.

Giovanni

Re: STM32F3xx 2xADC with DMA Problem

Posted: Wed May 17, 2017 8:03 am
by relsys
Hi,

The problem came from: stm32_registry.h, line:2386

Code: Select all

/*===========================================================================*/
/* STM32F334x8.                                                              */
/*===========================================================================*/
#if defined(STM32F334x8)
/* ADC attributes.*/
#define STM32_HAS_ADC1                      TRUE
#define STM32_ADC1_HANDLER                  Vector88
#define STM32_ADC1_NUMBER                   18
#define STM32_ADC1_DMA_MSK                  (STM32_DMA_STREAM_ID_MSK(1, 1))
#define STM32_ADC1_DMA_CHN                  0x00000000

#define STM32_HAS_ADC2                      TRUE
#define STM32_ADC2_HANDLER                  Vector88
#define STM32_ADC2_NUMBER                   18
#define STM32_ADC2_DMA_MSK                  (STM32_DMA_STREAM_ID_MSK(2, 1) |\
                                             STM32_DMA_STREAM_ID_MSK(2, 3))
                                             .
                                             .
                                             .


Should be:

Code: Select all

#define STM32_ADC2_DMA_MSK                  STM32_DMA_STREAM_ID_MSK(1, 2) 


.. and then, in mcuconf.h :

Code: Select all

#define STM32_ADC_ADC2_DMA_STREAM           STM32_DMA_STREAM_ID(2, 1)

should be changed to:

#define STM32_ADC_ADC2_DMA_STREAM           STM32_DMA_STREAM_ID(1, 2)

Re: STM32F3xx 2xADC with DMA Problem

Posted: Sun May 28, 2017 4:11 pm
by Giovanni
Hi,

Fixed as bug #840.

Giovanni