AnsweredAssumed Answered

Reading variable length strings from a usart with DMA

Question asked by Harvey White on Oct 5, 2017
Latest reply on Mar 15, 2018 by Harvey White

I need to read variable length strings from a usart.  The strings may be the result of local programming or not.  I'm using the HAL DMA receive driver under FreeRTOS.  I've found that the following approach works:

 

 

     HAL_UART_Receive_DMA(&huart3, (unsigned char*)&WIFI.RXbuffer.data, _RX_BUFFER_SIZE);
     xSemaphoreGive(WIFI_busy);

     while (WIFI.RXbuffer.data[0] == 0)
     {
         vTaskDelay(1);
     }
     comm_index = 0;
     while (comm_index != huart3.hdmarx->Instance->NDTR)
     {
         comm_index = huart3.hdmarx->Instance->NDTR;
         vTaskDelay(1);
     }

     // if was the result of a remote command, then command = AT_IP otherwise
     // it's from the send routine and is a valid command
     HAL_UART_AbortReceive_IT(&huart3);
     switch (WIFI.TXbuffer.command)

This works as follows:

1) clear WIFI buffer if needed

2) start DMA reception before programmed transmit

3) loop, delaying, until reception starts (allows remote to respond)

4) read NDTR in chip for this transaction.  NDTR starts high and decrements with each character transferred.  Set transfer limit to max buffer size.

5) loop waiting for NDTR to stabilize.  Note that this assumes variable length data transmitted in a burst (ESP8266 does).

6) abort reception to reset DMA flags and stabilize buffer

7) process data

 

comments?

Outcomes