cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152RE +CubeMX+Stop Mode+FreeRTOS

Soham Jani
Associate II
Posted on February 27, 2018 at 23:57

I'm trying to put the Nucleo-152re dev board into stop-mode, when there are no tasks running. It successfully enters the stop mode(i think) but the current consumption is 150uA. I have read in the manual that it should consume only 1.5uA and confirmed that it drops around that when running the 'PWR_STOP' example included in the STM32CubeL1 HAL library. 

I use the FreeRTOS pre and post sleep processing to put it to sleep. The task is woken up from suspended state when an external interrupt occurs. 

Please help spot the mistake, I know I must be forgetting a step. 

My configuration is -- running on board LSE , with HSI at 16Mhz while the other peripherals are at 8Mhz.    

Here are all the relevant functions --  (Also attached the main file)

void PreSleepProcessing(uint32_t *ulExpectedIdleTime)

{

// place for user code

*ulExpectedIdleTime = 0;

//HAL_UART_DeInit(&huart2);

// Disable the Power Voltage Detector

HAL_PWR_DisablePVD( );

// Enable Ultra low power mode

HAL_PWREx_EnableUltraLowPower( );

// Enable the fast wake up from Ultra low power mode

//HAL_PWREx_EnableFastWakeUp( );

//Enter to sleep Mode using the HAL function HAL_PWR_EnterSLEEPMode with WFI instruction

// HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

HAL_PWR_EnterSTOPMode( PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI );

//HAL_PWR_EnterSTANDBYMode();

}

void PostSleepProcessing(uint32_t *ulExpectedIdleTime)

{

// Enable Power Control clock

__HAL_RCC_PWR_CLK_ENABLE();

SystemClock_Config();

MX_GPIO_Init();

}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

/* Prevent unused argument(s) compilation warning */

UNUSED(GPIO_Pin);

xTaskResumeFromISR(defaultTaskHandle);

/* NOTE : This function Should not be modified, when the callback is needed,

the HAL_GPIO_EXTI_Callback could be implemented in the user file

*/

}

/* USER CODE END 4 */

/* StartDefaultTask function */

void StartDefaultTask(void const * argument)

{

/* USER CODE BEGIN 5 */

/* Infinite loop */

for(;;)

{

HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);

for(uint16_t i =0; i<1000; i++);

HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);

//vTaskDelay(100);

vTaskSuspend(NULL);

}

/* USER CODE END 5 */

}

Thanks!!

#stm32l-stop-mode #nucleo-l152re #freertos+hal
2 REPLIES 2
ab val
Associate III
Posted on February 28, 2018 at 09:01

Did you correctly set up the unused pin to Analog input, Call the appropriate Msp_DeInit(), disable the clocks?

Posted on February 28, 2018 at 16:15

Hello Ab,

CubeMX generates the code which sets all the pins to Analog, and I call the '__HAL_RCC_GPIOB_CLK_DISABLE()' to stop all the clocks before sleep.