stm32-rs / stm32g0xx-hal

Peripheral access API for STM32G0 series microcontrollers
Apache License 2.0
73 stars 51 forks source link

Make uart-dma example do repeated transfers #59

Closed ijager closed 3 years ago

ijager commented 3 years ago

The uart-dma example only did one transfer. I have adjusted it to do repeated transfers. However I am not sure if this is the right way to prime a new dma transfer.

Am I supposed to disable and re-enable the dma channel to issue a new transfer?

dma.ch1.disable();
dma.ch1.set_memory_address(tx_dma_buf_addr, true);
dma.ch1.set_transfer_length(tx_buffer2.len() as u16);
dma.ch1.enable();

So far this is the only way I managed to do a next dma transfer. Also setting the transfer length (number of bytes in this case) again seems to be a requirement, which makes sense I guess.

Is there another way besides dma.ch1.disable() ? For example when you're using the transfer-half-done event, I think the idea is to do non-stop dma transfers right?

andresv commented 3 years ago

So first half done interrupt means that first half of the bytes from tx_dma_buf_addr are transferred and you can write new bytes to this half. Next half done interrupt means that second half of the bytes are transferred and now you can fill this in. If new bytes are written with every half done interrupt DMA is hot and should transfer without pausing. Probably there are some fineprint details that must be done for this to actually happen.

ijager commented 3 years ago

I see, I guess you need to enable circular mode then

andresv commented 3 years ago

Yes circular mode must be enabled.

Just recently this came in where circular DMA transfers are used for ADC and actually also for UART: https://github.com/stm32-rs/stm32g0xx-hal/pull/58

andresv commented 3 years ago

This is still WIP right?

ijager commented 3 years ago

Not really, I think a circular-dma could be another example. The way this example works is exactly how I am using it now in a project, so I guess it is still a valid use case for periodic but not continuous transfers.

andresv commented 3 years ago

Thanks, then I am going to merge it.