tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.49k stars 913 forks source link

nRF52: update from 0.33 -> 0.34 causes 500x idle-current #4597

Open perttierkkila opened 1 week ago

perttierkkila commented 1 week ago

For ultra-low power applications where all peripherials are disabled and usually under 1.5uA SystemON currents, update to 0.34 was a bad mistake which caused 600uA idle current. After debugging, something keeps requesting HF-clock.

I tried to check diffs between 0.33 and 0.34 and I can't find any changes related to nRF52-parts. The problem is caused under initAll()-code. I tried to dig that part also but no luck as it goes to compiler-part.

Example code:

func main() {
    arm.EnableIRQ(uint32(nrf.IRQ_RTC1)) // workaround to keep IRQs running, already fixed in dev

    led := machine.P0_20
    led.Configure(machine.PinConfig{Mode: machine.PinOutput})
    for {
        led.Set(nrf.CLOCK.HFCLKSTAT.Get()>>16 == 1)
        time.Sleep(10 * time.Millisecond)
        led.Low()
        time.Sleep(500 * time.Millisecond)
    }
}

Serial, GC and scheduler disabled, flashing with command: tinygo flash -size=short -scheduler=none -gc=none -serial=none -target=pca10040 -programmer command main.go

Output:

Also tried to play with -opt values, no effect. Except -opt=0 which keeps current under 1.5uA but code is not running either. Any ideas which causes this issue?