A panic inside an interrupt handler hangs USB CDC targets without a message
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 18/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- go
调研方向
The hang comes from putchar writing into machine.Serial (USBCDC), where USBCDC.Write calls gosched() and task.Pause then fails inside an interrupt. Start by reading the USBCDC Write path and internal/task.Pause, and reproduce with the four-case ISR program from the issue. Done means ISR panics and large prints produce output or a clean message without hanging, with the watchdog no longer required.
由索引模型根据 Issue 内容生成。
描述
On targets that use USB CDC for stdout, a panic inside an interrupt handler prints nothing and the board hangs. A print inside an interrupt handler that does not fit in the USB TX ring also hangs the board. This only happens when a host has the serial port open.
Reproduce
Tested on a Waveshare RP2040-Zero (-target=waveshare-rp2040-zero) with the port open in a terminal. The watchdog resets the board after the hang, so that it can be flashed again.
package main
import (
"device/rp"
"machine"
"runtime/interrupt"
"time"
)
var mode = "panic" // panic, big or small
var nilp *int
func handler(interrupt.Interrupt) {
rp.TIMER.INTR.Set(1 << 1)
switch mode {
case "panic":
println("isr: about to panic")
println(*nilp)
case "big":
println("isr: printing 600 bytes")
for i := 0; i < 600; i++ {
print("x")
}
println()
case "small":
println("isr: small print")
}
}
func main() {
machine.Watchdog.Configure(machine.WatchdogConfig{TimeoutMillis: 5000})
machine.Watchdog.Start()
time.Sleep(4 * time.Second)
interrupt.New(rp.IRQ_TIMER_IRQ_1, handler).Enable()
rp.TIMER.INTE.SetBits(1 << 1)
rp.TIMER.ALARM1.Set(rp.TIMER.TIMERAWL.Get() + 100000)
for i := 0; ; i++ {
println("main alive", i)
machine.Watchdog.Update()
time.Sleep(500 * time.Millisecond)
}
}
Results
| Case | Serial output | Board |
|---|---|---|
nil pointer panic in main (control) |
full panic message | stops, as expected |
| nil pointer panic in the ISR | nothing, not even the println before the panic |
hangs |
| 600 byte print in the ISR | nothing, not even the first line | hangs |
| 600 byte print in the ISR, port not open | nothing | runs |
| small print in the ISR | arrives after the ISR returns | runs |
Cause
putchar writes to machine.Serial, which is USBCDC. The data goes into the TX ring, and the USB interrupt sends it. Inside an interrupt handler the USB interrupt cannot run.
- Panic: the message goes into the ring, then
abort()loops onwfiin handler mode. The ring is never sent. - Full ring:
USBCDC.Writecallsgosched()to wait for space.task.Pauseseesinterrupt.In()and callsruntimeFatal("blocked inside interrupt").runtimeFatalprints through the sameWrite, which callsgosched()again.
When the port is not open, Write returns early and drops the data, so the board does not hang.
The same path exists for HardFault_Handler and for the nil and bounds check panics in runtime and machine interrupt handlers. It affects every target where stdout is USB CDC, for example samd21, samd51, rp2040, rp2350, nrf52840 and mimxrt1062.
How this was found
A prototype call graph check from interrupt handlers to runtime.alloc and internal/task.Pause reported the putchar → USBCDC.Write → runtime.Gosched path on all USB CDC targets. The prototype is on https://github.com/davecheney/tinygo/tree/isr-taint-prototype.
/cc @dgryski @rdon-key
- 主要语言
- 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 于 1 天前认领。 未关闭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 天内回复