Skip to content

Fix UART and USB serial timeout values reading back wrong on Zephyr boards - #11585

Merged
tannewt merged 2 commits into
adafruit:mainfrom
mikeysklar:usb-cdc-write-timeout
Oct 15, 2026
Merged

tannewt merged 2 commits into
adafruit:mainfrom
mikeysklar:usb-cdc-write-timeout

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

What

timeout and write_timeout now read back in seconds, and None stays None.

Why

On Zephyr boards, 0.5 read back as 0.015625, and setting None turned into 0.

Tests

nRF54LM20 DK, usb_cdc data enabled in boot.py.

Property Set main reads This PR reads
usb_cdc.data.write_timeout 0.5 0.015625 0.5
usb_cdc.data.write_timeout 2.25 0.070313 2.250016
usb_cdc.data.write_timeout None 0.0 None
usb_cdc.data.timeout 0.5 0.015625 0.5
usb_cdc.data.timeout None not tested None
busio.UART(..., timeout=0.25).timeout 0.25 0.007813 0.250016
busio.UART.timeout 3 0.09375 3.0

Writes on Zephyr still ignore write_timeout; this only fixes the values.

Pico W and SiWx917-DK2605A are build-tested only.

Written with Claude; tested on hardware by me.

🤖 Generated with Claude Code

The timeout getters divided kernel ticks by 1e6 as if they were
microseconds, so usb_cdc write_timeout = 0.5 read back as 0.015625 on a
32768 Hz tick. Convert ticks to microseconds first, and report
K_FOREVER as -1 so usb_cdc shows None.

Setting usb_cdc timeout or write_timeout to None passed -1 to K_USEC(),
which came out as zero. Store K_FOREVER instead, the value both start
with.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine. Please add a native sim test that tests this.

native_sim ticks at 100 Hz, so before the fix timeout = 0.5 read back as
5e-05. The test sets 0.5, 2 and 0 on board.UART0() and checks each reads
back in seconds.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mikeysklar

Copy link
Copy Markdown
Collaborator Author

Added tests/test_busio_uart.py in 9c0689d. It sets timeout on board.UART0() and checks it reads back in seconds. native_sim has no usb_cdc, so it covers the busio side.

timeout set main this PR
0.5 5e-05 0.5
2 0.0002 2.0
0 0.0 0.0

The test fails on main and passes here. Also rechecked on a Feather nRF52840 (Zephyr): main reads 0.5 as 0.016384 and usb_cdc None as 0.0; this PR reads back 0.5, 2.25 and None.

@mikeysklar
mikeysklar requested a review from tannewt October 15, 2026 00:01

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt
tannewt merged commit 4435769 into adafruit:main Oct 15, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants