[ADCv3] Possible copy-paste error in hal_adc_lld.c for ADC5 clock mask Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

[ADCv3] Possible copy-paste error in hal_adc_lld.c for ADC5 clock mask

Post by alexblack »

Hi.
I am using the current stable 21.11.4 branch. In the ADCv3 driver file hal_adc_lld.c, there seems to be a copy-paste error regarding the clock mask (clkmask) for ADC5.
It appears that the bit shift corresponds to the ADC index (ADC3=bit2, ADC4=bit3, ADC5=bit4), but for ADC5, the code sets and resets bit 3 (which belongs to ADC4).
Here are the suspicious lines:

Code: Select all

775 #if STM32_ADC_USE_ADC5
776     if (&ADCD5 == adcp) {
777       adcp->dmastp = dmaStreamAllocI(STM32_ADC_ADC5_DMA_STREAM,
778                                      STM32_ADC_ADC5_DMA_IRQ_PRIORITY,
779                                      (stm32_dmaisr_t)adc_lld_serve_dma_interrupt,
780                                      (void *)adcp);
781       osalDbgAssert(adcp->dmastp != NULL, "unable to allocate stream");
782 
783       clkmask |= (1 << 3); // >>> Should be (1 << 4)

Code: Select all

865 #if STM32_ADC_USE_ADC5
866     if (&ADCD5 == adcp) {
867       clkmask &= ~(1 << 3); // >>> Should be ~(1 << 4)
868     }
#endif

Code: Select all

904 #if STM32_HAS_ADC3 || STM32_HAS_ADC4 || STM32_HAS_ADC5
905     if ((clkmask & 0xC) == 0) { // >>> Should be (0x1C) to include bit 4
906       rccDisableADC345();
907     }
#endif
Unlike ADC1-ADC4, the ADC5 block is missing the frequency check:

Code: Select all

775 #if STM32_ADC_USE_ADC5
776     if (&ADCD5 == adcp) {
  // Missing:
  // osalDbgAssert(STM32_ADC5_CLOCK <= STM32_ADCCLK_MAX, "invalid clock frequency");
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [ADCv3] Possible copy-paste error in hal_adc_lld.c for ADC5 clock mask

Post by Giovanni »

Hi,

Fixes committed, thanks.

Giovanni
Post Reply