drivers: serial: stm32: use PM constraints to prevent suspension

In the current implementation the STM32 UART driver required to enable
`CONFIG_PM_DEVICE` when `CONFIG_PM=y` to function properly. The main
reason is that in some situations, like in polling mode, transmissions
are not fully synchronous. That is, a byte is pushed to the _queue_ if
it is empty and then the function returns without waiting for it to be
transmitted to the wire. This makes sense to make things like per-byte
transmission efficient. However, this introduces a problem: the system
may reach idle state, and so enter low power modes before the UART has
actually finished the last data in the queue. If this happens,
communications can be interrupted or garbage data may be put into the
UART line.

The proposed solution in this patch uses PM constraints to solve this
problem. For the IRQ/DMA case it is easy since we can set the constraint
before transmission start, and when the completion (TC) interrupt is
received we can clear it. However, the polling mode did not have the
capability to signal the completion. For this case, a simpler IRQ
routine is provided to just release the constraint. As a result, the PM
hooks are not required and so system can operate with just `CONFIG_PM`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-09-09 22:41:35 +02:00 committed by Anas Nashif
commit e3f4907efe
2 changed files with 71 additions and 46 deletions

View file

@ -25,6 +25,11 @@ struct uart_stm32_config {
int parity;
const struct soc_gpio_pinctrl *pinctrl_list;
size_t pinctrl_list_size;
#if defined(CONFIG_PM) \
&& !defined(CONFIG_UART_INTERRUPT_DRIVEN) \
&& !defined(CONFIG_UART_ASYNC_API)
uart_irq_config_func_t irq_config_func;
#endif
};
#ifdef CONFIG_UART_ASYNC_API