cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151 Problem do not run some function after wake up

Hoang Loc
Associate II

Hi Community, my application use FreeRTOS work fine when i did not use PWR_EnterSTANDBYMode. The problem is the program did not run some function like skip function after wake up, For instance: usart2_init, delay.. when I debug and put the break point at that function. The program work properly. Please help me.

I use StdPeriph_Driver library and use stm32f1 before, I am new in using stm32L1xx

3 REPLIES 3

You have to turn on the clocks again

STM32L1xx_StdPeriph_Lib_V1.3.1\Project\STM32L1xx_StdPeriph_Examples\PWR\STOP\main.c

...
    /* Enable Wakeup Counter */
    RTC_WakeUpCmd(ENABLE);
 
    /* Enter Stop Mode */
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
 
// Sometime later... (in Spongebob announcer voice)
 
    /* Disable Wakeup Counter */
    RTC_WakeUpCmd(DISABLE);
 
    /* After wake-up from STOP reconfigure the system clock */
    /* Enable HSE */
    RCC_HSEConfig(RCC_HSE_ON);
 
    /* Wait till HSE is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)
    {}
 
    /* Enable PLL */
    RCC_PLLCmd(ENABLE);
 
    /* Wait till PLL is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {}
 
    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
 
    /* Wait till PLL is used as system clock source */
    while (RCC_GetSYSCLKSource() != 0x0C)
    {}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I use PWR_EnterSTANDBYMode not PWR_EnterSTOPMode, I test and find out that my stm32l is reset on wake up(run from begin app). I also initial clock to 32Mhz after wake up. I also try insert this code but has not change. Thanks for reply

/* Disable Wakeup Counter */
    RTC_WakeUpCmd(DISABLE);

This is my function to initial RCC.

ErrorStatus HSEStartUpStatus;
	/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
	/* RCC system reset(for debug purpose) */
	RCC_DeInit();
	/* Enable HSE */
	RCC_HSEConfig(RCC_HSE_ON);
	/* Wait till HSE is ready */
	HSEStartUpStatus = RCC_WaitForHSEStartUp();
	if (HSEStartUpStatus == SUCCESS)
	{
		 /* Enable 64-bit access */
		FLASH->ACR |= FLASH_ACR_ACC64;
 
		/* Enable Prefetch Buffer */
		FLASH->ACR |= FLASH_ACR_PRFTEN;
 
		/* Flash 1 wait state */
		FLASH->ACR |= FLASH_ACR_LATENCY;
 
		/* Power enable */
		RCC->APB1ENR |= RCC_APB1ENR_PWREN;
 
		/* Select the Voltage Range 1 (1.8 V) */
		PWR->CR = PWR_CR_VOS_0;
 
		/* Wait Until the Voltage Regulator is ready */
		while((PWR->CSR & PWR_CSR_VOSF) != RESET)
		{
		}
 
		/* HCLK = SYSCLK /1*/
		RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
 
		/* PCLK2 = HCLK /1*/
		RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
 
		/* PCLK1 = HCLK /1*/
		RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
 
		/*  PLL configuration */
		RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL |
											RCC_CFGR_PLLDIV));
		RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMUL12 | RCC_CFGR_PLLDIV3);
 
		/* Enable PLL */
		RCC->CR |= RCC_CR_PLLON;
 
		/* Wait till PLL is ready */
		while((RCC->CR & RCC_CR_PLLRDY) == 0)
		{
		}
 
		/* Select PLL as system clock source */
		RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
		RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
 
		/* Wait till PLL is used as system clock source */
		while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
		{
		}
	}

The problem is solved. Nothing wrong here. My board connect to a sensor and the sensor not work properly. That is really make me confuse when I try to debug. I just though the debug did not work properly, although I initial core clock to 32Mhz.(ps: I even think about has error in IDE.)