0
votes

I have setup some my UART on the STM with DMA , and sometimes I tranceived UART data with the HALs DMA functions (HAL_UART_Transmit_DMA und HAL_UART_Receive_DMA) and sometimes with the HALs timouted functions (HAL_UART_Transmit und HAL_UART_Receive).

So far so good, now I asked myself, if I can transmit the data with the delayed functions and receive the response with the DMA functions (since my transmitted data is so short, but the answer is rather large and I could do some other calculations until I probably will have the answer).

My question basically is, if there is any reason not to mix UART non-DMA tx'es with DMA rx'es? Or is it just stylistically bad, or maybe just fine?

HAL_UART_Transmit(&huart5, com->cmd, com->cmdSize, timeout);
HAL_UART_Receive_DMA(&huart5, rfidBuffer, com->responseSize);

//some other stuff

while(!/*check if flag in HAL_UART_RxCpltCallback was set*/);
//process received data
1
yes, you can, there is not problem to configure receiver as DMA and TX without. also it depends what exactly MCU do you have, because there are quite different peripherals, especially USART, then we can provide more information.vlk
I am using a STM32L071 and I am using USART5. For me I am still struggeling to understand the timing of the response. It probably really depends heavily on the communication partner, but it seems sometimes I get the response, sometimes I just miss it. I just call the HAL tx rx, just one after the other. Can the HAL routine be to slow to be called beore the rx comes? Or could I also call the Receive DMA before the Transmit, so it definetly is set up before the answer comes? Thanks already for the approval of the general thing :)Paul Würtz
I'm not sure if it will be possible in HAL, but in general HAL is big overhead in comparison how the peripherals in STM's are simple to configure with direct register access.vlk
@PaulWürtz yes, starting receive DMA before transmit seems to be a good ideafollowed Monica to Codidact

1 Answers

1
votes

On STM32L0xx just enable in registers:

  • CR3: DMAR and not DMAT
  • CR1: TE, RE and UE

configure only one DMA channel for USART RX, then for receiving you will use DMA and for transmitting just write data into TDR register. (before TX also check TXE bit (Transmit data register empty) in ISR register).