machine/usb: implement consistent device state transitions
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- embedded-iot, go
- 领域
- embedded-iot
调研方向
Start with src/machine/usb.go and compare its shared configuration and interface tracking with the USB 2.0 specification §9.1, Figure 9-1; then trace RP2040 driver handling, including interrupt paths and waits. Check how state changes interact with tasks and cores. Done means implementing consistent, synchronized state transitions and verifying that interrupt, endpoint, transfer, and wait handling respects them in both configurations.
由索引模型根据 Issue 内容生成。
描述
USB 2.0 Specification §9.1 (Figure 9-1) defines USB device states and their transitions. TinyGo's USB stack does not manage these states consistently. The shared code in src/machine/usb.go tracks configuration and interface selection but has no unified device state model. Some drivers handle parts of the state on their own, for example suspend handling in the STM32 OTG FS driver. Numerous USB-related issues have been reported, and incomplete state management may be a contributing factor.
Timeout-based waits and busy-wait loops are common across TinyGo's USB drivers. Some of these do not account for device state, so they can keep running after the state has changed.
Hang during Detach/Attach (#5651, #6085)
- With
tasks, a bus reset afterDetach()could make the E5 workaround wait for SE0 to end, which never happens with the pull-up off. The IRQ path didn't account for the detached state. #6085 addresses this. - With
cores, if core 1 callsDetach()after core 0 has passed the pull-up check added in #6085, core 0 stays in the SE0 wait loop until core 1 callsAttach(). @davecheney reported this in #6085, and it also reproduces ondev.
The tasks case shows this is not only a cores problem. Even on a single core, USB interrupts can preempt API calls while they update shared state. With cores, USB code can also run concurrently on both cores, and disabling interrupts on one core does not stop the other from changing shared state.
Proposed work
- Define and implement consistent USB device state transitions based on the USB specification.
- Make interrupt handlers, endpoint handling, and transfer processing respect the current state.
- Synchronize state transitions across interrupts and cores.
- Review timeout-based and unbounded waits, and replace them with state-aware handling where appropriate.
- Verify behavior with both
tasksandcores.
I plan to start with RP2040, where the problem has been confirmed.
The goal is to address the underlying state management problem rather than continue fixing individual symptoms.
References
- USB 2.0 Specification, §9.1, Figure 9-1
- #5651 (repeated Detach/Attach stalls)
- #6085 (fix for the
taskshang)
- 主要语言
- Go
- 星标
- 17.8k
- 派生
- 1.1k
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 380
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tinygo-org/tinygo 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
tinygo-org/tinygo#6727 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 86/100
tinygo-org/tinygo#6711 ·
维护者通常 1 天内回复
-
Builds are not reproducible: cgo snippet paths in debug info可能已有人在做 @tridev-tej 于 2 天前认领。 未关闭enhancement good first issue
难度 2/5 1-3 小时 新手友好度 78/100
tinygo-org/tinygo#6619 ·
维护者通常 1 天内回复
-
Fix the targets that tinygo build -target rejects可能已有人在做 @narguis 于 2 天前认领。 未关闭bug good first issue
难度 2/5 1-3 小时 新手友好度 74/100
tinygo-org/tinygo#6617 · 5 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 62/100
tinygo-org/tinygo#6312 ·
维护者通常 1 天内回复
查看 tinygo-org/tinygo 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
sresarehumantoo/cc-artex#456 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
factory:subtask
难度 1/5 1 小时以内 新手友好度 75/100
维护者通常 1 天内回复
-
release
难度 1/5 1 小时以内 新手友好度 75/100
github/gh-aw-mcpg#17603 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
bboerst/stratum-work#351 ·
维护者通常 1 天内回复