Description
Describe the bug
While trying to add the PM feature to the STM32U0 target in this PR, I saw that the device never went to the sleep mode because it is locked by the UART driver.
To Reproduce
Using the following MWE, build and flash with the typical commands:
west build -b example -- -DBOARD_ROOT=.
west flash
The current consumption is 1.75mA as is.
If pm_policy_state_lock_get()
and pm_policy_state_lock_put()
are commented out in drivers/serial/uart_stm32.c
, the current consumption drops to 440 µA. In both cases, the debug probe is attached and consumes few hundreds of µA.
Expected behavior
The current consumption is low (ie. the system goes to a low power mode) without manually disabling the pm lock in uart_stm32.c
.
Impact
The system does not reach the expected lifetime when battery-powered.
Logs and console output
The lock is get by uart_poll_out()
at the first printk()
(the boot banner or if disabled, my own app printk()
). Subsequent printk()
do not get or put the lock anymore.
Breakpoint 1, uart_poll_out (dev=<optimized out>, out_char=42 '*') at app/build/zephyr/include/generated/zephyr/syscalls/uart.h:108
108 z_impl_uart_poll_out(dev, out_char);
(gdb) backtrace
#0 uart_poll_out (dev=<optimized out>, out_char=42 '*') at app/build/zephyr/include/generated/zephyr/syscalls/uart.h:108
#1 console_out (c=42) at app/zephyr/drivers/console/uart_console.c:102
#2 0x080004a4 in char_out (c=<optimized out>, ctx_p=<optimized out>) at app/zephyr/lib/os/printk.c:98
#3 0x08004216 in vfprintf ()
#4 0x080004de in vprintk (fmt=0x8007689 "*** Booting Zephyr OS build v4.1.0-2646-ge41909a32ce9 ***\n", fmt@entry=0x1 <error: Cannot access memory at address 0x1>, ap=..., ap@entry=...) at app/zephyr/lib/os/printk.c:134
#5 0x0800560c in printk (fmt=0x8007689 "*** Booting Zephyr OS build v4.1.0-2646-ge41909a32ce9 ***\n") at app/zephyr/lib/os/printk.c:198
#6 0x08003ff0 in boot_banner () at app/zephyr/kernel/banner.c:46
#7 0x08002cc0 in bg_thread_main (unused1=<optimized out>, unused2=<optimized out>, unused3=<optimized out>) at app/zephyr/kernel/init.c:551
#8 0x08000508 in z_thread_entry (entry=0x8002cad <bg_thread_main>, p1=0x0, p2=0x0, p3=0x0) at app/zephyr/lib/os/thread_entry.c:48
#9 0x0800108c in arch_switch_to_main_thread (main_thread=0x8002cad <bg_thread_main>, stack_ptr=0x0, _main=0x8002cad <bg_thread_main>) at /home/mika/dev/embedded/zephyr/common/zephyr/arch/arm/core/cortex_m/thread.c:546
#10 0x20000608 in z_idle_threads ()
Environment (please complete the following information):
Additional context
The lock is taken by a poll function but CONFIG_UART_INTERRUPT_DRIVEN=y
is defined.