Question
WFI call inside IRQ handler
Posted on September 08, 2017 at 09:58
Hello,
I'm using STM32L100R8T6A.The problem I'm facing is that I do a Low Power Battery Powered Project, where it's necessary to detect that battery has been removed and I have backup capacitor for this case but with limited charge to hold MCU alive.
The problem is that I
detect Falling edge by EXTI if battery is removed at pin PC.13 (Wakeup 2).
When this interrupt is called I do this:HAL_GPIO_EXTI_IRQHandler(PTB_DEF_BATT_PRESENT_PIN); // PC13__HAL_RTC_WAKEUPTIMER_DISABLE(&T_hrtc); __HAL_RCC_CLEAR_RESET_FLAGS(); __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2); // Batt detectionRCC->APB1ENR |= RCC_APB1ENR_PWREN; // To be able to write to PWR registers, you have first to enable PWR's clock by setting RCC_APB1ENR.PWREN. SCB->SCR |= SCB_SCR_SLEEPDEEP; // enter deepsleep mode PWR->CR |= PWR_CR_PDDS; // enter standby in deepsleep PWR->CR |= PWR_CR_CWUF; // clear wakeup flag __WFI();
After this I enter Standby mode but it's never wokenup, not by rising edge at PC13 and event not by IWDG which is also running.When I call same code within the mainloop, it enters StandBy corectly and can be woken uop by both IWDG and PC13 rising edge.Is the problem that I call WFI within IRQ handler? If so is there some workarounf? I have to enter StandBy as Soon as battery is removed so it's time critical task which I can't handle within main loop, it's too slow.And then I have to detect Rising edge at PC.13 when battery is put back and wake up the system.
