2020-07-08 12:13 AM
Hi, I have the below code where I trigger the UART DMA and write to a buffer, and in the while loop I simply do a read from the buffer 1st element:
MX_UART7_Init();
Uartret = HAL_UART_Receive_DMA(&huart7, uartbuf, 300);
while(1){
if(Uartret == HAL_OK)
{
timeBuf[0] = uartbuf[0];
}
}
here is the uartbuf:
however if I remover the read line the 00s are will with values which I am expected.
Is there a way to read from dma on the fly ?
2020-07-09 12:24 AM
Unusual is the unconditional busy loop reading from memory in a potential race condition with the DMA in the above code pesented by the OP. That is totally independent of HAL or whatever you prefer to use.
2020-07-09 01:01 AM
yup in the debugger, I do read the mem out to a variable (timeBuf[0] = uartbuf[0];) and timeBuf is zero too.
yup I did that, and no zeros were found if it is only a empty while loop, so I wonder if we can read from DMA buffer without stopping the DMA.
2020-07-09 10:38 AM
Note that each message ends in a newline (0x0a). Use the uart character match interrupt with dma. When the character match interrupt happens, stop the dma, read the ntdr and calculate the size of the message and reset the ntdr and destination address. You can easily implement double buffering this way by alternating buffer pointers and using a global flag to keep track. With this method, you can receive the message completely in the background and get an interrupt when the last byte has arrived.
2020-07-12 08:19 PM
Do you have any example I can follow ?