AnsweredAssumed Answered

UART DMA Rx with variable length: Is HAL_DMA_Abort() not working?

Question asked by Lars Beiderbecke on May 20, 2018
Latest reply on May 21, 2018 by T J

Like many before, I'm trying to receive data with variable length, in particular responses from an ESP8266.


My idea is to look into the stream of received bytes to find an occurrence of "OK" or "ERROR".  My first version used polling, but eventually I need to use DMA. This is my (simplified) code now:


// check AT command
HAL_UART_Receive_DMA(&huart7, buffer, 24);  // 24 is max response length
HAL_UART_Transmit_DMA(&huart7, "AT\r\n", 4);
int found = 0, count = 0;
while (count++ < 2 * timeout) {  // timeout in seconds
  if (strfind(buffer, "OK")) {
    found = 1;
    break; // found
HAL_DMA_Abort(&hdma_uart7_rx); // abort pending receiver

// set to station mode
HAL_UART_Receive_DMA(&huart7, buffer, 24);
HAL_UART_Transmit_DMA(&huart7, "AT+CWMODE=1\r\n", 13);
found = count = 0;
// while() and so on


This works for the first ESP8266 command (no matter which one I choose), but not for subsequent commands, where the buffer just remains empty.


Why does my program break from one command to the other? The timeout is chosen appropriately. My only explanation would be that HAL_DMA_Abort() doesn't, although the description reads as if it should work.


(The very same thing happened with my polling code, but in that case I assume my code just missed the crucial bytes.)