STM32F3xx 2xADC with DMA Problem Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
relsys
Posts: 4
Joined: Wed May 10, 2017 1:17 pm

STM32F3xx 2xADC with DMA Problem

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F3xx 2xADC with DMA Problem

Post by Giovanni »

Hi,

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

Giovanni
relsys
Posts: 4
Joined: Wed May 10, 2017 1:17 pm

Re: STM32F3xx 2xADC with DMA Problem

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F3xx 2xADC with DMA Problem

Post by Giovanni »

Moving this in "bug reports".

Which device are you using exactly? F303?

Giovanni
relsys
Posts: 4
Joined: Wed May 10, 2017 1:17 pm

Re: STM32F3xx 2xADC with DMA Problem

Post 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
troepman
Posts: 2
Joined: Tue May 16, 2017 3:10 pm
Been thanked: 1 time

Re: STM32F3xx 2xADC with DMA Problem

Post 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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F3xx 2xADC with DMA Problem

Post by Giovanni »

Thanks for reports, I will fix this during weekend.

Giovanni
relsys
Posts: 4
Joined: Wed May 10, 2017 1:17 pm

Re: STM32F3xx 2xADC with DMA Problem

Post 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)
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F3xx 2xADC with DMA Problem

Post by Giovanni »

Hi,

Fixed as bug #840.

Giovanni
Post Reply