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

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
dismirlian
Posts: 65
Joined: Fri Dec 20, 2013 3:59 pm
Has thanked: 1 time
Been thanked: 16 times

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

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

Re: Bug and modification in STM32F37x\adc_lld.c

Post by Giovanni »

Hi,

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

Giovanni
dismirlian
Posts: 65
Joined: Fri Dec 20, 2013 3:59 pm
Has thanked: 1 time
Been thanked: 16 times

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

Post by dismirlian »

Hi Giovanni, of course, I'll give it a try after you commit the changes.

Diego.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post by Giovanni »

I just committed the changes, exactly what you suggested anyway.

Giovanni
Post Reply