2 Replies Latest reply on Nov 2, 2017 6:32 AM by dast_1961951

    STM32F4x:  platform_mcu_powersave / deep sleep race condition resulting in deferred ISR actions

    dast_1961951

      when arriving in stop_mode_power_down_hook(), PRIMASK is not set so interrupts are enabled.

       

      because of this, it is possible that there have been ISRs that have executed without their pending actions (threads that are pending on a message queue, semaphore, etc) occurring.

       

      example flow of events:

       

      1.

      all threads sleeping

      call idle function

      idle function calls stop_mode_power_down_hook()

      stop_mode_power_down_hook() determines device can sleep

      GPIO iSR is called

      ISR pushes a message to a worker thread

      ISR exits

      stop_mode_power_down_hook() continues & device enters deep sleep

      deep sleep continues until another GPIO ISR or RTC alarm

      device wakes, and performs context switch

      ISR message is finally received by worker thread and processed.

       

      example fix (which i could not implement because threadx glue code is closed):

       

      1.  determine no threads should be run

      2.  disables interrupts

      3.  check that all threads are still asleep.  if there is work to do, enable interrupts and continue working.

      4.  call idle function

      5.  call stop_mode_power_down_hook and so on.

       

      this method ensures that interrupts are disabled and any outstanding work is done before entering deep sleep.  anything that occurs on the GPIO IRQ will bring the device immediately out of deep sleep.