2008-11-11 12:23 PM
Reason for freeze after sleep
2011-05-17 03:51 AM
I have been having an issue where my processor will freeze after quite a few cycles of returning from STOP mode.
After looking through some of the files I think I found the problem and it relates to the STM32 library. Every time the processor comes back from being asleep it goes through the ''SYSCLKConfig_STOP()'' function that is in the example code. In this function the processor reconfigures the system clock after wake-up by enabling the HSE and PLL. The first thing that is done after the HSE is configured ON is: /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); In this function we have the following code from the fwlib: /******************************************************************************* * Function Name : RCC_WaitForHSEStartUp * Description : Waits for HSE start-up. * Input : None * Output : None * Return : An ErrorStatus enumuration value: * - SUCCESS: HSE oscillator is stable and ready to use * - ERROR: HSE oscillator not yet ready *******************************************************************************/ ErrorStatus RCC_WaitForHSEStartUp(void) { ErrorStatus status = ERROR; /* Wait till HSE is ready and if Time out is reached exit */ do { HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY); StartUpCounter++; } while((HSEStatus == RESET) && (StartUpCounter != HSEStartUp_TimeOut)); if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET) { status = SUCCESS; } else { status = ERROR; } return (status); } The problem seems to be that ''StartUpCounter'' is not reset. It is initialized at the top of the stm32f10x_rcc.c file as: static vu32 StartUpCounter = 0; Because it is static the value remains and is incremented every time the processor comes back from sleep. After enough cycles, the StartUpCounter value is high (equal to the HSEStartUp_TimeOut value) and will result in a fail. Please confirm if this is correct. To fix this I initialize StartUpCounter to zero within the RCC_WaitForHSEStartUp() function.2011-05-17 03:51 AM
Does anybody else use the ''SYSCLKConfig_STOP()'' function when coming out of sleep? More importantly does anybody else have issues with it causing rare lockups?