embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.37k stars 744 forks source link

embassy_stm32: How to send a large amount of the same data using SPI? #3399

Open jmjoy opened 1 week ago

jmjoy commented 1 week ago

I am using an SPI LCD screen, one of the operations is to full the screen, which is actually writing the same color data as the number of pixels on the screen.

Using the SPL library, the SPI DMA channel can be set up like this:

DMA_InitTypeDef DMA_InitStructure;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
// ...
DMA_Init(DMA_CHx, &DMA_InitStructure);

Because the memory address does not increase, the specified amount of the same data will be written to MOSI.

But I can't find a similar method in embassy_stm32::spi::Spi. It can be done using write, but if the screen pixels are large, the stack will explode, and using the heap is not advisable.

I hope there will be something like:

async fn write_n(&mut self, data: Word, n: usize) -> Result<(), Self::Error>;
showier-drastic commented 1 week ago

You can open a relatively small array (such as 32bytes), and send it repeatedly.

jmjoy commented 1 week ago

You can open a relatively small array (such as 32bytes), and send it repeatedly.

This is a good solution for the current situation.