Search code examples
stm32power-managementstm32ldiscovery

Exiting STOP mode on STM32L100Rc


I am a new coder using the STM32L100RC discovery board. As such, my problem is quite simple I believe; I cannot exit Stop mode using an external trigger on the WakeUp Pin PA0. The code works as fallow: the LED on the PC9 pin light up, I enter STOP MODE and once I use the WakeUp command by pushing on the PA0 button, the LED turns off for a few seconds. Now I do know that using a a for loop isn't the right way to wait a few seconds, no need to point this out. I'd be very grateful if someone could explain what I am doing wrong. Here's what I've done so far:

void Button_Initialization (void)

{



RCC_APB2PeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);



// Configure PC9 as push-pull output

GPIO_InitTypeDef GPIO_InitStruct;

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;

GPIO_Init(GPIOC, &GPIO_InitStruct);



GPIO_InitTypeDef GPIO_InitStructA;

GPIO_InitStructA.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStructA.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_InitStructA.GPIO_Mode = GPIO_Mode_AF;

GPIO_PinAFConfig(GPIOA, GPIO_Pin_0, GPIO_AF_WKUP);

GPIO_Init(GPIOA, &GPIO_InitStructA);

PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);





GPIO_InitTypeDef GPIO_InitStructButton;

// GPIO_InitStructButton.GPIO_Pin = ;

GPIO_InitStructButton.GPIO_Speed = GPIO_Speed_400KHz;

GPIO_InitStructButton.GPIO_Mode = GPIO_Mode_IN;

GPIO_InitStructButton.GPIO_PuPd = GPIO_PuPd_DOWN;

GPIO_Init(GPIOA, &GPIO_InitStructButton);



EXTI_InitTypeDef EXTI_InitStruct;

EXTI_InitStruct.EXTI_Line = EXTI_Line1;

EXTI_InitStruct.EXTI_LineCmd = ENABLE;

EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Event;

EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;

EXTI_Init( &EXTI_InitStruct);

}



int main(void)

{

Button_Initialization();

while(1)

{

// Turn off LED on PC9

GPIO_SetBits(GPIOC, GPIO_Pin_9);





PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFE);


GPIO_ResetBits(GPIOC, GPIO_Pin_9);

for (int i = 0; i < 1000000; i++)

{

}

}

}

Solution

  • With your configuration you have no wakup source:

    PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE); is only usable if you want to wake the uC from standby, but not from stop mode. (see Reference manual chapter 5.3.8 Standby mode and 5.4.2 PWR power control/status register (PWR_CSR))

    With entering the stop mode like this PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFE); you need a qualified event to wake the uC. To achive this you simply have to configure the PA0 as input (not the alternate wakeup function) with EXTI line event activated (which is EXTI line 0).

    Also before entering stop mode you have to make sure, that all interrupt, EXTI line and RTC pending bits are cleared. Otherwise the enter stop mode is ignored.