apache / apache/nuttx

SPI/DMA issue with ws2812 driver

Open
#11,273 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

At each transfer, there is a TERR (transfer error) on the RX channel. I tried to put the MISO pin on idle/high/low but it has no effect.

According to SAMD21 Errata:
```text
1.7.2 Linked Descriptor

When at least one channel using linked descriptors is already active, enabling another DMA channel (with or without
linked descriptors) can result in a channel Fetch Error (FERR) or an incorrect descriptor fetch.
This occurs if the channel number of the channel being enabled is lower than the channel already active.

Workaround

When enabling a DMA channel while other channels using linked descriptors are already active, the channel number
of the new channel enabled must be greater than the other channel numbers.`
```

In the spi driver, in the description and in the code it is always Tx and then Rx except in one place where it is Rx and then Tx which could lead in the FERR according to Errata

I think it would be better to swap Rx/Tx in the following code:

```c
static void spi_dma_setup(struct sam_spidev_s *priv)
{
/* Allocate a pair of DMA channels */

priv->dma_rx = sam_dmachannel(DMACH_FLAG_STEPSEL_PERIPH|
DMACH_FLAG_BEATSIZE_BYTE |
DMACH_FLAG_MEM_INCREMENT |
DMACH_FLAG_PERIPH_RXTRIG(priv->dma_rx_trig));
priv->dma_tx = sam_dmachannel(DMACH_FLAG_STEPSEL_PERIPH|
DMACH_FLAG_BEATSIZE_BYTE |
DMACH_FLAG_MEM_INCREMENT |
DMACH_FLAG_PERIPH_TXTRIG(priv->dma_tx_trig));

}
```
into

```c
static void spi_dma_setup(struct sam_spidev_s *priv)
{
/* Allocate a pair of DMA channels */

priv->dma_tx = sam_dmachannel(DMACH_FLAG_STEPSEL_PERIPH|
DMACH_FLAG_BEATSIZE_BYTE |
DMACH_FLAG_MEM_INCREMENT |
DMACH_FLAG_PERIPH_TXTRIG(priv->dma_tx_trig));

priv->dma_rx = sam_dmachannel(DMACH_FLAG_STEPSEL_PERIPH|
DMACH_FLAG_BEATSIZE_BYTE |
DMACH_FLAG_MEM_INCREMENT |
DMACH_FLAG_PERIPH_RXTRIG(priv->dma_rx_trig));
}
```

I can make a PR but it does not change anything in my case, I still get TERR.

Could disabling the DMAC_INT_TERR interrupt be a way around? when I disable it nsh is not showing up.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.