STM32: ADCv2: do not set DDS bit in non-circular mode Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
Dron_Gus
Posts: 34
Joined: Wed Apr 22, 2020 1:03 am
Has thanked: 5 times
Been thanked: 10 times

STM32: ADCv2: do not set DDS bit in non-circular mode

Post by Dron_Gus »

While searching for solution for lost sample(s) issue (very similar to viewtopic.php?f=35&t=6439 ) I have found that current ADCv2 driver unconditionally sets DDS bit in CR2 register. While STM32F4** DS in section 13.8.1 says:
At the end of the last DMA transfer (number of transfers configured in the DMA controller’s
DMA_SxNTR register):
• No new DMA request is issued to the DMA controller if the DDS bit is cleared to 0 in the
ADC_CR2 register (this avoids generating an overrun error). However the DMA bit is
not cleared by hardware. It must be written to 0, then to 1 to start a new transfer.
• Requests can continue to be generated if the DDS bit is set to 1. This allows
configuring the DMA in double-buffer circular mode.

I think this bit should be set only if (grpp->circular).
Please see patch.

This does not solve issue in my case, but it definitely reduce ADC_SR_OVR irqs count. And may be this will allow to remove additional dmaStreamGetTransactionSize() check from ADC irq handler:

Code: Select all

  /* Note, an overflow may occur after the conversion ended before the driver
     is able to stop the ADC, this is why the DMA channel is checked too.*/
  if ((sr & ADC_SR_OVR) && (dmaStreamGetTransactionSize(ADCD1.dmastp) > 0)) {
    /* ADC overflow condition, this could happen only if the DMA is unable
       to read data fast enough.*/
    if (ADCD1.grpp != NULL)
      _adc_isr_error_code(&ADCD1, ADC_ERR_OVERFLOW);
  }


I also have two more patches for ADC/DMA. One enabling DMA's FIFO for ADC channel and other enabling DMA's FIFO error IRQ.
But I still did not fix initial issue and don't want to waste your time reviewing something that possibly makes no scene.
Attachments
0001-STM32-ADCv2-set-DDS-bit-only-in-circular-mode.zip
(1.17 KiB) Downloaded 457 times
Dron_Gus
Posts: 34
Joined: Wed Apr 22, 2020 1:03 am
Has thanked: 5 times
Been thanked: 10 times

Re: STM32: ADCv2: do not set DDS bit in non-circular mode

Post by Dron_Gus »

I just backported (yes, we still use ChibiOS 20.3) and tested patch from viewtopic.php?f=35&t=6439 and seems it solves my issue.
Thanks @pseidel!
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32: ADCv2: do not set DDS bit in non-circular mode

Post by Giovanni »

Hi,

Can this be closed? 20.x is unsupported now.

Giovanni
Dron_Gus
Posts: 34
Joined: Wed Apr 22, 2020 1:03 am
Has thanked: 5 times
Been thanked: 10 times

Re: STM32: ADCv2: do not set DDS bit in non-circular mode

Post by Dron_Gus »

Giovanni wrote:Hi,

Can this be closed? 20.x is unsupported now.

Giovanni

Hi,

Up to you. adc_lld_start_conversion at master still sets DDS bit in CR2 register unconditionally.
While DS says this bit needs to be set only in circular DMA mode. I'm not sure how critical is this.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32: ADCv2: do not set DDS bit in non-circular mode

Post by Giovanni »

Hi,

Added the change in a slightly different way (to avoid checking the "circular" condition twice), I would appreciate a confirmation.

Giovanni
Dron_Gus
Posts: 34
Joined: Wed Apr 22, 2020 1:03 am
Has thanked: 5 times
Been thanked: 10 times

Re: STM32: ADCv2: do not set DDS bit in non-circular mode

Post by Dron_Gus »

Giovanni wrote:Hi,

Added the change in a slightly different way (to avoid checking the "circular" condition twice), I would appreciate a confirmation.

Giovanni

Hi,

We have just moved RusEFI project to ChibiOS 21.11.x. No issue with ADC observed so far.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32: ADCv2: do not set DDS bit in non-circular mode

Post by Giovanni »

Hi,

Thanks for confirming.

Giovanni
Post Reply