cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L071CB Ultra Low Power issue with LL libraries

DPast.1
Associate II

Hello,

I'm trying to get my STML071CB down to the lowest possible current, but can't seem to get to the low levels provided int he datasheets with my own code. I'm using the LL libraries and am going into STOP mode using the following code:

	LL_PWR_EnableUltraLowPower();
	LL_PWR_ClearFlag_WU();
	LL_PWR_SetRegulModeLP(LL_PWR_REGU_LPMODES_LOW_POWER);
	LL_PWR_SetPowerMode(LL_PWR_MODE_STOP);
	LL_LPM_EnableDeepSleep();
	__WFI();
	LL_PWR_ExitLowPowerRunMode();
	LL_PWR_DisableUltraLowPower();
	return Status_Ok;

However, I can't get down to the same low levels as I can using the HAL library and just calling the HAL stop command. So far as I can tell I'm doing the exact same thing, but there seems to be something I'm missing.

My LL code is configuring the USART2, 4, 5 and also the RTC, but I'm deinitializing them all before calling stop, turning off interrupts and the peripherals as well.

My clocks are initialized like so:

	LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
	while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)
	{
	}
 
	LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
	LL_RCC_MSI_Enable();
	while (LL_RCC_MSI_IsReady() != 1)
	{
	}
	LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6);
	LL_RCC_MSI_SetCalibTrimming(0);
 
	LL_RCC_LSI_Enable();
	while (LL_RCC_LSI_IsReady() != 1)
	{
	}
 
	LL_PWR_EnableBkUpAccess();
	LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
	if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSI)
	{
		LL_RCC_ForceBackupDomainReset();
		LL_RCC_ReleaseBackupDomainReset();
		LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
	}
	LL_RCC_EnableRTC();
 
	LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
	LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
	LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
 
	LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_MSI);
	while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_MSI)
	{
 
	}
	LL_SetSystemCoreClock(4194000);
	LL_RCC_SetUSARTClockSource(LL_RCC_USART2_CLKSOURCE_PCLK1);
 
	if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
	{
		return Status_Failed;
	}
	return Status_Ok;

I've been stuck on this for a couple days and can't figure out what the difference is between the HAL code and mine, just from inspecting the HAL libraries.

Any insight on what I might be missing would be appreciated.

2 REPLIES 2

Simplify your code by removing all parts not related to low power. Try if you can achieve the low power state, then graduallu add back what removed, to find your what was the source of problems.

JW

DPast.1
Associate II

Thanks JW, I'll give that a shot, that's a good idea.