Skip to content

BK7238: GPIO edge interrupts never fire (pulse_counter / hlw8012 / BL0937 read 0) #393

Description

@blafois

Summary

On the freshly-added BK7238 target, GPIO edge interrupts never fire. attachInterrupt()-based consumers (ESPHome pulse_counter, hlw8012/BL0937 energy metering) receive zero edges, even with a strong, continuous signal on the pin. The same wiring/config works on BK7231N.

This makes any interrupt/pulse-driven peripheral (energy meters, pulse counters, etc.) non-functional on BK7238, while polling-based GPIO (button input, relay/LED output) works fine.

Environment

  • LibreTiny v1.13.0 (latest release; master is identical) — BK7238 support from [beken-72xx] Support BK7238 #360, BDK 3.0.78
  • ESPHome 2026.8.0-dev (dev branch, native BK7238 support)
  • Board: generic-bk7238-tuya
  • Device: LSC Smart Plug w/ energy meter (Tuya T1-2S-NL module, BK7238, BL0937 metering chip)
  • Flashed via UART (ltchiptool); app confirmed booting (correct build timestamp in logs)

What works vs. what doesn't

Function GPIO Mechanism Works?
Relay P24 digital output
Status LEDs P9, P11 digital output
Button P26 polling input
BL0937 power meter CF=P6, CF1=P8, SEL=P1 interrupt (pulse) ❌ reads 0

Minimal reproduction

Bare pulse_counter on the BL0937 CF (power) and CF1 (voltage/current) pins:

sensor:
  - platform: pulse_counter
    name: "CF pulses (P6 power)"
    pin: P6
    update_interval: 5s
  - platform: pulse_counter
    name: "CF1 pulses (P8 V/I)"
    pin: P8
    update_interval: 5s

Plug energized on live mains, relay ON, ~250 W resistive/inductive load (a running drill) drawing current. A BL0937 CF output at 250 W should pulse at several hundred Hz.

Observed — flat zero for 25+ seconds on both pins:

[pulse_counter:200]: 'CF pulses (P6 power)':  Retrieved counter: 0.00 pulses/min
[pulse_counter:200]: 'CF1 pulses (P8 V/I)':   Retrieved counter: 0.00 pulses/min
(repeats every 5 s, always 0.00)

hlw8012/BL0937 likewise logs Got power=0.0W, voltage=0.0V (exactly 0.0, not nan), i.e. the driver runs but counts no pulses.

Notes / where I looked

The Arduino IRQ shim (cores/beken-72xx/arduino/src/wiring_irq.c) looks complete and calls gpio_int_enable(...). In the BDK (beken378/driver/gpio/gpio.c), gpio_int_enable() does register the GPIO ISR (intc_service_register(IRQ_GPIO, PRI_IRQ_GPIO, gpio_isr)) and has CFG_SOC_NAME == SOC_BK7238 branches for the interrupt-level registers, so the path appears wired up — yet no user callback is ever invoked on BK7238. Something in the BK7238 GPIO interrupt enable/dispatch (e.g. ICU/INTC routing or the INT-enable register write) is likely not taking effect.

Happy to run further tests on real hardware (scope on CF pin, register dumps, etc.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions