Skip to content

CH34x: add RTS/CTS flow control, correct 307200 baud rate, and timeout - #642

Draft
midnight-wonderer wants to merge 3 commits into
mik3y:masterfrom
midnight-wonderer:fix/ch34x-improvement
Draft

CH34x: add RTS/CTS flow control, correct 307200 baud rate, and timeout#642
midnight-wonderer wants to merge 3 commits into
mik3y:masterfrom
midnight-wonderer:fix/ch34x-improvement

Conversation

@midnight-wonderer

Copy link
Copy Markdown

This PR introduces three improvements and fixes to the Ch34xSerialDriver:

  1. Implement Hardware RTS/CTS Flow Control:
    • Exposes RTS/CTS flow control capability by overriding setFlowControl and getSupportedFlowControl.
    • Programs the hardware flow control register 0x2727 (0x0101 to enable, 0x0000 to disable) matching standard controller behavior.
    • Initializes the configured flow control state on port opening in openInt().
  2. Add 307200 Baud Rate Exception:
    • Hardcodes the dedicated exception for 307200 baud (divisor = 7 and factor = 0xd900). This matches the divisor configuration used in standard operating system drivers, yielding much lower frequency deviation and more reliable communication at this rate.
  3. Fix Register 0x0f2c Packet Upload Timeout:
    • Register 0x0f2c controls the USB upload packet timeout, which determines how long the chip buffers received data before flushing.
    • Previously, the driver wrote the lower byte of the baud rate factor to this register. This resulted in excessively short timeouts at lower baud rates (e.g. writing 12 instead of 64 at 1200 baud), leading to premature packet flushes and unnecessary CPU overhead.
    • This is corrected to calculate the timeout as 76800 / baudRate (minimum 0x07, capped at 0xFF) and write this to register 0x0f2c.
      These changes have also been integrated into the device test suite (DeviceTest.java) by configuring the expected flow control lock state (ON_BUFFER_FULL) for CH34x.

@midnight-wonderer

Copy link
Copy Markdown
Author

Notes

The magic number 76800 is from the official driver.

Open Questions

@kai-morich I wonder if we should log timeout with Log.d?
And, what do we do with lower byte of the baud rate factor?

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.

1 participant