DMA, SPI and WS2812B

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Post Reply
User avatar
Neon22
Posts: 18
Joined: Fri Feb 28, 2014 11:53 pm

DMA, SPI and WS2812B

Post by Neon22 » Thu Sep 11, 2014 11:48 am

I see this approach on controlling sequences of the WS2812B RGB LEDs.
The clever part is usuing the DMA to push the pattern out to the strip of LEDs without CPU overhead. Leaving the CPU to make pretty patterns.
http://blog.gitmi.com/interfacing-ws281 ... -update-3/

I wonder if we can use our DMA, SPI this way ?
(FYI SPI at 500kHz)

Original SPI approach is from Elia (on STM32..):
- http://eliaselectronics.com/driving-a-w ... -an-stm32/
The DMA originally by OctoWS2811 Paul Stoffregen:
- https://github.com/PaulStoffregen/OctoWS2811

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: DMA, SPI and WS2812B

Post by dhylands » Thu Sep 11, 2014 2:26 pm

This approach: http://forum.micropython.org/viewtopic. ... S2812#p899 uses SPI.

The SPI code doesn't look like it has DMA support yet =, but when it does, then we'll be able to allow the CPU to do things while the DMA is occurring.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: DMA, SPI and WS2812B

Post by Damien » Mon Dec 08, 2014 9:39 pm

SPI now supports DMA for send, recv and send_recv. These functions wait for the DMA transfer to finish before returning. Perhaps there needs to be an option to return straight away?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: DMA, SPI and WS2812B

Post by dhylands » Tue Dec 09, 2014 5:06 am

Having an option to return right away seems sensible.

You'd need a way to determine when the transfer is done (by polling).

It would also be good to be able to register an IRQ callback that runs when the DMA completes.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: DMA, SPI and WS2812B

Post by Damien » Tue Dec 09, 2014 11:11 am

All these things are possible. I think the DMA even includes an irq for transfer half complete.

Could use select module to determine when transfer is complete (but that could be overkill for such a simple check).

I consider exposing DMA as an object, since it has so many options, but I think it might be better to have the DMA managed fully by the "OS" and assign fixed channels for each peripheral. Then expose DMA functionality only by keyword arguments to the relevant methods.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: DMA, SPI and WS2812B

Post by dhylands » Tue Dec 09, 2014 11:07 pm

I don't think that we need to expose DMA directly.

I think that just being able to register a SPI transfer complete callback would be fine.

Tying it in with select might make sense but probably only if the SPI worked with stream (or whatever select uses).

Post Reply