2012-11-07 08:33 AM
Hi,
I'm working wih STM32L152 evaluation board, and i'm trying to make the MCU to enter stop mode. Though it seems like the MCU is stoping, I'm still woried about two things: 1. The MCU's current consumption is about 600uA (instead of around 1uA). 2. I've enabled the MCO, and I see that in stop mode the MSI is still running (and connected to the sysclk). According to the reference manual, it is suppose to stop in this mode. Am I doing something wrong? Thanks a lot, Amir #stop-mode-stm32l2012-11-07 09:44 AM
Am I doing something wrong?
Quite possibly, although you're basically asking us to guess what you've done wrong. Suggest you examine how your code differs from the examples, and projects on the STM32L-Discovery board, etc.2015-04-25 05:12 PM
I know this is an old thread, but I'm experiencing the same problem. I have a circuit with a stm32l152,and no matter what I do I can't get it to draw less than 400uA in stop mode. In Standby it goes down very low.
I can also confirm that no matter what I do the systick interrupt will keep firing during stop mode (I keep it in a loop until the wake isr is handled)I use Atollic with a segger, and I suspect that something in the build process/start-up script is setting some sort of debug flag... I have tried to implement every trick in the forums regarding low power stop mode. I have also run the stop mode example of both the CUBEMX and legacy peripheral libraries on the stm32l100 discovery, with no success. Anyone got any ideas? I have tried to clear the DBGMCU bit as this seems the most obvious solution, but no luck.2015-04-28 04:48 AM
Here is the code I used (slightly abreviated) this code uses the new CubeMX HAL drivers, but nothing much has changed. The only code that is not shown is the RTC setup which is configured to generate an auto-wake interrupt.
/* Includes ------------------------------------------------------------------*/
#include ''Global_Variables.h''
/* local variables -----------------------------------------------------------*/
uint8_t wake_flag = 0;
/* Private function prototypes -----------------------------------------------*/
void
SystemClock_Config(
void
);
static
void
SystemPower_Config(
void
);
static
void
SystemClockConfig_STOP(
void
);
static
void
SystemClockConfig_WAKE(
void
);
void
Sleep();
/* MAIN process */
int
main(
void
)
{
int
loopcounter = 0;
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
MX_RTC_Init();
/* Configure the system Power */
SystemPower_Config();
LEDInit(&LED1);
SetLed(&LED1, Off, 0);
while
(
true
)
{
loopcounter++;
Sleep();
SetLed(&LED1, Red, 0);
Delay(200);
SetLed(&LED1, Off, 0);
}
}
/**
* @brief RTC Wake Up callback
* @param None
* @retval None
*/
void
HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
/* Clear Wake Up Flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
wake_flag = 1;
}
/**
* @brief System Power Configuration
* The system Power is configured as follow :
* + Regulator in LP mode
* + VREFINT OFF, with fast wakeup enabled
* + HSI as SysClk after Wake Up
* + No IWDG
* + Automatic Wakeup using RTC clocked by LSI (after ~4s)
* @param None
* @retval None
*/
static
void
SystemPower_Config(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure =
{ 0 };
FLASH_OBProgramInitTypeDef pOBInit;
#ifdef DEBUG
HAL_DisableDBGStopMode();
HAL_DisableDBGSleepMode();
HAL_DisableDBGStandbyMode();
#else
HAL_DisableDBGStopMode();
HAL_DisableDBGSleepMode();
HAL_DisableDBGStandbyMode();
#endif
/* Select the desired V(BOR) Level ---------------------------------------*/
HAL_FLASHEx_OBGetConfig(&pOBInit);
if
(pOBInit.BORLevel != OB_BOR_OFF)
{
pOBInit.OptionType = OPTIONBYTE_BOR;
pOBInit.BORLevel = OB_BOR_OFF;
HAL_FLASH_OB_Unlock();
HAL_FLASHEx_OBProgram(&pOBInit);
/* Launch the option byte loading. This will reset the processor */
HAL_FLASH_OB_Launch();
}
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower();
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_DisableFastWakeUp();
// disable power voltage detector
HAL_PWR_DisablePVD();
/* Enable GPIOs clock */
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__GPIOC_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__GPIOH_CLK_ENABLE();
/* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */
GPIO_InitStructure.Pin = GPIO_PIN_All;
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
HAL_GPIO_Init(GPIOH, &GPIO_InitStructure);
/* Disable GPIOs clock */
__GPIOA_CLK_DISABLE();
__GPIOB_CLK_DISABLE();
__GPIOC_CLK_DISABLE();
__GPIOD_CLK_DISABLE();
__GPIOH_CLK_DISABLE();
}
/**
* @brief Configures system clock before STOP: disable HSI, MSI, PLL
* @param None
* @retval None
*/
static
void
SystemClockConfig_STOP(
void
)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
/* Enable Power Control clock */
__PWR_CLK_ENABLE();
/* Get the Oscillators configuration according to the internal RCC registers */
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
/* Select MSI as system clock source and configure the HCLK, PCLK1 and PCLK2 */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
assert_param(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK);
// /* To go into stop mode, turn off HSI and PLL*/
// RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
// RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
// RCC_OscInitStruct.LSEState = RCC_LSE_ON;
// RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
// RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
// RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
// RCC_OscInitStruct.MSIState = RCC_MSI_ON;
// RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
// RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
// RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF;
// RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
// assert_param(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK);
/* Reduce voltage scaling to optimise the power consumption*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
/* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
// while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET)
// {
// };
}
/**
* @brief Configures system clock after wake-up from STOP: enable HSI, PLL
* and select PLL as system clock source.
* @param None
* @retval None
*/
static
void
SystemClockConfig_WAKE(
void
)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
/* Enable Power Control clock */
__PWR_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
while
(__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET)
{
};
/* Get the Oscillators configuration according to the internal RCC registers */
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
/* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
assert_param(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK);
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
assert_param(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK);
}
/** System Clock Configuration
*/
void
SystemClock_Config(
void
)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
__PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
__SYSCFG_CLK_ENABLE();
}
void
Sleep()
{
uint32_t loopcounter = 0;
///// disable all unnecessary interrupts
HAL_NVIC_DisableIRQ(CC_GDO_IRQ_Channel);
///// Disable peripherals
///// configure clocks for low power
SystemClockConfig_STOP();
///// stop the systic ISR
HAL_SuspendTick();
//////////////////////////////////////////////////////////////////////////////////
/* Enter Stop Mode */
wake_flag = 0;
while
(wake_flag == 0)
{
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
loopcounter++;
}
//////////////////////////////////////////////////////////////////////////////////
///// start the systic ISR
HAL_ResumeTick();
/* Configures system clock after wake-up from STOP: enable HSI, PLL */
SystemClockConfig_WAKE();
}
2015-05-04 01:21 AM
Does anyone have anything to contribute? I'm desperate here... I can't seem to get any board to run properly in STOP mode.