UART DMA

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
TamirM
Level 2
Level 2
25 sign-ins First like given 10 questions asked

Hello,

I'm using printf override to send strings via RS232, it works well.

Now i'm trying to use DMA  to make those transactions but it doesn't work properly.

My code is based on the UART_DMA example with minor changes.

What am I missing?

Thanks in advance

0 Likes
1 Solution

Tamir,

Using DMA with UART makes sense only if long strings are being transmitted, or when data is being streamed continuously (like from ADC) in time-constrined application. If code has sufficient window for UART output, there is no need for DMA. If standard printf works - don't use DMA. An example code above using DMA is likely slower than the standard UART API.

       If you really need a DMA, then SCB UART should have DMA output enabled in the Advanced tab, and output pin connected to the DMA component. The DMA should be configured for level sense. As long the UART Tx buffer not empty, the output pin will stay high, forcing DMA to push data into Tx buffer, until full.  It this case the _write() call is not needed, but DMA have to be configured for each string if the lengths of the strings are different. So for short messages it may not worth the effort. 

View solution in original post

0 Likes
3 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @TamirM 

 

The _write function passes the char pointers one by one so the advantage of using DMA is minimum. To get the current code working, you can add a waiting statement in the _write function - 

int _write(int file, char *ptr, int len)
{
    file = file;    // Mask warning

//    TxDMA_SetDataElementSize(0, len); // ???
//    UART_UartPutString(ptr);
    // Wait till Tx Fifo is not full
    while(UART_SpiUartGetTxBufferSize() > 6);
    TxDMA_ValidateDescriptor(0);
    TxDMA_SetSrcAddress(0, ptr);
    TxDMA_ChEnable();
    
    return (len);
}

 

You can also implement this without printf so that the entire transaction can occur without CPU intervention. 


Best regards, 
Hari

0 Likes
TamirM
Level 2
Level 2
25 sign-ins First like given 10 questions asked

Hi @Hari,

Thank you very much for your response.

unfortunately, i can't hold my code in any point, and waiting will make the use of the DMA redundant.

 How do you suggest to implement this without 'printf 'so that the entire transaction can occur without CPU intervention?

Thanks,

Tamir

0 Likes

Tamir,

Using DMA with UART makes sense only if long strings are being transmitted, or when data is being streamed continuously (like from ADC) in time-constrined application. If code has sufficient window for UART output, there is no need for DMA. If standard printf works - don't use DMA. An example code above using DMA is likely slower than the standard UART API.

       If you really need a DMA, then SCB UART should have DMA output enabled in the Advanced tab, and output pin connected to the DMA component. The DMA should be configured for level sense. As long the UART Tx buffer not empty, the output pin will stay high, forcing DMA to push data into Tx buffer, until full.  It this case the _write() call is not needed, but DMA have to be configured for each string if the lengths of the strings are different. So for short messages it may not worth the effort. 

0 Likes