cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107 can't correctly wakeup from standby mode

ASerg.1
Associate

I'm trying to use the standby mode of STM32F and waking it up by WKUP (PA0) pin.

Going to standby seems OK, power consumption goes to 4 uA.

If I reset MCU with RESET pin, it starts normally: after 250 ms delay it goes to sleep and consumes 4 uA

https://i.stack.imgur.com/nDM6f.png

But if I wake it up with WKUP pin it behaves strangely: consumption stays on a "run" level and I see cycles off my 250 delay, MCU keeps restarting instead of going to sleep.

https://i.stack.imgur.com/KYPqM.png

My code is really simple:

#include <stm32f1xx_hal.h>
 
 
#ifdef __cplusplus
extern "C"
#endif
void SysTick_Handler(void)
{
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
}
 
void Error_Handler()
{
	__asm("bkpt 255");
	__asm("bx lr");
}
 
void SystemClock_Config(void)
{
	RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
	RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
 
	__HAL_RCC_AFIO_CLK_ENABLE();
	__HAL_RCC_PWR_CLK_ENABLE();
	
	/** Initializes the RCC Oscillators according to the specified parameters
	* in the RCC_OscInitTypeDef structure.
	*/
	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
	RCC_OscInitStruct.HSIState = RCC_HSI_ON;
	RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
	RCC_OscInitStruct.LSIState = RCC_LSI_ON;
	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
	RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL_NONE;
	if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
	{
		Error_Handler();
	}
	/** Initializes the CPU, AHB and APB buses clocks
	*/
	RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
	              | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
	RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
	RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
	RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
	RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
	if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
	{
		Error_Handler();
	}
 
	/** Configure the Systick interrupt time
	*/
	__HAL_RCC_PLLI2S_ENABLE();
}
 
int main(void)
{
	HAL_Init();
	
	SystemClock_Config();
 
	__HAL_AFIO_REMAP_SWJ_NOJTAG();
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
 
	HAL_Delay(250);
	
	HAL_PWR_EnterSTANDBYMode();	
}

1 ACCEPTED SOLUTION

Accepted Solutions
ASerg.1
Associate

Found a solution in errata sheet and with a help of the internet:

int main(void)
{
	HAL_Init();
	
	SystemClock_Config();
 
	__HAL_AFIO_REMAP_SWJ_NOJTAG();
	HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
	
	PWR->CR |= PWR_CR_CWUF;
	if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
		/* System resumed from STANDBY mode */
		__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); 
		/* Clear StandBy flag */
		__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); 
		/* Clear Wakeup flag */
	}
	
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
 
	HAL_Delay(250);
	
	HAL_PWR_EnterSTANDBYMode();	
}

View solution in original post

1 REPLY 1
ASerg.1
Associate

Found a solution in errata sheet and with a help of the internet:

int main(void)
{
	HAL_Init();
	
	SystemClock_Config();
 
	__HAL_AFIO_REMAP_SWJ_NOJTAG();
	HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
	
	PWR->CR |= PWR_CR_CWUF;
	if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
		/* System resumed from STANDBY mode */
		__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); 
		/* Clear StandBy flag */
		__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); 
		/* Clear Wakeup flag */
	}
	
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
 
	HAL_Delay(250);
	
	HAL_PWR_EnterSTANDBYMode();	
}