Most efficient way to wait DMA's end of transmission

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

Most efficient way to wait DMA's end of transmission

Post by kreyl »

My system: stm32f205RB, YAGARTO.
I need to transmit large amount of data using DMA.
I set up all related to DMA within a thread, started transmission - and what is the most efficient way to wait for completion?
dmaWaitCompletion() is a loop waiting for data count to become zero. As far as I understand, OS will keep the thread active until time will come to switch to another thread. In other words, OS will spend a full timeslot for the thread, performing silly polling check.
In this particular case, interrupt is not convenient.
What can I do to check that DMA is still busy, and if yes, then "release" thread? OS could handle other threads this time.
Thank you in advance!
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Most efficient way to wait DMA's end of transmission

Post by Tectu »

What exactly do you mean by "transmitting a large amount of data"? Internally? By that sentence I guess it's out of or into the MCU. Therefore I guess you must be using some peripherial such as SPI, right? Then you should notice that all the peripherial drivers of ChibiOS/RT do already use DMA where possible.
I know this might now answer your question, but it might maybe make your problem obsolete.


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Most efficient way to wait DMA's end of transmission

Post by Giovanni »

It depends.

Polling is convenient if you have to transfer data and then you have other things to do before you try to resynchronize with the DMA. Note that polling waiting the DMA can be a waste of CPU time or irrelevant depending on the thread priority in the system.

Alternatively you can enable a DMA callback and wakeup a thread from there, it is what most device drivers do, there is an overhead caused by the ISR and context switch but context switch is particularly fast in ChibiOS.

The "best" way largely depends on you scenario.

Giovanni
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

Re: Most efficient way to wait DMA's end of transmission

Post by kreyl »

Tectu:
Yes, I use USART6 to transmit data to another CPU. Value is 12 bytes or more; not that LARGE, especially for 115200 baudrate - but still several thousands of CPU instructions. I was under impression that serial drivers use interrupts, not DMA; interrupts is less efficient, therefore I decided not to use OS' driver. If I am wrong - please correct me :)

Giovanni:
My idea is to quickly prepare data to transmit, start DMA and then release thread - lazily checking time after time if transmission is completed.
May I ask you - where can I get information on how to suspend thread, and how to wake it up again? I would gladly use your suggestion with callback.
My threads are all static, by the way.

All: Thank you again!
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Most efficient way to wait DMA's end of transmission

Post by Tectu »

USART does use the DMA by default (at least on STM32?) but Giovanni might correct me.


~ Tectu
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Most efficient way to wait DMA's end of transmission

Post by Giovanni »

Hi,

Tectu is correct, there are two drivers using USARTs: UART (unbuffered with DMA) and Serial (buffered interrupt driven).

Giovanni
Post Reply