Skip to content

Fix serial file transfer on macOS and 3rd party serial tool - #3248

Draft
zxkmm wants to merge 2 commits into
portapack-mayhem:nextfrom
zxkmm:SERIAL_FILE_TRANSFER_FIX
Draft

Fix serial file transfer on macOS and 3rd party serial tool#3248
zxkmm wants to merge 2 commits into
portapack-mayhem:nextfrom
zxkmm:SERIAL_FILE_TRANSFER_FIX

Conversation

@zxkmm

@zxkmm zxkmm commented Jul 5, 2026

Copy link
Copy Markdown
Member

IMPORTANT

Merge this firstly, and merge portapack-mayhem/MayhemHub#108 after next mayhem FW release.

Brief description of what you did

  • Fix serial file transfer on macOS and 3rd party serial based tool.

Proof that your changes work

In discord channels

🖥️ Proof it compiles

Space remaining in flash ROM: 5044 bytes ( 0.5 %)

📱 Proof of testing on a real device

maintainer bypass

📡 Proof against a real emitter/receiver (if applicable)

maintainer bypass


📚 Wiki documentation commitment

  • I will (or already) create(d) wiki document for my newly added feature

Checklist

  • Kept changes minimal and limited to necessary files
  • Verified functionality remains intact and code compiles
  • Attached proof that the code compiles successfully (or marked N/A as a trusted contributor)
  • Attached proof of testing on real PortaPack hardware (or marked N/A as a trusted contributor)
  • Attached proof of testing against a real emitter/receiver (if RF-related), or marked N/A with justification
  • I understand that by getting this PR merged, I am implicitly agreeing to create or update the corresponding wiki page (including a main-screen screenshot, description, controls, and limitations)
  • I own all rights to this code (i.e., all code contained in this PR), including compliant usage rights for third-party libraries, and I agree that this code is licensed under the license of this project (GPL-3.0).
  • If any third-party libraries are used, I confirm that their licenses comply with the requirements for contributing to this repository.
  • Reviewed the Contributing Guidelines

@zxkmm
zxkmm marked this pull request as ready for review July 5, 2026 08:59
@zxkmm
zxkmm requested a review from Copilot July 5, 2026 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the USB serial (CDC-style) implementation to behave correctly with USB 2.0 high-speed bulk requirements and with host tools (notably macOS and some third‑party serial utilities) that are stricter about packet sizing, ZLP termination, and CDC control requests.

Changes:

  • Make high-speed bulk endpoints compliant by using 512-byte wMaxPacketSize and matching transfer buffer sizes.
  • Fix TX/RX transfer robustness by ensuring USB DMA buffers outlive the scheduling call (avoid stack-backed buffers) and by increasing bulk OUT queue depth.
  • Improve host interoperability by enabling ZLP for bulk IN, treating configuration/line coding as “channel opened”, and returning a proper GET_LINE_CODING payload.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
firmware/application/usb_serial_shell_filesystem.cpp Avoid stack overflow in binary SD write by moving the USB bulk buffer to static storage.
firmware/application/usb_serial_host_to_device.hpp Stop redefining bulk buffer size locally; rely on the shared USB serial header.
firmware/application/usb_serial_host_to_device.cpp Mark ISR-written transfer metadata as volatile for thread-context polling.
firmware/application/usb_serial_endpoints.c Document bulk IN queue constraint; increase bulk OUT queue depth to allow more in-flight reads.
firmware/application/usb_serial_device_to_host.h Increase bulk buffer / serial buffer sizing defaults to 512 to match HS bulk max packet.
firmware/application/usb_serial_device_to_host.c Replace stack TX buffer with static ping-pong buffers suitable for DMA lifetime.
firmware/application/usb_serial_descriptor.c Correct HS bulk max packet size (512) and fix endpoint descriptor comments/interval.
firmware/application/usb_serial_cdc.c Improve USB IRQ wakeup reliability; enable bulk IN ZLP; return/track CDC line coding; open channel earlier for tools that don’t assert DTR.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 32 to 34
#ifndef USBSERIAL_BUFFERS_SIZE
#define USBSERIAL_BUFFERS_SIZE 128
#define USBSERIAL_BUFFERS_SIZE 512
#endif

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i tested it and it behaves stable at this val.
this is a safe trade off, we have so many code that can stackoverflow anyway. and not worth to have the buffer static to waist RAM.


size_t size = (size_t)strtol(argv[0], NULL, 10);

chprintf(chp, "send %d bytes\r\n", size);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it is safe that max number of here could only be 100000, it is impossible to greater than INT_MAX and I believe the cast is not worth for more asm instructions it brings, i guess 1 more tick

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