STM32G071 ADC Start

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

Moderators: RoccoMarco, barthess

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

STM32G071 ADC Start

Postby Tabulous » Sun Oct 16, 2022 7:00 pm

this loop takes for ever ?


/**
* @brief ADC voltage regulator enable.
*
* @param[in] adc pointer to the ADC registers block
*/
NOINLINE static void adc_lld_vreg_on(ADC_TypeDef *adc) {

osalDbgAssert(adc->CR == 0, "invalid register state");

#if defined(ADC_CR_ADVREGEN)
adc->CR = ADC_CR_ADVREGEN;
volatile uint32_t loop = (STM32_HCLK >> 20) << 4;
do {
loop--;
} while (loop > 0);
#else
#endif
}


#define STM32_HSIDIV_VALUE 16//1
#define STM32_HSI16_ENABLED TRUE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSI_ENABLED TRUE
#define STM32_LSE_ENABLED FALSE
#define STM32_SW STM32_SW_HSISYS//STM32_SW_PLLRCLK
#define STM32_PLLSRC STM32_PLLSRC_NOCLOCK//STM32_PLLSRC_HSI16
#define STM32_PLLM_VALUE 2
#define STM32_PLLN_VALUE 16
#define STM32_PLLP_VALUE 2
#define STM32_PLLQ_VALUE 4
#define STM32_PLLR_VALUE 2
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE STM32_PPRE_DIV1
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
#define STM32_MCOPRE STM32_MCOPRE_DIV1
#define STM32_LSCOSEL STM32_LSCOSEL_NOCLOCK

User avatar
Giovanni
Site Admin
Posts: 14462
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1078 times
Been thanked: 922 times
Contact:

Re: STM32G071 ADC Start

Postby Giovanni » Sun Oct 16, 2022 7:04 pm

Is this from latest trunk code?

Giovanni

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: STM32G071 ADC Start

Postby Tabulous » Sun Oct 16, 2022 7:07 pm

Giovanni wrote:Is this from latest trunk code?

Giovanni


#define CH_KERNEL_VERSION "7.1.0"

Downloaded it in July but looking in hal_adc_lld.c this function is still the same

User avatar
Giovanni
Site Admin
Posts: 14462
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1078 times
Been thanked: 922 times
Contact:

Re: STM32G071 ADC Start

Postby Giovanni » Sun Oct 16, 2022 7:16 pm

That is the RT version :-)

Please make sure to try the latest trunk code, Bob worked on that driver recently.

Giovanni

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: STM32G071 ADC Start

Postby Tabulous » Mon Oct 17, 2022 8:46 am

Giovanni wrote:That is the RT version :-)

Please make sure to try the latest trunk code, Bob worked on that driver recently.

Giovanni


So updated to the latest trunk and its still looping...
loop var has 4.2 billion iterations to go :o


Untitled.png

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: STM32G071 ADC Start

Postby Tabulous » Mon Oct 17, 2022 1:53 pm

changed the code below so i could see what STM32_HCLK value is.

STM32_HCLK with my settings, as above is 1000000.
Thus 1000000 >> 20 would equal zero....... so its plain to see why the loop var is 4.2billion iterations.

This code to to create a delay(datasheet tADCVREG_SETUP 20uS) based on AHB clock frequency is not good.




Code: Select all

NOINLINE static void adc_lld_vreg_on(ADC_TypeDef *adc) {

  osalDbgAssert(adc->CR == 0, "invalid register state");

#if defined(ADC_CR_ADVREGEN)
  adc->CR = ADC_CR_ADVREGEN;
  int temp = STM32_HCLK;

  volatile uint32_t loop = (temp >> 20) << 4;
  do {
    loop--;
  } while (loop > 0);
#else
#endif
}

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: STM32G071 ADC Start

Postby FXCoder » Mon Oct 17, 2022 2:16 pm

That timing loop doesn't play nicely with 1MHz (0xF4240) STM32_HCLK.
It runs out of bits in the >> 20.

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: STM32G071 ADC Start

Postby Tabulous » Mon Oct 17, 2022 2:39 pm

FXCoder wrote:That timing loop doesn't play nicely with 1MHz (0xF4240) STM32_HCLK.
It runs out of bits in the >> 20.


just for now ive hard coded it

NOINLINE static void adc_lld_vreg_on(ADC_TypeDef *adc) {

osalDbgAssert(adc->CR == 0, "invalid register state");

#if defined(ADC_CR_ADVREGEN)
adc->CR = ADC_CR_ADVREGEN;
volatile uint32_t loop = 10000;//(STM32_HCLK >> 20) << 4;
do {
loop--;
} while (loop > 0);
#else
#endif
}

User avatar
Giovanni
Site Admin
Posts: 14462
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1078 times
Been thanked: 922 times
Contact:

Re: STM32G071 ADC Start

Postby Giovanni » Mon Oct 17, 2022 3:49 pm

It needs a different expression, not a big deal.

Giovanni

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: STM32G071 ADC Start

Postby FXCoder » Tue Oct 18, 2022 2:43 am

Just OR the >> 20 result with 1 before left shift 4?


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 11 guests