Search code examples
embeddeduartdmastm32f4discoveryhal

STM32F4-Discovery UART receive by DMA with included start-marker as well as an end-marker


Hi I am really new at embedded programming. I am using stm32cube IDE. I am trying to read a string to the DMA buffer but I need to implement start-marker as well as an end-marker. For example I only need to read the serial data in between '<' and '>' to the DMA buffer and when soon as it gets to the end-marker I want to call following call back function and process the data.

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 
{
  //Process Data 
}

I want this to run in the background all the time. Is this possible?


Solution

  • No, the DMA controller cannot check the value of the data and stop or interrupt when a delimiter or marker byte is received. The DMA controller can only copy the received byte to memory. If you want to read variable length packets between delimiters then you need to use the CPU to check whether each byte is a delimiter. You can use the UART's RX interrupt to check for the delimiter as each byte is received.

    DMA might be useful for receiving a continuous stream of bytes or a packet of known length.