Skip to content

clear pending ICU interrupts before enabling global IRQ/FIQ (fix rare hang after deep-sleep wake)#26

Open
heyongman wants to merge 1 commit intoopenshwprojects:masterfrom
heyongman:fix/deepsleep-wakeup-early-boot-hang
Open

clear pending ICU interrupts before enabling global IRQ/FIQ (fix rare hang after deep-sleep wake)#26
heyongman wants to merge 1 commit intoopenshwprojects:masterfrom
heyongman:fix/deepsleep-wakeup-early-boot-hang

Conversation

@heyongman
Copy link

Context / Problem

In a door sensor use case the device spends most of its time in deep sleep and wakes up frequently via GPIO (door
open/close). Under stress (rapid open/close cycles) the firmware would sometimes hang very early during boot.

Observed symptoms:

  • The last reliable UART log line is: bk_misc_init_start_type 3 3
  • The next expected line (FreeRTOS heap init) such as prvHeapInit-start ... never appears
  • This indicates the start type detection finished, but the system gets stuck before completing func_init_basic() /
    before the heap is initialized.

Root Cause Analysis

A deep-sleep wake is not a fully cold boot. Some ICU interrupt status bits can remain latched/pending after wake-up.

During the boot path, intc_init() enables the ICU global IRQ/FIQ relatively early. If any interrupt is already
pending at that moment, the CPU may enter IRQ/FIQ handlers before the OS/heap is ready, which can lead to an
unrecoverable early-boot hang (no further logs after bk_misc_init_start_type).

Fix

In intc_init(), clear any pending ICU interrupt status before enabling interrupt sources and global IRQ/FIQ:

  • CMD_CLR_INTR_STATUS
  • CMD_CLR_INTR_RAW_STATUS

This prevents immediate entry into interrupt handlers during the extremely early boot stage after deep-sleep wake.

Changes

  • platforms/bk7231n/bk7231n_os/beken378/driver/intc/intc.c
    • Add ICU pending interrupt clear at the beginning of intc_init() (before enabling global IRQ/FIQ)
    • Add a comment explaining the deep-sleep wake scenario and why this is needed

Test Plan

  • Stress test: rapidly toggle door open/close to trigger deep-sleep wake >= 100 cycles (Set a short time to deep-sleep, approximately 3 seconds.)
  • Verify UART logs: no more cases where output stops at bk_misc_init_start_type 3 3 and heap init log is missing
  • Verify runtime behavior: wake -> advertise -> sleep remains stable over long runs without hangs/resets

Risk / Impact

  • Minimal change: only clears pending ICU interrupt flags before enabling interrupts
  • No behavioral change for cold boot; improves stability for deep-sleep wake scenarios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant