← Back to Pull requests

hal: renesas: ra: r_usb_device: Add support for 5-pipe USBFS peripherals (RA2L2, RA2A1, RA4E2, RA6E2, RA6T3) #208

Closed
unknown closed this pull request without merging on May 22, 2026 00:52 UTC
View on GitHub
unknown unknown commented on May 02, 2026 21:04 UTC
Author

Add support for 5-pipe USBFS peripherals (RA2L2, RA2A1, RA4E2, RA6E2, RA6T3)

I'm a big fan of the FSP and Renesas hardware. I recently picked up an RA4E2 devkit for a project and ran into issues getting USB working out of the box. Digging into the driver, I noticed the 5-pipe USBFS variant wasn't supported, but most of the code was already in place, it just needed some hardware-specific touch-ups to handle the different pipe layout and FIFO access pattern.

Since I had some spare time over the weekend, I figured I'd try to fill in the gaps. The change is fairly minimal and gated behind a feature macro, so it shouldn't affect any existing supported boards.

Hope this is useful! Happy to make any adjustments based on your feedback!

Problem

The existing r_usb_device.c driver only supported the 10-pipe USBFS peripheral variant. On MCUs with the 5-pipe USBFS module (RA2L2, RA2A1, RA4E2, RA6E2, RA6T3), the driver failed in two ways:

1. Pipe allocation: find_pipe() returned pipe numbers (1–3, 8–9) that don't physically exist on 5-pipe hardware. According to the RA4E2 datasheet (Section 25.1), the 5-pipe USBFS module exposes only pipes 0, 4, 5, 6, and 7, with pipes 4–7 being configurable for endpoints.

2. FIFO access: The driver used the D0FIFO/D1FIFO ports for common-pipe data transfers. On the 5-pipe USBFS variant, common-pipe transfers must go through the CFIFO port instead.

Fix

Introduced a BSP_FEATURE_USB_HAS_PIPE04567 feature macro to gate the hardware-specific code paths. When set:

  • find_pipe() uses a 5-pipe lookup table:

  •   {0, 0},   // Control      → Pipe 0
      {0, 0},   // Isochronous: Not supported
      {4, 5},   // Bulk         → Pipes 4–5
      {6, 7},   // Interrupt    → Pipe 6-7
      

  • pipe_xfer_in() / pipe_xfer_out() / process_pipe_xfer() / pipe_wait_for_ready() route through CFIFOSEL / CFIFO / CFIFOCTR instead of D0FIFO*.
  • The original 10-pipe code path is preserved verbatim under #else, so existing supported MCUs are unaffected.

    Testing

    Verified the change works on both peripheral variants and does not introduce regressions:

  • 5-pipe USBFS — RA4E2 devkit (new support)

  • 10-pipe USBFS — RA8M1 (regression check)
  • Tested via USB CDC ACM sample code with bidirectional data transfer (host→device and device→host) confirmed working on both peripherals.

    Affected MCUs

    Adds support for these MCU groups (5-pipe USBFS):

  • RA2L2

  • RA2A1

  • RA4E2

  • RA6E2

  • RA6T3
  • Diff: 317 lines (+237 / -80) across 3 files Reviewer: Hoog-V Review duration: 27588m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 317 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.345
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #208"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.0% · Safe to merge
    16.0%