cancel
Showing results for 
Search instead for 
Did you mean: 

Mixing "normal Transmission" and DMA Transmission, with "normal RX interrupt handling"

ingwmeier
Senior

Maybe it is not supposed to be used like this:
Regular receive interrupt handler and using LL_USART_TransmitData8 function.
Then sending a larger configuration file using HAL_UART_Transmit_DMA on demand.

This leads to these flaws:
1. HAL_UART_Transmit_DMA activates TC Interrupt which is not handled, garbage is sent after endof DMA unless LL_USART_DisableIT_TC(USARTx) is called in the DMA interrupt.
2. next time  you try to start HAL_UART_Transmit_DMA does not work because of huartx.gState Busy flag, huartx.gState &= 0xfffffffe needs to done in the DMA interrupt. 
3. if implementing 1. and 2. The second time of sending the configuration file misses one character, if LL_USART_TransmitData8 has been used in between, because USARTx->CR3 is 0x00003080 after using DMA, setting it to USARTx->CR3 = 0x3000; prevents losing one character.

So I found "solutions" for these flaws, but I'm not happy with it.

 

2 REPLIES 2
Andrew Neil
Super User

So, as well as mixing "normal"  and DMA, you're also mixing LL and HAL ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I use HAL for setting up UARTS, for transmission I use LL_USART_TransmitData8 and for reception LL_USART_ReceiveData8 in the interrupt, this works in many projects with no problems.

I have not found HAL_UART_Transmit_DMA function example using LL, and since sending a 20kByte plus size configuration struct using DMA seemed to be quick and easy :)