About low power mode , generally speaking , To achieve the effect of energy saving , Generally only STOP Mode and STANDBY pattern . however , Enter low power consumption mode and wake up some precautions , as follows :

One , Configuration related (STOP And STANDBY The settings are the same )

1, use STM32Cube activation RTC, The configuration is as follows : Remember to turn on interrupt when configuration is complete

explain : Used here RTC Clock source is LSI, According to LSI Frequency to set asynchronous
predivider value and synchronous predivider
value, To reach one second ( Above is LSI by 32.768kHz Setting of ). An alarm clock to block unnecessary dates , hour , Minutes or seconds ( set up Enable For shielding ), The above alarm clock is set to 10 When the alarm is activated ( That is, one minute activation and one interruption , Ignore date , hour , Minutes and Sub Second match ).

Two , Power consumption considerations

1, After many experiments , Summed up as not used IO Port set as analog input , Useful to MCU Of IO According to the peripheral devices MCU Level at stop . Peripheral high time ,MCU When entering the stop state , Set the output mode , High level , Set low instead ( That is, the level is consistent with the peripheral devices ).

2, Check peripheral circuit , Some drivers , Power conversion IC If enabled by software , Turn off if not required after entering stop mode , Because it has working current ; If enabled by hardware , You need to check the chip manual to see what the static working current is , If it's high , Can only modify the hardware circuit or use low consumption IC replace .

3. Are there any closed circuits around , For example, voltage acquisition , although ADC Closed , But there are losses in this voltage divider , The size generally depends on the resistance and supply voltage

4. In addition, if online debugging , After entering stop mode , Debugging disabled , See if it's true SWDIO,SWCLK Both pins are also directly set as analog inputs , Debugging is also turned off :GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,

Three , Enter low power mode and wake up

1, Required before entering low power mode

SysTick->CTRL = 0; // off timer
SysTick->VAL = 0x00; // empty val, Clear timer

because SysTick System timers belong to CM3 A peripheral in the kernel , Embedded in NUIV in . It's a 24bit Decrement counter for , The time for each count is 1/SYSCLK. When reloading the value register, see 0 When , The system timer generates an interrupt , One cycle repeat . The cumulative value is SystemCoreClock
/ 1000, So the interruption is 1ms once ( This leads to a direct wake-up MCU).


// get into STANDBY pattern

2, awaken
(1)STOP Low frequency clock is used after mode wake-up , At the same time, it will enter the alarm interrupt function , Need to interrupt the function RTC_Alarm_IRQHandler() Or interrupt callback function HAL_RTC_AlarmAEventCallback() Reconfigure clock and turn on system timing :




(2)STANDBY Mode will reset after wake-up MCU, Re execute function , So be careful not to reconfigure RTC Clock . because STANDBY Mode will reset after wake-up , So enter STANDBY The pattern is the same as above , However, it is not necessary to reconfigure the clock and turn on the system timing after wake-up ( Because the new execution from the main function is equivalent to the configuration ).
(3) Reset or power on Precautions

Power on or reset can use the value of the backup area register to be protected to determine whether it has been configured RTC, If configured , No need to configure again , No configuration , It should be configured .

HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1, 0xA5A5);

If(HAL_RTCEx_BKUPRead(&hrtc,RTC_BKP_DR1) != 0xA5A5) // Judged as not configured RTC

RTC_Config();// Reconfigure RTC, This function needs to be written by yourself
Four , Reading time and timing of realizing any time 1, Read time stay rtc.c Time and date structure defined in RTC_DateTypeDef

RTC_TimeTypeDef stimestructure;
Read time and date in main function and print HAL_RTC_GetTime(&hrtc,
&stimestructure, RTC_FORMAT_BIN);
/* Get the RTC current
Date */
&sdatestructure, RTC_FORMAT_BIN);
/* Display date Format :
yy/mm/dd */

printf("%02d/%02d/%02d\r\n",2000 + sdatestructure.Year,
sdatestructure.Month, sdatestructure.Date);

/* Display time
Format : hh:mm:ss */
stimestructure.Minutes, stimestructure.Seconds);

2, Realize any second timing Set as above to wake up only when matching seconds , In fact 1 Wake up every minute , To wake up in any second, you only need to reconfigure the alarm clock at each wake-up or before entering the low power consumption mode .
Read the current clock first , Take its second , Then set the second of the alarm as current +10s( there 10 It's an example )

HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN);

stimestructure.Seconds = stimestructure.Seconds+10;

HAL_RTC_SetAlarm(&hrtc, &sAlarm, RTC_FORMAT_BIN);

©2019-2020 Toolsou All rights reserved,
JAVA Detailed explanation of anomalies MySQL An interview is a must ! How to use it quickly html and css Write static page R Language cluster analysis case Dialogue between apple and Nissan suspended ,Apple Car How's it going ?java Realize the function of grabbing red packets SpringBoot practice ( five ):mybatis-plus In BaseMapper,Iservice and ServiceImpl Google says home office affects work efficiency !2021 Return to offline office in 2010 about keras use fit_generator Encountered in StopIteration Programmer Tanabata Valentine's Day confession code