Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.6k
windows: Add machine.UART support for serial COM ports.#18533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
Implement machine.UART class for Windows port, providing access toserial COM ports with an API compatible with other MicroPython ports.Features:- Support for COM1-COM255 via integer or string identifier- Standard UART parameters: baudrate, bits, parity, stop, flow control- Configurable timeouts (timeout, timeout_char)- Configurable buffer sizes (rxbuf, txbuf)- Stream protocol support (read, write, poll, flush)- UART.list() class method to enumerate available COM ports- sendbreak() and readchar()/writechar() supportImplementation uses Win32 API (CreateFile, DCB, COMMTIMEOUTS) withthe MICROPY_PY_MACHINE_UART_INCLUDEFILE pattern for integration.Signed-off-by: Konstantin Kim <kimstik@gmail.com>
codecovbot commentedDec 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@## master #18533 +/- ##======================================= Coverage 98.38% 98.38% ======================================= Files 171 171 Lines 22300 22300 ======================================= Hits 21939 21939 Misses 361 361 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
- Fix UART.list() to check ERROR_NO_MORE_ITEMS specifically and skip entries that fail due to buffer too small instead of breaking early.- Make sendbreak duration baudrate-dependent (13 bit periods) like rp2.- Disable DTR by default to avoid resetting Arduino/ESP devices.- Add UART_PORT_NAME_MAX constant for consistent buffer sizes.- Remove DEFAULT_UART_* macros, use inline values in one place.- Add comments for flow control flags and buffer sizes.Signed-off-by: Konstantin Kim <kimstik@gmail.com>
c65fec6 toeda90cdCompareno loopback requirementSigned-off-by: Konstantin Kim <kimstik@gmail.com>
Josverl commentedDec 11, 2025
Should there be an option to filter out the Bluetooth serial.? Bluetooth serial: when Windows creates outgoing/incoming RFCOMM ports, they appear as COMx and are listed in the registry. AFAIK the registry does not provide sufficient detail for that. |
kimstik commentedDec 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Good idea — could be added to a TODO/wishlist for post-merge enhancements (e.g. UART.list(bluetooth=False) or similar). |
RegEnumValueA already returns the string length in portNameSize,so strlen() call is redundant.Signed-off-by: Konstantin Kim <kimstik@gmail.com>
kimstik commentedDec 15, 2025
Josverl commentedDec 15, 2025
My point is that by choosing the registry API - this will not be possible other than by replacing it entirely with another API that does provide access to richer information. |
kimstik commentedDec 15, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Valid concern. Registry API (advapi32) indeed cannot distinguish Bluetooth ports. However:
Even pyserial has open PR#70 (since 2016) to add Registry support - SetupAPI misses virtual ports (com0com). PS, my short research- Registry : advapi32 WinNT+ - Sees busy ports. No metadata (can't filter BT). [libserialport, jSSC/Arduino, .NET Runtime, Sysinternals Portmon]- QueryDosDevice : kernel32 WinXP+ - Same issues + buffer guesswork. [-]- SetupAPI : setupapi Win2000+ - +50% code, slower - for metadata we don't need. [pyserial, node-serialport]- CreateFile loop : kernel32 Any - Slow, misses busy ports, side effects (DTR toggle). antipattern. [Tera Term legacy]- WMI : ole32+ Win2000+ - Massive complexity for no benefit. overkill |
Josverl commentedDec 16, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
My experience and feedback from mpflash users was that they did not want enumeration and connections to Bluetooth serial ports by default (Windows, Linux, nor Mac) , and want an opt-in for the edge cases. While enumeration and connection to all potential ports is different from single connection I think this view from the community is a relevant input. Thanks for sharing your research Filtering BT could be just using Pyserial, similar to themflash BT filter So I think this PR is a good starting point. |
Summary
Implement machine.UART class for Windows port, providing access to serial COM ports with an API compatible with other MicroPython ports.
Features:
Implementation uses Win32 API (CreateFile, DCB, COMMTIMEOUTS) with the MICROPY_PY_MACHINE_UART_INCLUDEFILE pattern for integration.
Testing
CI Testing:
Hardware Testing:
Skipped Tests:
extmod/machine_uart_tx.py- requires physical UART with loopback wiringextmod/machine_uart_irq_txidle.py- requires IRQ support (not implemented)Note:
mpremotebuild may fail in CI due to upstream issue withhatch-vcsversion detection in forked repository (not relatedto this PR).