Skip to content

Commit 9966dc3

Browse files
committed
fix: ESP32-C3 needs to clear MCAUSE after handling interrupt
MCAUSE was never being cleared after handling an interrupt. On RISC-V, mret does NOT zero MCAUSE — it retains the last trap cause. Every other TinyGo RISC-V target (FE310, K210, QEMU) explicitly does riscv.MCAUSE.Set(0) after handling. The ESP32-C3 was missing this. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent ba88db0 commit 9966dc3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/runtime/interrupt/interrupt_esp32c3.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ func handleInterrupt() {
201201
reg.Set(thresholdSave)
202202
riscv.Asm("fence")
203203

204+
// Zero MCAUSE so that interrupt.In() returns false once we
205+
// return to normal (non-interrupt) code. Other RISC-V targets
206+
// (FE310, K210) do the same.
207+
riscv.MCAUSE.Set(0)
208+
204209
// restore MSTATUS & MEPC
205210
riscv.MSTATUS.Set(mstatus)
206211
riscv.MEPC.Set(mepc)

0 commit comments

Comments
 (0)