wiring/usbserial: add multi-byte USBSerial write overload#2925
Open
TJett wants to merge 1 commit into
Open
Conversation
Add USBSerial::write(const uint8_t*, size_t) so Serial.write(buf, len) does not fall back to Print::write() byte-by-byte.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Essential the same class of issue as 2924.
Serial.write(buf, len)onUSBSerialdoes not use a native buffer-write path. It falls back toPrint::write(const uint8_t*, size_t), which iterates throughwrite(uint8_t)one byte at a time.On P2 / Photon 2 this causes buffered USB Serial writes, including writes performed through
SerialLogHandler, to be fed into the HAL one byte at a time, which makesSerial.write(buf, len)take much longer than expected.Solution
Add a native
USBSerial::write(const uint8_t* buffer, size_t size)overload and route it to a publicHAL_USB_USART_Send_Data_Buffer()HAL entrypoint. Onrtl872x, that entrypoint is implemented as a thin wrapper around the existingHAL_USB_USART_Send_Data_Multiple()bulk transmit path.Files changed:
Steps to Test
Application-level testing on P2 / Photon 2:
Log.write(buf, len)usingmicros().Expected results:
When running the example code below, I got the following results:
Before, on 6.4.1:
After:
Over a 100x speedup! From effectively 4 kB/s to 400 kB/s through the log handler
I also ran
wiring/usbserialwiring/no_fixture/Example App
References
AI Disclosure
I used Codex/GPT-5.4 to assist me in making this PR.
Completeness