Page 1 of 1

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

Posted: Mon Apr 28, 2025 1:34 pm
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.

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

Posted: Mon Apr 28, 2025 1:43 pm
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!

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

Posted: Thu May 15, 2025 9:27 am
by Giovanni
Hi,

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

Giovanni

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

Posted: Sun May 25, 2025 11:32 pm
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.

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

Posted: Tue Jul 01, 2025 9:41 am
by Giovanni
Hi,

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

Giovanni

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

Posted: Wed Jul 09, 2025 9:26 am
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.

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

Posted: Wed Jul 09, 2025 12:12 pm
by Giovanni
Hi,

Thanks for confirming.

Giovanni