Report
4 days, 20 hours ago.

Sleep and deepsleep modes work differently on two equal boards

Greetings I am testing the different operating modes of a NUCLEOL476RG board with a code example. This code puts the microcontroller in the different operating modes it has in order to be able to measure (using jumper JP6) the current it consumes in each mode. The problem is that I have several boards (3) and for each I measure completely different current values. To illustrate these here are the values ​​that I get:

Expected consumption: stop1 = 6.6uA stop2 = 1.1-1.4 uA (RTC on).

Board 1: stop1 = 6.6uA stop2 = 1.4uA.

Board2: stop1 = 82uA stop2 = 82uA.

Board3: stop1= 2uA Stop2 = 2uA.

the code used is this and I used mbed-dev library instead of common mbed.h (this code can be consulted in the following link https://os.mbed.com/teams/ST/code/Nucleo_sleep/file/cef094cd4cfa/main.cpp):

include the mbed library with this snippet

#include "mbed.h"
InterruptIn event(USER_BUTTON);
DigitalOut myled(LED1);
 
int go_to_sleep = 0;
 
void pressed()
{
    printf("Button pressed\n");
    go_to_sleep = go_to_sleep + 1;
    if (go_to_sleep > 3) go_to_sleep = 0;
 
}
 
int main()
{
    int i = 0;
 
    printf("\nPress Button to enter/exit sleep & deepsleep\n");
 
    event.fall(&pressed);
 
    while (1) {
 
        if ((go_to_sleep == 0) || (go_to_sleep == 2)) {
            printf("%d: Running\n", i);
            myled = 1;
            wait(1.0);
        }
 
        if (go_to_sleep == 1) {
            myled = 0;
            printf("%d: Entering sleep (press user button to resume)\n", i);
            wait(0.1); // To let the printf finish
            sleep();
        }
 
        if (go_to_sleep == 3) {
            myled = 0;
            printf("%d: Entering deepsleep (press user button to resume)\n", i);
            wait(0.1); // To let the printf finish
            deepsleep();
        }
 
        i++;
    }
}

I have tested these boards using SW4TStm32 and with all three I get the expected values ​​instead of generated with mbed.

I used the board2 to test the consumption in shutdownmode (0,4uA) programming code with mbed mixing with HAL so I assume therefore that some register prevents board 2 going into deepsleep (and in sleep) and that register is not deleted correctly when reprograming with mbed.

include the mbed library with this snippet

#include "mbed.h"
//#include "WakeUp.h"#include "STM32L4xx_HAL_Driver.h"
#include <ctype.h>
InterruptIn event(USER_BUTTON);
DigitalOut myled(LED1);
Serial PC(D1, D0);

int go_to_sleep = 0;
bool habilitado;
void pressed()
{
    printf("Button pressed\n");
    go_to_sleep = go_to_sleep + 1;
    if (go_to_sleep > 5) go_to_sleep = 0;
    
    if(go_to_sleep==5){
    
        HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
       
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    
        HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW);
    
    }
    
}



            
int main()
{
    HAL_Init();
    SystemClock_Config();

    //PC.baud(19200);
    int i = 0;
    PC.printf("\nPress Button to enter/exit sleep & deepsleep\n");
    event.fall(&pressed);
    
    
    
    __HAL_RCC_PWR_CLK_ENABLE(); 
    HAL_PWR_EnableBkUpAccess();
    
    
    
    if (READ_REG(RTC->BKP31R) == 1)
    {
        WRITE_REG( RTC->BKP31R, 0x0 );  
        event.fall(&pressed);
    }
    
    if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF2) != RESET)
    {
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    }

  /* Initialize the User push-button to generate external interrupts */
    event.fall(&pressed);
    while (1) {
    
 
        if ((go_to_sleep == 0) || (go_to_sleep == 2)||(go_to_sleep==4)) {
            PC.printf("\n\r%d: Running\n", i);
            myled = 1;
            wait(1.0);
        }
 
        if (go_to_sleep == 1) {
            myled = 0;
            PC.printf("%d: Entering sleep (press user button to resume)\n", i);
            
            wait(0.1); // To let the printf finish
            sleep();
        }
 
        if (go_to_sleep == 3) {
            myled = 0;
            PC.printf("\n\r%d: Entering deepsleep (press user button to resume)\n", i);
            habilitado=sleep_manager_can_deep_sleep();
            PC.printf("can I deepsleep? %d)\n", habilitado);
            if(habilitado==false){
                sleep_manager_unlock_deep_sleep();
                habilitado=sleep_manager_can_deep_sleep();
                PC.printf("\n\r I couldnt but now my value is %d",habilitado);
            }
            PC.printf("\n\r%d: Entering deepsleep (press user button to resume)\n", i);
            wait(0.1); // To let the printf finish
            sleep_manager_sleep_auto();
            //deepsleep();
            
        }
        if (go_to_sleep == 5) {
            myled = 0;
            PC.printf("%d: Entering shutdown (press user button to resume)\n", i);
            wait(1); // To let the printf finish
            // Disable all used wakeup sources: WKUP pin 
            HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
            // Clear wake up Flag 
            __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
    
            // Enable wakeup pin WKUP2 
            HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW);
            // Set RTC back-up register RTC_BKP31R to indicate
            //later on that system has entered shutdown mode  
            WRITE_REG( RTC->BKP31R, 0x1 );
            //Enter shutdown mode 
            HAL_PWREx_EnterSHUTDOWNMode();
       
        }
        
        i++;
    }

}

besides i dont know why board3 has that consumption.

Does anyone know why this happens or what can I do to force the board to enter deepsleep using mbed? Thanks for helping, greetings

Comment on this question
Be the first to answer this question.

To post an answer, please log in.