[riot-notifications] [RIOT-OS/RIOT] stm32: get bytes left to transfer via DMA and set transfer complete callback (#16440)

Sebastiaan de Schaetzen notifications at github.com
Tue May 4 18:41:42 CEST 2021


The scenario I'm in is the following: I'm expecting to approximately half a megabyte of data over UART at a baudrate of 1000000 (that's 1 MHz, not 100 KHz). As that is more data than I have memory available, I have to process it as it's coming in.

With RIOT's current API I'm having two issues:
 - The data I receive is of unknown size. It might be a nice multiply of my buffer, or it might not. Waiting for all data to be received using `dma_wait` could block forever, getting the bytes left using `dma_suspend` would pause the transfer, potentially resulting in data loss.
 - The external peripheral should not have to wait for the DMA controller to be reconfigured when it is full.

In order to work around the first issue, I added `dma_left`. This allows me to known how much data is already in the buffer (by taking the size of the buffer and subtracting the result of `dma_left`). Based on the contents of the received data, I can know whether I've reached the end or not.

In order to fix the second issue I added a function which lets me execute a callback when my receive buffer is full. I can then reconfigure the DMA controller to start writing back into the start of the receive buffer up to the read pointer. This essentially implements a circular buffer, but with the difference that it will stop the flow of data when my read pointer has not yet caught up (this happens when I do a lot of logging over a 115200 baud UART)

I hope this makes it a little clearer why I would like these functions, and I will definitily be fixing some of the race conditions I created in here tomorrow.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16440#issuecomment-832083939
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210504/a90879fe/attachment.htm>


More information about the notifications mailing list