STM32CubeMX Series|Wake on Standby

Standby wake

1. Introduction to Low Power Mode

After the system or power supply is reset, the microprocessor is in the running state, HCLK provides the clock for the CPU in the running state, and the kernel executes the program code. When the CPU does not need to continue running (for example, waiting for an external event), multiple low-power modes can be used to save power. The user needs to select an optimal low-power mode based on the lowest power consumption, fastest startup time, and available wake-up sources. STM32 provides three low power consumption modes to achieve different levels of power consumption reduction:

  • Sleep mode (CM3 core stops working, peripherals are still running) (highest power consumption)
  • Stop mode (all clocks are stopped) (typical current consumption is about 20uA)
  • Standby mode (1.8V core power is off) (minimum current consumption is about 2uA)

In running mode, power consumption can also be reduced by the following methods:

  • Reduce the system clock
  • Turn off the clocks of unused peripherals on the APB and AHB buses

Insert picture description here

This experiment only introduces STM32's lowest power consumption mode (ie standby mode). Standby mode can achieve the lowest power consumption of STM32. This mode turns off the voltage regulator in CM3 deep sleep mode, the entire 1.8V power supply area is powered off, the PLL/HSI/HSE oscillator is also powered off, and the SRAM and register contents are lost. Only the backup registers and standby circuit maintain power supply. The
following figure shows the conditions for STM32 to enter and exit standby mode:

Insert picture description here

2. Hardware design

In this experiment, the D1 indicator light is used to indicate that the system is running normally. The indicator light is off to indicate that it enters the standby mode. The K_UP button is used to wake up the standby mode and use the serial port 1 to print related debugging information.

  • D1 indicator
  • K_UP button
  • USART1 serial port

3. Software design

3.1 STM32CubeMX settings
  • RCC set external HSE, clock is set to 72M
  • PC0 is set to GPIO push-pull output mode, pull-up, high-speed, and the default output level is high
  • PA0 is set to GPIO pull-down input mode
  • USART1 is selected as the asynchronous communication mode, the baud rate is set to 115200Bits/s, the transmission data length is 8Bit, no parity, 1 stop bit

Insert picture description here

  • Enter the project name, select the project path (no Chinese), select MDK-ARM V5; check Generated periphera initialization as a pair of'.c/.h' files per IP; click GENERATE CODE to generate the project code
3.2 MDK-ARM programming
  • Add a function to enter standby mode in the main.c file
/* USER CODE BEGIN 4 */
void Sys_Enter_Standby(void){
    
    
	__HAL_RCC_PWR_CLK_ENABLE();		//使能PWR时钟
	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);		//清除Wake_UP标志
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);	//设置WAKEUP用于唤醒
	HAL_PWR_EnterSTANDBYMode();		//进入待机模式
}
/* USER CODE END 4 */
  • Add the following test program in the while loop of the main function
while (1){
    
    
	printf("Time: 5\r\n");
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,GPIO_PIN_RESET);		
	HAL_Delay(1000);
		
	printf("Time: 4\r\n");
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,GPIO_PIN_SET);		
	HAL_Delay(1000);

	printf("Time: 3\r\n");
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,GPIO_PIN_RESET);		
	HAL_Delay(1000);

	printf("Time: 2\r\n");
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,GPIO_PIN_SET);		
	HAL_Delay(1000);

	printf("Time: 1\r\n");
	HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,GPIO_PIN_RESET);		
	HAL_Delay(1000);

	printf("Entered Standby Mode...Please press KEY_UP to wakeup system!\r\n");
	Sys_Enter_Standby();
}

4. Download verification

After the compilation is correct, download it to the development board, you can see that the D1 indicator flashes continuously when the system is running, and enters the standby mode after 5 seconds, at which time the D1 indicator is off. When the KEY_UP button or the reset button is pressed, the standby mode is awakened, the system restarts, and the serial port prints a prompt message
Insert picture description here

Guess you like

Origin blog.csdn.net/Chuangke_Andy/article/details/108734308