Author Topic: STM32L082 stop mode ADC issue (solved)  (Read 4930 times)

0 Members and 1 Guest are viewing this topic.

Offline ManulTopic starter

  • Super Contributor
  • ***
  • Posts: 1414
  • Country: lt
STM32L082 stop mode ADC issue (solved)
« on: March 07, 2022, 01:28:57 am »
Hello, guys,

I have a board with a module containing STM32L082. I have a HAL based code (yes, I know...) which is not written by me. When MCU goes to stop mode, for a while all looks good and stable, but after around 3 minutes current consumption starts fluctuating up to 3-10uA (normal is <2uA). The time until it happens varies a liitle, depends on temperature, certainly looks that the issue is caused by some leakage, drifting. If MCU wakes up, condition resets. I've checked everything around GPIO's and so on. No obvious issues. Tried setting all to analog input. Then I found that if I remove ADC initialization, the issue is solved. This striked me as weird.

I've finally isolated to this: initialization alone does not cause issue (HAL_ADC_Init). Enabling of ADC clock does not cause issue (__HAL_RCC_ADC1_CLK_ENABLE). But if the ADC peripheral is enabled by HAL_ADC_Start or in fact even a register write the issue happens and nothing can undo it. Disabling, stoping clock, even deinitialization by HAL_ADC_DeInit does not help. The next time MCU goes to stop mode, after a few minutes the weirdness starts. And if ADC was never enabled, all is good.

I've also tried manually disabling internal reference, temperature sensor, even rearranging the code thinking that maybe the issue is somewhere else and the ADC code just happens to add some delay, but it seems no. Seems that enabling the ADC peripheral affects something else, but I can not track what.

If you have ever seen something like this, whould be a great help. Could it be something regarding the MUX perhaps? Thanks.
« Last Edit: March 10, 2022, 07:52:44 pm by Manul »
 

Online wek

  • Frequent Contributor
  • **
  • Posts: 591
  • Country: sk
Re: STM32L082 stop mode ADC issue
« Reply #1 on: March 07, 2022, 09:15:05 am »
This thread describes suspiciously similar symptoms, but unfortunately no solution there.

Make sure, the ADC disable follows the guidelines in RM (AFAIK even the example code in RM was flawed in this regard). Or,  maybe better, try to reset ADC using its reset bit in RCC_APB2RSTR.

How do you set PWR_CR.ULP?  How do you set PWR_CR.LPSDSR?

Do you use LSI? LSE? CSS?

If everything fails, try to reduce code (or write from scratch) to absolute minimum but complete compilable example, which still exhibits the problem, and post.

JW
 
The following users thanked this post: Manul

Offline ManulTopic starter

  • Super Contributor
  • ***
  • Posts: 1414
  • Country: lt
Re: STM32L082 stop mode ADC issue
« Reply #2 on: March 07, 2022, 05:18:37 pm »
Thanks. Yes, that thread might be describing same issue, just mine is not so strongly expressed. Will try your suggestions. I've also got an idea to just dump all registers at two breakpoints: before and after enabling of ADC. Hopefully I can find clues by comparing these two dumps. Will post if I find something useful.
 

Offline ManulTopic starter

  • Super Contributor
  • ***
  • Posts: 1414
  • Country: lt
Re: STM32L082 stop mode ADC issue
« Reply #3 on: March 08, 2022, 12:39:53 am »
Part of that was me having a blind spot: another function disabled ADC clock, so HAL deinitialization did not work. Now deinitialization solves the problem. Except that init - deinit sequence is crude way to use hardware, so I continue to look for a decent solution.

Anyway, I've found one weird thing, ADC_CR register ADCAL bit is stuck and never gets cleared. It's stuck from the moment ADC is initialized and the only ways I've found which clears it are complete deinitialization or manually disabling the internal voltage regulator (sort of expected). In fact, if I disable the regulator and then enable it again, the issue is completely solved, because it clears the ADCAL bit. So something is messed up and the automatic calibration is misbehaving. Have suspicion that it could be clock configuration. Weirdly enough, the ADC seems to work as expected, just the bizzare issue I described in the first post.
 

Online wek

  • Frequent Contributor
  • **
  • Posts: 591
  • Country: sk
Re: STM32L082 stop mode ADC issue
« Reply #4 on: March 08, 2022, 01:27:55 pm »
> Anyway, I've found one weird thing, ADC_CR register ADCAL bit is stuck and never gets cleared.

Then your ADC startup/calibration procedure is incorrect.

The ADC in STM32 generally are very complex, and it's important to meticulously follow the procedures described in manual. See for example here.

> I continue to look for a decent solution

I personally would start with getting rid of Cube/HAL. Generally I don't recommend to use Cube/HAL to anything beyond "usual" i.e. things that can be clicked in CubeMX.

JW
 
The following users thanked this post: Manul

Offline ManulTopic starter

  • Super Contributor
  • ***
  • Posts: 1414
  • Country: lt
Re: STM32L082 stop mode ADC issue
« Reply #5 on: March 10, 2022, 07:51:33 pm »
So in the end I found, that ADC voltage regulator must be disabled (bit ADVREGEN in ADC_CR) before entering stop mode. Although, who could have guessed that this description from datasheet:

Quote
To keep power consumption low, it is important to disable the ADC voltage regulator before entering lowpower mode (LPRun, LPSleep or Stop mode).

means "random fluctuations of current, delayed by arbitrary number of minutes". If it would just draw some extra current, that would be understandable. But this obscure behaviour is really unexpected. I wonder what is happening on a circuit level.

If anyone else has such problem, a call to LL_ADC_DisableInternalRegulator before entering stop mode should solve it. Be sure ADC is disabled before that. If HAL functions are used, these enable and disable ADC automatically.
« Last Edit: March 10, 2022, 07:54:34 pm by Manul »
 

Online wek

  • Frequent Contributor
  • **
  • Posts: 591
  • Country: sk
Re: STM32L082 stop mode ADC issue (solved)
« Reply #6 on: March 10, 2022, 08:12:04 pm »
Thanks for coming back with the solution.

JW
 

Offline glinders

  • Newbie
  • Posts: 1
  • Country: nz
Re: STM32L082 stop mode ADC issue (solved)
« Reply #7 on: March 28, 2023, 06:55:19 pm »
We had the same issue on an STM32L071.

When going into STOP mode the total current would drop to less than 0.5uA. After a while, the current would ramp up to 60-100uA in a few seconds, where it would sit for several seconds or minutes or even longer before dropping to 0.5uA again.

This seemed to be completely random, independent of power supply voltage or temperature (cold-spray).

It was also fixed by calling LL_ADC_DisableInternalRegulator before entering stop mode.
 

Offline vanthome

  • Newbie
  • Posts: 7
  • Country: de
Re: STM32L082 stop mode ADC issue (solved)
« Reply #8 on: July 16, 2023, 07:57:06 pm »
Hello, I have the same issue with an STM32L071KZU6 but in my case, only
Code: [Select]
HAL_ADC_DeInit(); helps.
 

Online wek

  • Frequent Contributor
  • **
  • Posts: 591
  • Country: sk
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->