cancel
Showing results for 
Search instead for 
Did you mean: 

Low Power Sleep on L011K4 does not work

TSchi.2269
Associate III

Hello,

I've made a project with an Nucleo L011K4 where the L011K4 initializes, and then should go to sleep. It should wake up when an Interrupt is received on A2-pin.

My current project is developed using the CubeMX suite. This generates standard code and some BSP functions, including the SPI connection etc. However, when I check the STM32CubeL0 repo, and when I check the examples for the L011K4, I see a Low-Power Sleep functionality.

When I try to copy the code to my existing project, and import it in my existing project, I get a lot of errors, missing functions and when I finally thought I got it succesfully imported; my firmware stopped working (initialisation was still okay, but it did not detect the interrupt anymore. Is there any easy way to put the L011K4 into sleep? I don't have a deep understanding of the whole HAL and STM32 platform (still learning). Are there any tutorials maybe?

Is there a way to input a sleep or low-power sleep into my project with relative ease, and what would the power consumption?

This is a piece of the code that I used:

while (1)
	  {
		/* Reduce the System clock to below 2 MHz */
		SystemClock_Decrease();
 
		/* Suspend Tick increment to prevent wakeup by Systick interrupt.         */
		/* Otherwise the Systick interrupt will wake up the device within 1ms     */
		/* (HAL time base).                                                       */
		HAL_SuspendTick();
 
		HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
 
		/* Resume Tick interrupt if disabled prior to Low Power Run mode entry */
		HAL_ResumeTick();
 
		/* Read interrupt source registers in polling mode (no int) */
		if(MEMSInterrupt) {
			lsm6dsox_mlc_out_get(&dev_ctx, mlc_out);
			if(mlc_out[0] == 4){
				HAL_GPIO_WritePin(D6_GPIO_Port, D6_Pin, GPIO_PIN_SET);
				/* Comment this line out if you dont want LD3 to blink */
				//HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
			}else if(mlc_out[0] == 0){
				HAL_GPIO_WritePin(D6_GPIO_Port, D6_Pin, GPIO_PIN_RESET);
				/* Comment this line out if you dont want LD3 to blink */
				//HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
			}
			MEMSInterrupt = 0;
		}
	    /* USER CODE END WHILE */
	  }

 I copied the SystemClock_Decrease() function from the example.

3 REPLIES 3
Mohamed Aymen HZAMI
ST Employee

Hello,

Can you please clarify more or you can send your code in order to reproduce the problem.

For the power consumption of all the power modes you can find them in the datasheet in section Supply current characteristics.

Thanks and Best Regards,

Mohamed Aymen.

Piranha
Chief II

> should go to sleep. It should wake up when an Interrupt is received on A2-pin.

__DSB();
__WFI();

That is for a sleep mode and any interrupt. Now, low-power sleep mode and wake-up pins are a completely different story. First you must understand what exactly do you need.

Hello @Mohamed Aymen HZAMI​ , thanks for replying.

What I want to do, is to let the L011K4 sleep until an interrupt is measured (EXTI2_3_IRQn). When the interrupt is detected, I want to check wether the mlc_out[0] is 0 or 4, turn on the light (only for debugging purposes since that is 2mA), and then go to sleep until the next interrupt.

How should I do this exactly? Based on the code, do you suggest another way to handle this? The examples given with the CubeL0 package are kind of confusing.