ARMmbed / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
4.66k stars 2.97k forks source link

STM32L1: ADC after deep sleep #14475

Closed chrissnow closed 3 years ago

chrissnow commented 3 years ago

Description of defect

After deep sleeping the ADC will not function as the HSI clock is no longer enabled.

We are using the following to bring the ADC back to life

void forceAdcOutOfSleep() {
    RCC_OscInitTypeDef HSIRCC_OscInitStruct;
    HAL_RCC_GetOscConfig(&HSIRCC_OscInitStruct);
    if (HSIRCC_OscInitStruct.HSIState != RCC_HSI_ON) {
        HSIRCC_OscInitStruct.HSIState = RCC_HSI_ON;
        HSIRCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
        HSIRCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
        HAL_StatusTypeDef ret = HAL_RCC_OscConfig(&HSIRCC_OscInitStruct);
        if (ret != HAL_OK) {
            debug("HSI initialization failed - ADC will not function properly\r\n");
        }
    }
}

Target(s) affected by this defect ?

XDOT_L151CC

Toolchain(s) (name and version) displaying this defect ?

ARMC6

What version of Mbed-os are you using (tag or sha) ?

mbed-os-6.9.0

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

n/a

How is this defect reproduced ?

Enable Tickless, though it may be possible to call deep sleep directly? You should get a value the first time, then zero afterwards.

#include "mbed.h"

// Blinking rate in milliseconds
#define BLINKING_RATE     500ms

int main()
{
    // Initialise the digital pin LED1 as an output
    DigitalOut led(LED1);
    AnalogIn   ain(A0);
    AnalogIn   vref(ADC_VREF);

    while (true) {
        led = !led;

        printf("vref: 0x%04X \n", vref.read_u16());
        ThisThread::sleep_for(BLINKING_RATE);
    }
}
chrissnow commented 3 years ago

One for @jeromecoutant I think.

ciarmcom commented 3 years ago

@chrissnow thank you for raising this issue.Please take a look at the following comments:

It would help if you could also specify the versions of any tools you are using?

NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'. This indicates to us that at least all the fields have been considered. Please update the issue header with the missing information, the issue will not be mirrored to our internal defect tracking system or investigated until this has been fully resolved.

jeromecoutant commented 3 years ago

I remind that we don't recommend to enable TICKLESS for STM32L1...

chrissnow commented 3 years ago

I remind that we don't recommend to enable TICKLESS for STM32L1...

I did somewhat expect that response! any particular reason on the L1? seems to be mostly behaving itself for us.

jeromecoutant commented 3 years ago

I remind that we don't recommend to enable TICKLESS for STM32L1...

I did somewhat expect that response! any particular reason on the L1? seems to be mostly behaving itself for us.

Depending on your use case, we don't ensure a correct behaviour for targets that enables LPTICKER on top of ST RTC wakeup timer. In other words, we let you decide and verify for your application. Maybe you could have to update "lpticker_delay_ticks" value: https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json#L1237-L1240

ciarmcom commented 3 years ago

Thank you for raising this detailed GitHub issue. I am now notifying our internal issue triagers. Internal Jira reference: https://jira.arm.com/browse/IOTOSM-3737