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

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
dast_1961951
Level 4
Level 4
10 likes received First like received

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.

2 Replies
VinayakS_26
Moderator
Moderator
Moderator
100 replies posted 50 replies posted 25 replies posted

Hi,

Have you tried this with FreeRTOS or is this something that pertains to ThreadX RTOS only.

0 Likes
dast_1961951
Level 4
Level 4
10 likes received First like received

only tried this with threadx.  it is an issue in the design of the stop mode function, so generally it should also occur this way in other RTOS, depending on how the adjustment of internal time is done.

0 Likes