cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure AHB and APB for STOP Mode on STM32L4?

MD'Si.1
Associate III

Hi,

I was following @Laurids_PETERSEN post on his low power ThreadX example (Part 2 ThreadX Low power Project ). 
I noticed his sample code, Snippet 11 on Enter Low Power mode configured the APB ENR, AHB ENR in RUN mode and then disabled all the peripheral clocks in the APB SMENR and AHB SMENR for STOP Mode. In previous STM32Cube examples I have never seen this being done before.

I would like to know what is recommended steps when entering low power mode. I thought I should just enable on the peripheral clocks I need to run in STOP mode e.g. if my only wakeup sources are a GPIOF pin and the RTC wakeup source then I would just enable only those peripheral clocks in STOP mode Enable register.  I have copied my enter Low Power Mode function below.

void SystemControlEnterLowPowerMode(void)
{
__HAL_RCC_PWR_CLK_ENABLE();

//Disables SRAM2 and SRAM3 retention in stop mode 2.
//Nothing is stored in SRAM2 and SRAM3
HAL_PWREx_DisableSRAM2ContentRetention();
HAL_PWREx_DisableSRAM3ContentRetention();

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOI_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
__HAL_RCC_GPIOE_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOG_CLK_DISABLE();
HAL_PWREx_DisableVddIO2();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
//__HAL_RCC_GPIOF_CLK_DISABLE(); //wakeup pin is on this port

//Enable only clocks needed during sleep mode
MODIFY_REG(RCC->AHB1SMENR, DUMMY_VALUE, RCC_AHB1SMENR_FLASHSMEN | RCC_AHB1SMENR_SRAM1SMEN );
MODIFY_REG(RCC->AHB2SMENR, DUMMY_VALUE, RCC_AHB2SMENR_GPIOFSMEN );
MODIFY_REG(RCC->AHB3SMENR, DUMMY_VALUE, 0 );
MODIFY_REG(RCC->APB1SMENR1, DUMMY_VALUE, RCC_APB1SMENR1_PWRSMEN | RCC_APB1SMENR1_RTCAPBSMEN);
MODIFY_REG(RCC->APB1SMENR2, DUMMY_VALUE, 0 );
MODIFY_REG(RCC->APB2SMENR, DUMMY_VALUE, 0 );

HAL_UART_DeInit(&hlpuart1);

/* Suspend sys ticks to avoid waking up the mcu on every interrupt */
HAL_SuspendTick();

/* Disable the Debug Module during STOP mode */
//HAL_DBGMCU_DisableDBGStopMode();

/* Enter Stop Mode */
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}

 

1 REPLY 1
Amel NASRI
ST Employee

Hi @MD'Si.1 ,

If your purpose is to understand more about low power modes in STM32L4, I suggest you look to the wiki article Getting started with PWR.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.