AnsweredAssumed Answered

correct sequence to park STM32F427 in stop mode

Question asked by poshtiw.harsh on Sep 15, 2015
Latest reply on Oct 2, 2015 by Amel N
Hi,
I am running into issue where the device is locking up from time to time once STM32F427 is parked to stop mode.
Here is what I do it to park it to stop mode.
Please review the code snippet and let me know if I am missing anything or it is erroneous.
/* Make sure PWR peripheral is running */
   RCC->APB1ENR |= RCC_APB1ENR_PWREN;  
    
   /* Back-up registers to be modified */
   ADC1_CR2_c = ADC1->CR2;
   ADC2_CR2_c = ADC2->CR2;
   ADC3_CR2_c = ADC3->CR2;
   DAC_CR_c   = DAC->CR;
   PWR_CR_c   = PWR->CR;
  
   /* Clear any pending external interrupts */
   EXTI->PR = 0x007FFFFF;
 
if(EXTI->PR == 0) /* All pins are still quiet, we can go to sleep */
   {       
      do
      {
 
 
    /* Disable SysTick Timer */
   SysTick->CTRL  &= 0xFFFFFFFE;
   /* Disable each ADC (drivers must re-calibrate each ADC) */
   ADC1->CR2 &= ~(ADC_CR2_ADON);
   ADC2->CR2 &= ~(ADC_CR2_ADON);
   ADC3->CR2 &= ~(ADC_CR2_ADON);
 
   /* Disable each DAC  (drivers must re-calibrate each DAC) */
   DAC->CR &= ~(DAC_CR_EN1 | DAC_CR_EN2);
     
   /* Voltage regulator in low power mode during stop mode */
   PWR->CR  |=  PWR_CR_LPDS;
     
   /* Enter Stop mode when the CPU enters deep sleep */
   PWR->CR  &= ~PWR_CR_PDDS;
     
   /* Disable the Flash power down in low power mode */
   PWR->CR &= ~PWR_CR_FPDS;
     
   /* Clear the Wake up flag */
   PWR->CR  |= PWR_CR_CWUF;
 
   /* Turn off misc clocks/clock sources */
   RCC->BDCR &= ~( RCC_BDCR_LSEON  |            // Disable LSE oscillator
                   RCC_BDCR_RTCSEL |            // Select no clock source for RTC
                   RCC_BDCR_RTCEN );             // Disable RTC
 
   RCC->CSR  &=  ~RCC_CSR_LSION;               // Disable LSI oscillator
 
   /* clear reset cause register */
   RCC->CSR |= RCC_CSR_RMVF;                   // Clear Reset cause flags
 
 /* RTC Wake Up Timer & RTC ISR Configuration */
   RTC_wakeup_setup(rtcWakeupTime);
 
 systime_pause();
         ENTER_CRITICAL();
 /* Prepare to enter Cortex-M3/M4 DEEPSLEEP = STOP mode */
         SCB->SCR |= SCB_SCR_SLEEPDEEP;
         SCB->SCR &= ~SCB_SCR_SEVONPEND; // use only enabled IRQs to wake-up
          
         dsb();
         nop();
          
         wfi(); // Sweet dreams ... //now STM is waiting for interrupt only power button, charge completion, External power source and  RTC interrupts are allowed in off mode
                 //in low power mode we allow Power button, trigger, charger connection and BT interrupts are allowe
         nop(); 
         nop();
         nop();   
 
         SCB->SCR &= ~SCB_SCR_SLEEPDEEP; // clear or wake from sleep/stop mode 
      
         /* Resume OS Tick (needed for OSTimeDly used in changeToPowerMode() */
         systime_resume();
         /* Start clocks, as any irq/task may be called after interrupts are enabled */
         CLKGEN_init();
         /* Enable interrupts to service RTC and OS Tick*/
         EXIT_CRITICAL();
/* Clear the Wake up flag */
         PWR->CR  |= PWR_CR_CWUF;
 
 
} while (IsNoWakeupTriggered());


Outcomes