STM32L082 stop mode ADC issue (solved) - Page 1
Forum section: electronics / general

author: Manul
author_rank: Super Contributor
timestamp: March 07, 2022, 01:28:57 am
content: 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 andnothing 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.

author: wek
author_rank: Frequent Contributor
timestamp: March 07, 2022, 09:15:05 am
content: This threaddescribes 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

author: Manul
author_rank: Super Contributor
timestamp: March 07, 2022, 05:18:37 pm
content: 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.

author: Manul
author_rank: Super Contributor
timestamp: March 08, 2022, 12:39:53 am
content: 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.

author: wek
author_rank: Frequent Contributor
timestamp: March 08, 2022, 01:27:55 pm
content: > 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 examplehere.> I continue to look for a decent solutionI 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

author: Manul
author_rank: Super Contributor
timestamp: March 10, 2022, 07:51:33 pm
content: 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:Quotemeans "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.

author: wek
author_rank: Frequent Contributor
timestamp: March 10, 2022, 08:12:04 pm
content: Thanks for coming back with the solution.JW

author: glinders
author_rank: Newbie
timestamp: March 28, 2023, 06:55:19 pm
content: 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 callingLL_ADC_DisableInternalRegulatorbefore entering stop mode.

author: vanthome
author_rank: Newbie
timestamp: July 16, 2023, 07:57:06 pm
content: Hello, I have the same issue with an STM32L071KZU6 but in my case, onlyCode:HAL_ADC_DeInit();helps.

author: wek
author_rank: Frequent Contributor
timestamp: July 17, 2023, 08:35:30 am
content: Maybe related?https://community.st.com/t5/stm32-mcu-products/stm32l010k8-on-off-adc-vrefint-in-low-power-run-mode/m-p/573421#M218289JW