audit 0.21.0: Type-C/PD follow-ups

Open
#4,538 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
8/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c
Domain
embedded-iot

Research direction

Start by reading the four cited sites in src/typec/usbc.c (:138-140, :189-199, :208-226) and src/portable/st/typec/typec_stm32.c (:63, :319-335, :479-486), then the R1/R2 spec sections recorded in the details. Each item needs a protocol state machine (MessageID/ack/retry, TX buffer ownership, attach/detach event delivery, common revision) designed together, not a literal change. Done means repeated Request, retransmission, wraparound, Soft_Reset→GoodCRC→Request, busy-send, full-queue detach and both-peer-revision cases pass on a PD-capable board with an analyzer; no HIL board was available to the reporter.

Written by the indexing model from the issue text.

Description

follow-up Prio 📌

Deferred defects found in the repository audit of 0.21.0..ad7c83db8 (batch typec). Each was validated against the source at ad7c83db8 and judged real but too large, or too hardware-dependent, for the audit PR's contained fixes.

1. All Requests use MessageID zero; no acknowledgment-driven counter exists.
  • Where: src/typec/usbc.c:210,226; src/portable/st/typec/typec_stm32.c:319–335
  • Verdict: valid, with correction: Soft_Reset itself must use zero. After its matching GoodCRC, the next locally transmitted message uses the incremented counter. Repeated ordinary Requests also reuse zero. The claimed automatic local Hard Reset is unsupported: this stack has no such recovery engine.; introduced: Request defect is older; new Soft_Reset exposes another sequence requiring the missing state.; severity: medium
  • Hardware/spec dependence: Yes; verified by R1 below.
  • Overlap: None.
  • Remaining work and verification: Implement protocol MessageID/acknowledgment/retry/reset state together. Test repeated Requests, retransmission, wraparound and Soft_Reset→GoodCRC→Request; validate with a PD peer/analyzer. Simply incrementing on API calls is incorrect.
2. A second accepted send overwrites the shared buffer and pending send.
  • Where: src/typec/usbc.c:189–199; src/portable/st/typec/typec_stm32.c:322–335,479–486
  • Verdict: valid by source trace. With TX busy, Request stores _tx_buf plus length 6; Soft_Reset rewrites that buffer and replaces the pending length with 2. Both return true, and the Request is lost. The example does not itself call Soft_Reset, so this is an application-triggered API defect.; introduced: Older for repeated Requests; new mixed-message trigger.; severity: medium
  • Hardware/spec dependence: Pending-slot loss needs no hardware semantics. Active-DMA corruption and safe lifetime/retirement changes do; those are unverified.
  • Overlap: None.
  • Remaining work and verification: Define admission and buffer ownership before copying; preserve accepted messages or reject additional sends. Test busy-GoodCRC and busy-application-TX cases, completion/error/detach retirement, then validate on a PD-capable board.
3. Dropped detach event leaves callback state stale and suppresses the next attach.
  • Where: src/typec/usbc.c:138–140,249; src/osal/osal_none.h:196–207
  • Verdict: valid by causal source trace. OS-none uses a bounded, non-overwriting queue; failed enqueue is ignored. Starting from reported attached, losing detach leaves the state true, so a later attached event produces no callback. FreeRTOS ISR sends can fail similarly.; introduced: Yes for stale callback state; ignored queue failure is older.; severity: medium
  • Hardware/spec dependence: No hardware/spec premise required.
  • Overlap: None. #4163 and PR #4197 address interrupt ownership, not lost attachment events.
  • Remaining work and verification: Define whether the API guarantees every edge or eventual current state, then provide loss recovery accordingly. Test full-queue detach, drain, reattach and final-state delivery. Merely asserting enqueue success does not recover notification.
4. Request and Soft_Reset always advertise PD 3.0, including with a PD 2.0 peer.
  • Where: src/typec/usbc.c:208,224; src/portable/st/typec/typec_stm32.c:63
  • Verdict: valid for normal messages. Invalid as a complaint about the PD 2.0 GoodCRC field: the spec permits that value for responses to both PD 2.0 and PD 3.0 messages. Neither send layer adjusts the application header.; introduced: Request defect is older; Soft_Reset defect introduced by 78a54e2e7.; severity: medium
  • Hardware/spec dependence: Yes; verified by R2 below, including the GoodCRC exception.
  • Overlap: None.
  • Remaining work and verification: Maintain the common revision across Requests and Soft_Reset, with defined detach/hard-reset/error-recovery lifecycle. Test both peer revisions and reset sequences; verify emitted headers with a PD analyzer. Changing only the literal to PD 2.0 is insufficient.
Adjudication notes: typec

Claims still needing read-doc:

  • F3: For STM32G4 and STM32U5, what happens after TXSEND with TX DMA requests disabled, and after re-enabling requests/interrupts on attachment? Can pending TX complete or report an error, or is explicit cancellation required?
  • F4 / simplify F02: What precisely happens to each register written by dma_start() while its channel is enabled? Can an Rp-only change actually damage an ongoing receive, and would suppressing its rearm preserve recovery after detach, reset and queued RX completion? Finish G4 DMA/UCPD and U5 GPDMA/UCPD review, including applicable errata.
  • F2, proposed repair only: What event safely releases the transmit buffer on each driver variant, including cancellation and detach?
  • F10: Does enabling CC detection with an already-connected partner generate the event needed for initial notification on each supported variant?

The completed protocol claim records are:

  • R1 — verified: Calibre 1922, USB Power Delivery Specification Rev. 3.1 v1.8, §6.7.1, p.232; §6.12.2.2.1.3–7, pp.252–253; §6.12.2.3.2–5, p.258. Lookups a04ce8f6de96, da5875bc4935, e17e37570d23. These establish Soft_Reset ID zero, acknowledgment-driven increment and duplicate detection. The finding’s reference to §6.7.2 for duplicate detection was incorrect; that section concerns the retry counter.
  • R2 — verified / partly refuted: Same book, §6.2.1.1.5, p.111, lookup d6581b17d53f. Common revision persists through Soft_Reset; GoodCRC has an explicit exception permitting the driver’s value. No separate matching errata document was found by lookup 6d39db8ab38d.
  • Hardware claims remain pending: RM0440 book 3661, pp.402–403 and 2068, and G4 UCPD errata were read. U5 RM 3666 and errata were located, but full register-page and variant verification was not completed. These partial lookups do not verify the proposed hardware changes.

Checked all 190 open follow-up issues and 29 open PRs returned by the requested commands, plus a targeted open-issue search. “None” means no covering item found; the related locking issue/PR does not cover these findings.

No additional confirmed defect was found in the batch’s changes. Conclusions are source/document inspection, not runtime reproduction. No builds, tests or HIL ran; no suitable Type-C board appeared in the checked HIL rosters. HEAD remains ad7c83db8, and the checkout remains clean.

Dominant language
C
Stars
7.3k
Forks
1.6k
Avg merge
1d 19h
Merged PRs (30d)
67

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hathach/tinyusb

All issues in hathach/tinyusb

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.