Skip to content

fix(minihub): fix USB CDC 64-byte packet tail overflow, 0xFF header collision, and 30Hz serial overrun - #16

Open
spf13 wants to merge 1 commit into
hello-nexus:mainfrom
spf13:fix/minihub-lighting-flicker
Open

spf13 wants to merge 1 commit into
hello-nexus:mainfrom
spf13:fix/minihub-lighting-flicker

Conversation

@spf13

@spf13 spf13 commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

Fixes LED flickering, wrong/shifted RGB colors (pink/tie-dyed fans), and missed device topology updates on the iBUYPOWER MiniHub (VID_3402&PID_0900, firmware 1.0.1.1).

Root Causes (Proven via Firmware 1.0.1.1 minihub.bin Disassembly & Live Hardware Verification)

  1. USB CDC 64-Byte Continuation Buffer Overflow (CDC_Receive_FS at 0x0801AC50..0x0801B1E8):
    • Firmware copies Buf[0..*Len-1] into its 64-byte rx_buf (0x20000258) without clearing rx_buf[*Len..63], and its continuation loop copies all 64 bytes of rx_buf[0..63] into portN_buf regardless of *Len or 150/300-byte buffer bounds.
    • For Channels 1-3 (157 = 64 + 64 + 29 bytes), Packet 3 (*Len = 29) left rx_buf[29..63] populated with Packet 2's LED bytes and overflowed 33 stale bytes (shifted by (95 - 7) % 3 = 1 GRB component -> Pink #C80032 for Blue #0032C8) into port(N+1)_buf[0..32].
    • For Channel 4 (307 = 64*4 + 51 bytes), Packet 5 (*Len = 51) overflowed rx_buf[51..63] (13 bytes) past port4_buf[299] (0x20000643) directly into pwm_buf[0..6] (0x20000644..0x20000650), corrupting the 60-halfword WS2812 0V reset preamble (which build_pwm at 0x0800CC48 never clears after power-on).
    • Fix: MiniHubHub.WritePacketized now sends lighting stream frames in explicit 64-byte zero-padded chunks with high-resolution Stopwatch.GetTimestamp() pacing (5 ms inter-chunk, 25 ms post-latch after Channel 4), and ScrubLightingSramIfSerial zeroes port3_buf, port4_buf, and pwm_buf[0..59] when entering RgbModeSoftware.
  2. In-Payload 0xFF Header Collision:
    • Firmware checks rx_buf[0] == 0xFF && rx_buf[1] == 0xEE && rx_buf[2] == 0x03 at packet boundaries; clamping LED channel bytes to 0xFE (MaxLedChannelByte) in MiniHubProtocol.BuildLightingStream prevents LED payload bytes at 64-byte packet boundaries from matching 0xFF command headers.
  3. Full 4-Channel Cycle Deduplication & 10 Hz Pacing:
    • Firmware only sets led_update_flag = 1 (0x20000090) on Channel 4 (FF EE 03 04) and re-latches all 4 ports together in main(). MiniHubLightingFrameWriter now stages and writes all 4 channels as an atomic cycle under MiniHubHub.IoLock, deduplicates unchanged static frames (with 1 confirmation cycle), and caps continuous animation streaming at 100 ms (10 Hz).
  4. Device Topology Refresh on Connect & Zone Resize:
    • MiniHubHeartbeatWorker now notifies MiniHubLightingDeviceProvider.OnHubStateUpdated() on connect/disconnect (matching Np50HeartbeatWorker), and SetZoneLedCount invokes DevicesChanged so LightingEngine immediately updates its DeviceFrame set.

Verification

  • dotnet test (77/77 MiniHub & HubWorker tests passing).
  • Live hardware verification on iBUYPOWER MiniHub (COM3, FW 1.0.1.1) across Front 3, Rear, Top, and CPU fans.

@spf13
spf13 force-pushed the fix/minihub-lighting-flicker branch from 81dc1fa to bfdca3d Compare October 22, 2026 18:43
@spf13 spf13 changed the title fix(minihub): deduplicate and pace lighting frames to prevent LED flicker fix(minihub): fix USB CDC 64-byte packet tail overflow, 0xFF header collision, and 30Hz serial overrun Oct 22, 2026
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