With CONFIG_UART_NS16550_DW8250_DW_APB, uart_ns16550_irq_tx_ready()
reports the transmitter ready whenever USR.TFNF is set, i.e. as soon as
the TX FIFO has room, while uart_ns16550_fifo_fill() writes up to
fifo_size bytes without checking how much room there actually is. When
the ISR runs with data left in the FIFO, the excess bytes are written to
a full FIFO and lost.
On the Silicon Labs SiWx917 (ulpuart, ns16550 with the DW8250 option)
this happens right after boot and about once per thousand fills under
load: the UART ISR is entered with no interrupt pending (IIR reads 0xC1)
while the FIFO still holds 15 of the 16 bytes of the previous fill, so
the fill loses up to 15 bytes. With the Bluetooth monitor in
interrupt-driven mode on that UART the stream had a truncated New Index
frame after every boot and lost 15-byte chunks every 1-2 seconds, while
the polled mode was unaffected.
Stop the DW8250 fill loop as soon as USR.TFNF clears, so that the driver
never writes more than the FIFO can take and returns the number of bytes
it actually accepted.
Fixes#117777
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Compilation was failing when one instance is using interrupt driven
API and another one is using asynchronous API with TIMER byte counting.
Compilation was also failing if instance had timer property in DT but
Kconfig was indicating use of the interrupt driven API.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Add device pm support so the LPUART can be re-initialized
after a low-power state that collapses its power domain
(for example i.MX RT700 deep-sleep-retention), which loses
all peripheral state.
The suspend action saves and masks the enabled interrupts
so a pending interrupt cannot fire its ISR against the
powered-down register bank; the resume action re-initializes
the peripheral and restores those interrupts, and the ISR
bails out while suspended. pm_device_driver_init() establishes
the initial device state.
This relies on the LP_FLEXCOMM parent being resumed first
to re-select the peripheral in the wrapper, which device PM
guarantees via init-priority ordering.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Replace direct NVIC pending-state calls with k_irq_set_pending()/
k_irq_is_pending()/k_irq_clear_pending(), dropping the dependency on
cmsis_core.h where nothing else needed it.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The functions eusart_silabs_ll2cfg_*() have never been used. Probably the
original author wrote them for the completeness since their
eusart_silabs_cfg2ll counterparts were required.
Orphan function generate warning that could in turn generate error with
-Werror.
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
The functions uart_silabs_ll2cfg_*() have never been used. Probably the
original author wrote them for the completeness since their
uart_silabs_cfg2ll counterparts were required.
Orphan function generate warning that could in turn generate error with
-Werror.
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
This commit updates the usage of ring_buf to utilize the new
put_ptr/commit/get_ptr/consume pattern instead of the traditional
claim/finish approach. This change is part of a larger refactor aimed at
streamlining the ring_buf API and improving its efficiency.
Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
When converting timeout (in microseconds) to bauds use by the HW
frame timeout use less accurate conversion but one that does not
use 64 bit division. 64 bit division takes a lot of code and time
and shoud be avoided.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The async driver reserved its devicetree-assigned RX/TX DMA channels by
poking the DMA controller's dma_context atomic bitmap directly with
atomic_set_bit(). That bypassed the public DMA API, never detected a
channel that was already in use, and dereferenced dma_rx/dma_tx.dma_dev
unconditionally: when only one direction is wired to DMA the other
dma_dev is NULL, so the reservation crashed on a NULL pointer.
Reserve each channel through dma_request_channel() with a BIT(channel)
filter instead. This forces exactly the devicetree channel, registers it
in the same allocation bitmap that dma_request_channel(dev, NULL) callers
(such as memory-to-memory transfers) consult, and returns an error when
the channel is already taken. Each direction is now guarded by its own
NULL check, fixing the single-direction crash.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Yuzhuo Liu <yuzhuo_liu@realsil.com.cn>
Since frame-timeout-supported DT property if of boolean type, use of
dt_compat_any_has_prop() without an explicit value argument of True
makes that function to always return true. Set function argument
value to True to get the expected behavior.
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
The static 'dlf' property is valid only for a specific PCLK/baud rate
combination. The current calculation accounts for this fixed value when
selecting the integer divisor, but cannot adapt to runtime baud rate
changes.
A low fixed PCLK may require a fractional divisor to reduce baud rate
error for the requested baudrate.
Add an opt-in 'dlf-auto' property to calculate the integer divisor and
DLF value together whenever the baud rate changes, using 1/64-resolution
fixed-point arithmetic. When enabled, 'dlf-auto' overrides 'dlf'.
Also enable DLF support when an instance uses either 'dlf' or
'dlf-auto'. Existing 'dlf' users are unaffected.
Signed-off-by: Bo Sun <bo.sun@kernel.li>
Add reset driver for the reset part of the ch32 rcc.
Use this new reset driven in `wch,usart` to reset the usart peripheral
before use.
Signed-off-by: Fiona Behrens <me@kloenk.dev>
This fixes a potential build warning introduced in 7b2a3c0cca, where
the static functions would get declard but not used if the board has:
- CONFIG_PM=y
- CONFIG_UART_ASYNC_API=y
- CONFIG_DMA=y
- the dma node enabled in devicetree
Reproduced with:
west build -p -b stm32f4_disco samples/hello_world -DCONFIG_PM=y
-DCONFIG_UART_ASYNC_API=y -DCONFIG_DMA=y
zephyrproject/zephyr/drivers/serial/uart_stm32.c:218:13: warning:
'uart_stm32_rx_wakeup_lock_get' defined but not used
Found this downstream, finding the specific combination of option and
dt override to reproduce this was a big mess, there's no benefit chasing
down the specific combination of ifdeffery here so let's just mark them
as maybe unused and if that combo hits the compiler can just drop them.
Between ifdefs form Kconfig and the HAL this driver is already VERY hard
to follow.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
MISRA C:2012 Rule 8.2 requires every parameter in a function type to be
named, including the parameters of function pointer parameters.
The cache, clock control, comparator, entropy, Ethernet, I2S and serial
drivers left callback parameters unnamed, or carried forward
declarations that dropped the names the definitions already use. The two
virtio callbacks get ARG_UNUSED() for the arguments they deliberately
ignore.
Name them after the arguments the documentation or the
definitions already use. No functional change.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
A UART that woke the SoC keeps PM_STATE_SUSPEND_TO_IDLE locked forever
once the hardware receiver timeout is in use.
The WKUP interrupt takes the lock and sets rx_woken. The IDLE arm of
uart_stm32_isr() would release it, but set_timeout_itr() disables the
IDLE interrupt when it programs RTOR, so the RTO arm reports the end of
reception instead and only clears the flag and flushes. The lock is never
released, so the system never enters a Stop state again.
Move acquire and release into helpers and call them from both paths, so
the behaviour at the end of reception is consistent.
Also move enable_wakeup_line out of the block with the PM policy helpers.
Tested on a nucleo_l476rg, cyclic asynchronous reception with PM enabled.
Fixes: #116273
Signed-off-by: Eden Frosst <eden.frosst@rbr-global.com>
The baudrate divisor calculation should take the fractional parameter
into account when a DLF-capable UART is used. Otherwise non-optimal
integer divisors can be derived, especially for low pclk or high
baud_rate values.
Signed-off-by: Andreas Weissel <andreas.weissel@synaptics.com>
If GPPI is using IPC communication then delay the initialization of an
UARTE instance which is using GPPI connection after GPPI is initialized
which happens after IPC service is setup.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
uart_gecko_irq_tx_enable() enables both the TXBL and TXC interrupts,
but nothing in the standard interrupt-driven flow clears the TXC
flag: it is write-1-to-clear and only uart_gecko_irq_tx_complete()
clears it, which typical interrupt handlers (servicing
uart_irq_tx_ready() and uart_irq_rx_ready()) never call. Once a
transmission completes, TXC stays pending and the UART interrupt
re-enters continuously whenever TX is enabled, spinning at hardware
interrupt priority between TXBL servicing opportunities.
This is the same defect as in the silabs usart driver fixed by the
previous commit, where it was measured on hardware (82017 ISR entries
for 1811 TX-ready services on xg24_rb4186c). The gecko driver shares
the exact structure: TXC enabled as an interrupt source, no stale
flag clearing in irq_tx_enable() or irq_tx_disable(), and
irq_is_pending() not reporting TXC. This change is build-tested for
slwrb4104a but not validated on Series 0/1 hardware.
Only enable TXBL, which is sufficient to pace FIFO refills, and clear
the stale TXC flag when TX is disabled so uart_irq_tx_complete()
cannot report a completion from a previous transmission.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
uart_silabs_irq_tx_enable() enables both the TXBL and TXC interrupts,
but nothing in the standard interrupt-driven flow clears the TXC flag:
it is write-1-to-clear and only uart_silabs_irq_tx_complete() clears
it, which typical interrupt handlers (servicing uart_irq_tx_ready()
and uart_irq_rx_ready(), as the console, shell and Bluetooth monitor
do) never call. Once the first frame completes, TXC stays pending and
the UART interrupt re-enters continuously for the whole duration of a
transmission, spinning at hardware interrupt priority between TXBL
servicing opportunities (one byte time apart at the configured baud
rate). The driver's own irq_is_pending() does not include TXC either,
so the documented "while (uart_irq_is_pending())" handler idiom cannot
observe the interrupt cause it is being invoked for.
This is distinct from and not addressed by commit 3a6406439c
("drivers: serial: silabs: Only clear processed flags"), which fixed
flag clearing inside irq_tx_complete() itself but did not change TXC
being enabled as an interrupt source that no standard handler
acknowledges.
Measured on xg24_rb4186c with an interrupt-driven TX user that
services only uart_irq_tx_ready(): 82017 ISR entries for 1811 TX-ready
services. The storm throttles every thread on the CPU to the UART
byte rate, and starves the radio hard enough to break Bluetooth link
supervision under load. With this fix the same workload shows 805139
TX-ready services in 806757 ISR entries.
Only enable TXBL, which is sufficient to pace FIFO refills, and clear
the stale TXC flag when TX is disabled so uart_irq_tx_complete()
cannot report a completion from a previous transmission. TXC remains
readable through uart_irq_tx_complete(), which uses the raw interrupt
flag rather than the enabled mask.
The eusart driver also enables TXC from irq_tx_enable(), but clears
stale TXC flags in both irq_tx_enable() and irq_tx_disable(), which
prevents the storm; this was verified on the same hardware (497
interrupts for 497 TX-ready services when transmitting 512 bytes).
The legacy gecko driver shares the vulnerable structure and is fixed
in the following commit.
Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Add a stub configure callback to the native PTY UART driver when
CONFIG_UART_USE_RUNTIME_CONFIGURE is enabled.
The stub accepts valid configuration requests without applying any UART
settings and returns -EINVAL when the configuration pointer is NULL.
This enables applications that require the runtime UART configuration API,
such as Modbus RTU, to use the native PTY UART driver.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
Do not defer STOPRX when CBWT is active because CBWT does not process
ENDRX interrupts. Trigger STOPRX immediately to complete RX teardown
and prevent subsequent uart_rx_enable() calls from returning -EBUSY.
Fixes#115897 and #115899
Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
By default, the UART RX FIFO is configured to trigger an interrupt
when it is half full. This end up breaking implementations that
assumed a per-byte interrupt delivery. These changes make these
properties adjustable in the DTS for RX and TX FIFOs.
Signed-off-by: Steven Macías <esmu@bang-olufsen.dk>
In interrupt handlers, only clear interrupt flags that have been
processed. This fixes a race condition where an interrupt that was
raised after flags were read for processing was prematurely
cleared without the corresponding action being taken.
When this condition was met, irq_tx_complete() never reported that
transmission was complete, while err_check() failed to report errors.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
bounce_buf_swap_len variable is used when mode that uses TIMER to
count RX bytes was used. Macro for calculating that variable was
invoked with incorrect argument as UARTE_US_TO_BYTES was applied
to baudrate argument. Because of that
CONFIG_UART_NRFX_UARTE_BOUNCE_BUF_SWAP_LATENCY was in fact not
applied.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Restore the previous interrupt state when DMM RX buffer preparation
fails. Returning with the IRQ lock held could leave interrupts disabled
after uart_rx_buf_rsp() reports the error.
Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
Model DMAEND and FRAMETIMEOUT_DMAEND support as a devicetree
capability. Use DMAEND for finite asynchronous RX frame timeouts on
capable UARTE instances and retain STOPRX on unsupported hardware.
Disable TIMER-based byte counting when DMAEND is available. Preserve
buffer accounting when uart_rx_disable() races with an ENDRX rollover,
reject buffer responses during teardown, and restore the interrupt
state after DMM preparation failures.
Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
uart_stm32_async_rx_disable() forced RXNE on and left the ERROR
interrupt enabled, causing per-byte/per-overrun ISR load on continuous
RX streams.
Keep async and interrupt-driven RX ownership separate: async disables
RXNE on enable and, on disable, only tears down async state and
disables ERROR. RXNE remains off; callers that switch back to
interrupt-driven RX must re-enable it via uart_irq_rx_enable().
This avoids ISR flooding for async users and matches API ownership.
Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
Add UART asynchronous driver support for Realtek Bee series SoCs,
including RTL87x2G and RTL8752H.
This driver supports:
- Asynchronous TX/RX transfers
Signed-off-by: Yuzhuo Liu <yuzhuo_liu@realsil.com.cn>
GPIO isolation during sleep leaves all pins floating, for power saving.
In some configurations the UART peripheral will remain ON during sleep
and can be affected by signal shifts in the pins. Use the pad hold
function to leave signals recessive and avoid spurious UART events
which can dirty the FIFO and leave pending interrupts which can
stall the system.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Use xen_sched_yield() in the Xen HVC UART driver instead of calling the
low-level scheduler hypercall entry point directly.
This keeps the driver on the public Xen scheduler helper API while
preserving the existing behavior. The driver still yields the current
VCPU when the TX ring is full so the console backend can consume data.
Signed-off-by: Vladyslav Goncharuk <vladyslav_goncharuk@epam.com>
Assisted-by: Codex:gpt-5 cpp-code-map
Remove the dedicated BCM2711 auxiliary UART driver and its associated
Kconfig entry now that support has been integrated into the generic
NS16550 driver.
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
Add support for the Broadcom BCM283x auxiliary UART variant to the
NS16550 driver by introducing a dedicated Kconfig option and variant-
specific register definitions required for the extended register set.
This enables the generic NS16550 driver to support the auxiliary UART
found on Broadcom BCM283x SoCs.
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
The bridge already forwards the port configuration (baudrate,
parity, etc...) to the peer, but not the modem control lines.
Forward DTR RTS state to the peer port as well, so a bridged
serial port carries the control lines through like a USB-serial
adapter does.
Note the forwarding is compiled in only if CONFIG_UART_LINE_CTRL
is enabled.
Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
Each detected error was assigned with '=', so simultaneous conditions
reported only the last one checked. OR the flags together.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Add UART driver support for the CH5xx.
This enables the hello_world and the drivers/uart/echo_bot samples.
Signed-off-by: Elie Carrot <elie.carrot@smile.fr>
Align the public UART async API with its microsecond-based implementation.
Update the wide-data (u16 variant) TX and RX API documentation to
specify microseconds and SYS_FOREVER_US.
Replace millisecond-named forever sentinels in the serial test driver and
asynchronous UART callers, while retaining existing microsecond timeout
values in drivers, tests, and samples.
Assisted-by: Copilot:GPT-5.6 Terra
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This driver needs the nsi_errno conversion component.
Let's make sure we build it by selecting it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" drivers/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Add initial UART driver support for the ELAN EM32 SoC family. The driver
implements basic polling TX/RX via the Zephyr serial API and instantiates
devices from devicetree when an EM32 UART node is present and okay.
Devicetree:
- Compatible: "elan,em32-uart" (binding included)
Notes:
- The driver is initialized at PRE_KERNEL_1
with CONFIG_SERIAL_INIT_PRIORITY
so the device is ready before the console backend binds.
Signed-off-by: Johnny Chuang <johnny.chuang@emc.com.tw>
This PR migrates the MIT-licensed Xen public headers into the
`include/zephyr/xen/public` directory to the zephyr-xenlib module.
Since the xen public headers require GCC extensions,
enable GNU_C_EXTENSIONS along with enabling CONFIG_XEN.
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Remove the dedicated xlnx_xuartps driver and consolidate support
into the Cadence UART driver (uart_cdns), as both drivers target
the same underlying Cadence UART IP used by Xilinx platforms.
Update device tree bindings and DTS files to use the Cadence
compatible string on supported platforms, remove obsolete driver
sources, and adjust build system configuration accordingly.
Also update test overlays to reflect the driver consolidation.
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>