AnsweredAssumed Answered

STM32 reset when wakeup by extern line from stop mode

Question asked by zhang.xiang on May 23, 2013
Latest reply on May 24, 2013 by zhang.xiang
Hello, everybody
now I use stm32f103r8, I haved followed the reference manual and configured my mcu in to stop mode. And it has been in stopmode, but when i press button to wakeup the mcu, the mcu reset. I print value of register RCC_CSR, it's the default value 0x0c000000.
as descriped above, my problem is why mcu reset when I pressed button to wakeup the mcu?
by the way, I post my code below:


void MCU_sleep (void)
{
    UART1_send_array ((u8 *)"go to sleep\r\n", 13); //debug  


    AFIO -> EXTICR[0] = 0 << 12; //exit_lin3 enable
    AFIO -> EXTICR[2] = 0 << 0;  //exit_lin8 enable
    
    EXTI -> IMR = (1 << 3) | (1 << 8); //exit interrupt mode  
    EXTI -> FTSR = (1 << 3) | (1 << 8); //rising edge trigger     
      
    //clr pending request and rtc flag before enter stop     
    EXTI -> PR = (1 << 3) | (1 << 8);
    RTC -> CRL &= (~(1 << 1)); //clr RTC alarm flag
      
    //set SLEEP_DEEP bit(2), clr SEVEONPEND bit(4)
    SCB -> SCR |= (1 << 2); 
    //clr PDDS bits in PWR_CR, means sleep mode
    PWR -> CR &= (~(1 << 1)); 


    //LPDS(bit0) = 0     
    PWR -> CR &= (~(1 << 0)); //regulator on during sleep mode


    WFI_SET();




    //clr SLEEP_DEEP bit after wakeup
    SCB -> SCR &= (~((1 << 2)));
    RTC -> CRL &= (~(1 << 1));       


    //after wakeup, configure clock again
    RCC_config ();
    UART1_send_array ((u8 *)"wake up\r\n", 9); 
}






void interrupt_config (void)
{
    //EXIT3, position 9,priority 16
    //EXIT8,position 23, priority 30
    //ISER,interrupt enable
    NVIC -> ISER[0] = (1 << 9) | (1 << 23); 
}




the debug information by uart descrip below:




power on
RCC_CSR=0x0C000000
UART1 test                 
go to sleep                   //mcu sleep here, and I press button, mcu reset, 
power on
RCC_CSR=0x0C000000
UART1 test
go to sleep

Outcomes