- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
PSoC 4 MCU
- Tags:
- dma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.