STM32G071 ADC resolution is always 12 bits Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
dmene
Posts: 14
Joined: Mon Nov 23, 2015 6:38 pm
Been thanked: 4 times

STM32G071 ADC resolution is always 12 bits

Post by dmene »

Hello,
I am doing tests with the ADC of the STM32G071 and it is not possible to change the
resolution is always 12 bits.

.cfgr1 = ADC_CFGR1_RES_10BIT |
ADC_CFGR1_EXTEN_RISING |
ADC_CFGR1_EXTSEL_SRC(5),
Daniel
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32G071 ADC resolution is always 12 bits

Post by Giovanni »

Hi,

The driver does not enforce 12 bits, is the value of the CFGR1 register what you expect after starting the conversion? perhaps that setting is not reaching the ADC for some reason.

Giovanni
dmene
Posts: 14
Joined: Mon Nov 23, 2015 6:38 pm
Been thanked: 4 times

Re: STM32G071 ADC resolution is always 12 bits

Post by dmene »

yes, the setting does not reach the ADC, regardless of the setting, bits 3 and 4 of CFGR1 remain at 0.

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

Re: STM32G071 ADC resolution is always 12 bits

Post by Giovanni »

Hi,

Is that structure actually passed to adcStartConversion() ? please try to step into adc_lld_start_conversion() until the register is actually written (line 311), please check the value there.

Giovanni
dmene
Posts: 14
Joined: Mon Nov 23, 2015 6:38 pm
Been thanked: 4 times

Re: STM32G071 ADC resolution is always 12 bits

Post by dmene »

const ADCConversionGroup adcgrpcfg1 =
{
.circular = true,
.num_channels = ADC_GRP1_NUM_CHANNELS,
.end_cb = adcCallback, // NULL,
.error_cb = adcErrorCallback,
.cfgr1 = ADC_CFGR1_RES_12BIT |
ADC_CFGR1_EXTEN_RISING |
ADC_CFGR1_EXTSEL_SRC(5),
.cfgr2 = 0xCD,
....
}

adcStartConversion(&ADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH);

CFGR1 0x00000543
CFGR2 0x000000CD

Daniel
dmene
Posts: 14
Joined: Mon Nov 23, 2015 6:38 pm
Been thanked: 4 times

Re: STM32G071 ADC resolution is always 12 bits

Post by dmene »

Sori,
.cfgr1 = ADC_CFGR1_RES_10BIT |

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

Re: STM32G071 ADC resolution is always 12 bits

Post by Giovanni »

I am trying to understand if the driver writes the correct value and it is not "taken" by the CFGR1 register. What is the value of the "cfgr1" variable just before it is written in the register?

Code: Select all

  /* ADC configuration and start.*/
  adcp->adc->CFGR1  = cfgr1;


There are 2 cases:
1) The variable has the correct value and it is not latched into the register for some HW reason, then OK, we need to understand why.
2) The variable itself has a wrong value, this could be a SW bug in the driver somewhere (but I don't see anything in the code right now).

Debugging should be easier compiling with -O0 or optimizations could fool the debugger.

Giovanni
dmene
Posts: 14
Joined: Mon Nov 23, 2015 6:38 pm
Been thanked: 4 times

Re: STM32G071 ADC resolution is always 12 bits

Post by dmene »

Hi,

The cfgr1 variable has an incorrect value.
I defined a variable:
uint32_t CFGR1x;

/* ADC configuration and start.*/
adcp->adc->CFGR1 = cfgr1;
CFGR1x = cfgr1;

Then the value of CFGR1x is 0x00000543 (it should be 0x0000054B)

Daniel
dmene
Posts: 14
Joined: Mon Nov 23, 2015 6:38 pm
Been thanked: 4 times

Re: STM32G071 ADC resolution is always 12 bits

Post by dmene »

Hi,

I did this test, something is writing in the structure.

uint32_t CFGR1x, CFGR1y, CFGR1z;

/* ADC configuration and start.*/
CFGR1x = ADC_CFGR1_RES_10BIT | ADC_CFGR1_EXTEN_RISING | ADC_CFGR1_EXTSEL_SRC(5) | ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG ;
adcp->adc->CFGR1 = CFGR1x; // cfgr1;
CFGR1y = adcp->adc->CFGR1;
CFGR1z = CFGR1x;

CFGR1x 0x0000054B
CFGR1y 0x00000543
CFGR1z 0x0000054B

Daniel
psyco
Posts: 21
Joined: Fri May 22, 2020 1:40 am
Been thanked: 11 times

Re: STM32G071 ADC resolution is always 12 bits

Post by psyco »

This appears to be an errata. See ES0418 2.6.2, "Writing ADC_CFGR1 register while ADEN bit is set resets RES[1:0] bitfield".
Post Reply