machine/usb: implement consistent device state transitions

Abierto
#6,253 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
embedded-iot, go
Área
embedded-iot

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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 after Detach() 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 calls Detach() after core 0 has passed the pull-up check added in #6085, core 0 stays in the SE0 wait loop until core 1 calls Attach(). @davecheney reported this in #6085, and it also reproduces on dev.

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

  1. Define and implement consistent USB device state transitions based on the USB specification.
  2. Make interrupt handlers, endpoint handling, and transfer processing respect the current state.
  3. Synchronize state transitions across interrupts and cores.
  4. Review timeout-based and unbounded waits, and replace them with state-aware handling where appropriate.
  5. Verify behavior with both tasks and cores.

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 tasks hang)
Lenguaje dominante
Go
Estrellas
17.8k
Forks
1.1k
Merge medio
1 d 4 h
PR fusionados (30 d)
380

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tinygo-org/tinygo

Todos los issues de tinygo-org/tinygo

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.