machine: add a fast write-only SPI.Tx for STM32

Abierto
#6,409 1 comentario 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
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
64/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
embedded-iot

Línea de trabajo

Start by reading the generic Transfer()/Tx in src/machine/spi_tx.go, then the STM32 SPI implementation in src/machine/machine_stm32_spi.go where the new Tx should live. Use spi.tx() in src/machine/machine_atsamd21.go and machine_atsamd51.go as the model for the write-only split, and follow the transmit-only procedure in RM0090: write each byte when TXE is set, then wait TXE=1 and BSY=0 and drain DR/SR to clear OVR. Done when Tx(buf, nil) no longer waits per byte, the final BSY wait is preserved, and a display driver such as ili9341 still works on an STM32 board.

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

Descripción

STM32 targets that use machine_stm32_spi.go don't have their own SPI.Tx. They use the generic one in src/machine/spi_tx.go, which calls Transfer() once per byte. Transfer() waits for RXNE, then TXE, then BSY on every byte, so the bus goes idle between bytes. The comment in Transfer() already says so:

this will effectively prevent this Transfer() function from being capable of maintaining high-bandwidth communication throughput

SPI displays suffer the most (ili9341, st7789, st7735, ssd1351 and others), because almost all their traffic is long write-only bursts with Tx(buf, nil).

SAMD21 and SAMD51 already solve this. Their Tx has a write-only path (spi.tx() in machine_atsamd21.go and machine_atsamd51.go) that writes the next byte as soon as the data register is empty, and only waits for completion and drains RX at the end.

Proposal: give STM32 its own Tx with the same split.

  • Write-only (r == nil): write each byte to DR when TXE is set, without waiting for RXNE or BSY per byte. At the end, wait for TXE=1 and BSY=0, then read DR and SR to clear OVR. This is the transmit-only procedure from the SPI chapter of the STM32F4 reference manual (RM0090).
  • Read and read/write: keep the current per-byte behaviour for now, or pipeline them the same way later.

Waiting for BSY=0 once at the end keeps the current guarantee that the last byte is on the wire when Tx returns, so drivers that raise CS right after Tx keep working.

Background: tinygo-org/drivers#196 (2020) worked around this with an STM32F4-specific backend inside the ili9341 driver. The conclusion back then was that the fix belongs in the machine package, so every SPI driver on STM32 benefits and not only one display. I'm closing that PR in favour of this issue.

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.