DMA with five SPI ports simultaneously - Page 1
Forum section: electronics / general

author: luiHS
author_rank: Frequent Contributor
timestamp: April 01, 2022, 06:18:08 am
content: HiI have no experience with DMA, and I need to develop a project with five SPI ports using DMA. It's just about sending data to control WS2812 LEDS.Is it possible to send data through five SPI ports at the same time using DMA? I will use RT1064 microcontrollers.

author: TomS_
author_rank: Frequent Contributor
timestamp: April 01, 2022, 06:30:52 am
content: If you have 5 SPI peripherals and 5 DMA channels available it should be possible.

author: luiHS
author_rank: Frequent Contributor
timestamp: April 01, 2022, 07:01:17 am
content: Quote from: TomS_ on April 01, 2022, 06:30:52 amThe RT1064 has 32 eDMA channels. Does this mean that it can run 32 simultaneous processes per DMA?.It also has 4 x SPI and 1 x FlexSPI.

author: pcprogrammer
author_rank: Super Contributor
timestamp: April 01, 2022, 08:20:50 am
content: Quote from: luiHS on April 01, 2022, 07:01:17 amThis means that you can have 32 DMA transactions running in total. A single channel can do a single task.It does mean that with the 5 available SPI interfaces you will be able to do your DMA setup, as long as it is possible to route the requests of the 5 SPI interfaces to different DMA channels. With the 128 sources muxible onto the 32 channels you should be ok.Find your self the manuals for programming this device and see what you have to do to set it all up.

author: newbrain
author_rank: Super Contributor
timestamp: April 01, 2022, 08:37:38 am
content: As pcprogrammer says. it should be possible, given also the relatively slow SPI speed if used for WS2812 control (about 6.4 MHz if 8 bits per WS2812 "bit" are used, but it's probably possible to go lower using 4 bits/bit).In an SDR home project with a iMX RT1021 we are simultaneously using two DMA channels for I2S in and out (up to 384 kS/s, L+R channels), one for SPI out at 45 MHz, and one for memory to memory moves at a handful of milliseconds interval.If you are using the NXP SDK, and especially with freeRTOS adapted drivers (not sure you are using it), there'sa lotof overhead.I have stripped the drivers to the bare minimum, building your own TCD (transfer control descriptor) and using direct register access will ease the CPU load a lot - the eDMA controller in this series is not outlandishly difficult to use.Also, remember to check what is the best priority grouping and scheduling algorithm for your use case to avoid channels starving each other (should not happen, given the speed).Eta:WAIT!isn't the FlexSPI used only for the external flash? I'm not sure you can use it (at least, this is on the 1021).Still, you have three FlexIOs that can be repurposed to SPI - or something more WS2812 friendly, maybe.

author: PlainName
author_rank: Super Contributor
timestamp: April 04, 2022, 09:38:04 pm
content: An alternative might be using GPIO to drive up to 8 LED signals at once. You'd use a timer to trigger the DMA which would just do memory to GPIO on each tick. However, the downside is that each DMA transfer is a bit (specifically, 8 off parallel bits) rather than byte, so you'd need to organise the source data as bytes of bitstream, orthogonal to source used to drive SPI. The plus side is each stream is synced to each other and you only need one DMA channel (and one GPIO port).

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 04, 2022, 09:48:43 pm
content: Quote from: luiHS on April 01, 2022, 06:18:08 amIf you're using the RT1064, I'd suggest looking at FlexIO. You should be able to generate signals for even more than 5 strings of those LEDs concurrently.And you can sure couple this with DMA.It's basically the idea just above, but with FlexIO, you can devise something very efficient.

author: hans
author_rank: Super Contributor
timestamp: April 05, 2022, 08:26:56 am
content: Sorry if I'm too divergent thinking in this solution.. reason I post because IMO SPIs are quite valuable periperhals, and using them for LEDs sounds a bit overkill....On other MCUs I've successfully used timers to control WS2812B LEDs. After all, it's a PWM with about 1/3 and 2/3 duty cycle to send 0s and 1s.On a PIC32MX250 I've done this with the 2ch of DMA, 2x output-compare on 1 timer to control 2 LED strings. Should be easy to scale it far further.. (up to the limit of PWM/DMA channels)If the duty cycle of each LED string is no where near 50% , you can perhaps also use a multiplexer (perhaps in the MCU if it has alternative pin locations) to switch 1 control channel between multiple strings. The data is then sent sequentially in time, but if a slight delay is not an issue, then that's very possible.Then finally if you really do need in the other of 5 or more LED strings.. perhaps DMA'ing into 8 bits of a GPIO port is a possibility? Again use a timer to chop up the time base in 3 or 4 sections to send the normal PWM cycle with data over it. I think mikeselectricstuff has a video of that concept on YT with a PIC32.I've not familiarized myself much with the RT micros. Perhaps I should get a Teensy. That FlexIO peripheral sounds interesting.