Page 1 of 1

[DONE] Bug and modification in STM32F37x\adc_lld.c

Posted: Wed Mar 19, 2014 11:38 pm
by dismirlian
Hello, I've found a bug in the low level ADC driver; the bug appears only with the SDADC (present in the STM32F37x family).

Currently, the code is:

Code: Select all

#if STM32_ADC_USE_SDADC2
      ...
      rccEnableSDADC1(FALSE);
      ...
#endif /* STM32_ADC_USE_SDADC2 */

#if STM32_ADC_USE_SDADC3
      ...
      rccEnableSDADC1(FALSE);
      ...
#endif /* STM32_ADC_USE_SDADC3 */


The code enables the clocks to the incorrect SDADCs.

Also, in the same file, the function adc_lld_start_conversion does this:

Code: Select all

void adc_lld_start_conversion(ADCDriver *adcp) {
     ...

    /* Leaving initialization mode.*/
    adcp->sdadc->CR1 &= ~SDADC_CR1_INIT;

    /* SDADC conversion start, the start is performed using the method
       specified in the CR2 configuration, usually SDADC_CR2_JSWSTART.*/
    adcp->sdadc->CR2 = cr2;

    ...


In my application, the trigger is not SDADC_CR2_JSWSTART, but an external event generated by a timer (chosen with bits SDADC_CR2_JEXTSEL and SDADC_CR2_JEXTEN). Those bits can only be written if INIT = 1, so my "quick fix" was to duplicate the assignment to CR2 (note that SDADC_CR2_JSWSTART can only be written when INIT = 0). I don't know the best way to fix this issue... but here is my code:

Code: Select all

void adc_lld_start_conversion(ADCDriver *adcp) {
     ...

     adcp->sdadc->CR2 = cr2;

  /* Leaving initialization mode.*/
    adcp->sdadc->CR1 &= ~SDADC_CR1_INIT;

    /* SDADC conversion start, the start is performed using the method
       specified in the CR2 configuration, usually SDADC_CR2_JSWSTART.*/
    adcp->sdadc->CR2 = cr2;

    ...


Thanks!
Diego.

Re: Bug and modification in STM32F37x\adc_lld.c

Posted: Thu Mar 20, 2014 8:57 am
by Giovanni
Hi,

Thanks for finding, adding to the TODO list. Could you give a try to the changes after the commit?

Giovanni

Re: [TODO] Bug and modification in STM32F37x\adc_lld.c

Posted: Thu Mar 20, 2014 1:19 pm
by dismirlian
Hi Giovanni, of course, I'll give it a try after you commit the changes.

Diego.

Re: [DONE] Bug and modification in STM32F37x\adc_lld.c

Posted: Sat Mar 22, 2014 12:33 pm
by Giovanni
I just committed the changes, exactly what you suggested anyway.

Giovanni