cancel
Showing results for 
Search instead for 
Did you mean: 

UART DMA not working for some reason

Philip Westphal
Associate II
Posted on June 01, 2018 at 17:54

Hello again. I've been trying to get my mcu to transfer a buffer via UART to my computer with the help of DMA.

for some reason, it does not appear to be working. I think my computer recognizes it correctly just as when I am 

not using DMA but for some reason i am not receiving the information on my computer.  

Thank you very much for your help.

8 REPLIES 8
T J
Lead
Posted on June 01, 2018 at 22:15

Did you enable the Uart Interrupt ?

 and start the DMA ?

    HAL_UART_Receive_DMA(&huart1, (uint8_t *)Usart1RxDMABuffer, U1RxBufSize);

Posted on June 02, 2018 at 01:31

Thank you for your reply. I should have given more information. I apologize. I am using the discovery board for the stm32f072rbt6. I am trying to use the dma function to send values from the adc to my computer. It does work without dma (only hal_transmit_fs) but not with it.

To answer your questions. I did enable the Uart interrupt via Cube and I did start the dna. My main is attached to the original question as a text file. But just to be sure I have attached the settings below.

//start dma

HAL_UART_Transmit_DMA(&huart1, (uint8_t *)bufftr, sizeof(bufftr));

//Interrupt settings

0690X0000060L46QAE.png
Posted on June 02, 2018 at 03:26

I use this code to transmit if I have data in my Tx Buffer, much like your senerio.

   if (TxDMA1BufHasData) {

        char uartState = HAL_UART_GetState(&huart1);

        if ((uartState == HAL_UART_STATE_READY) || (uartState == HAL_UART_STATE_BUSY_RX)) {

            TxDMA1BufHasData = false;         // sending now

            if(HAL_UART_Transmit_DMA(&huart1, (uint8_t *)Usart1TxDMABuffer + U1TxBufferPtrOUT, U1TxBufferPtrIN - U1TxBufferPtrOUT) == HAL_OK) {

                U1TxBufferPtrOUT = U1TxBufferPtrIN;

                Usart1TxDMABuffer[U1TxBufferPtrIN] = 0;     // null terminator, not needed

:(

            }

            else {

                _Error_Handler(__FILE__, __LINE__); /* Transfer error in transmission process */

            }

        }

    }
Posted on June 02, 2018 at 11:04

I did enable the Uart interrupt via Cube and I did start the dna.

I don't use Cube so I don't understand what the above does mean and whether Cube prevents you somehow to shoot into foot, but normally you can't use both interrupts and DMA, as they work out of the same hardware flag (thus one clearing the flag prevents the other). I'd expect DMA being faster than interrupt though, prevailing in practical cases (although it's still wrong).

JW

Posted on June 02, 2018 at 12:59

In the cube, you can enable an interrupt with a checkbox, the cube sets it up in your initialization code.

I had to check the Uart1 interrupt before the DMA would function correctly.

For some reason HAL seems to need it.

I didn't add anything to the Uart interrupt,.

not sure why.

so much to do, I just moved on.

in another thread, This was the final fix for DMA Uart functionality. ( suggested by another engineer)

Posted on June 05, 2018 at 11:31

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6sy&d=%2Fa%2F0X0000000bxK%2FsRO42ndqch3_KcdGIvkdCYD8woZ2QD9gDdhEF3oLf4Y&asPdf=false
Posted on June 05, 2018 at 11:55

these should be zero .. when you get it going.

uint8_t U1TxBufferPtrOUT = 0;

uint8_t U1TxBufferPtrIN = 0;

your code looks good, what are you doing wrong ?

0690X00000604e9QAA.jpg
Posted on June 07, 2018 at 13:27

Thank you for your reply and sorry my late response. I tried setting it up as suggested, however it still does not work.

I will try to find a oscilloscope to test if data is actually being sent. 

Also, I set the device up as a CDC usb device. Could that be the reason why it does not work? I tried to do it without, however I am unsure how to receive the data on my computer without a virtual com port.