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.

Moderators: RoccoMarco, barthess

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

Most efficient way to wait DMA's end of transmission

Postby kreyl » Sun Feb 03, 2013 9:32 pm

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: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

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

Postby Tectu » Sun Feb 03, 2013 9:35 pm

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: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

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

Postby Giovanni » Sun Feb 03, 2013 9:42 pm

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
Contact:

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

Postby kreyl » Sun Feb 03, 2013 10:10 pm

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: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

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

Postby Tectu » Sun Feb 03, 2013 10:15 pm

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


~ Tectu

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

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

Postby Giovanni » Sun Feb 03, 2013 10:24 pm

Hi,

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

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 46 guests