cancel
Showing results for 
Search instead for 
Did you mean: 

UART DMA transmit works only one time

Thierry.1
Associate

Hello,

I got a problem with HAL library 10.4 for STM32L152RE in UART DMA transmission, the data is transmited only one time using the function HAL_UART_Transmit_DMA(&huart3,t_Buffer ,11) using uart3,  after that the UART3 structure keep the "flag" huart3.gState to HAL_UART_STATE_BUSY and all the other transmissions failed

it never come back to the  HAL_UART_STATE_READY so it is impossible to make another transmission.

 

I solve the problem by changing this flag state back to "ready" when transmission is done  using indirectly the (callback) transmission interrupt provided in  DMA1_Channel2_IRQHandler but it is not really a solution !! 

it should be OK once the data has been transmitted properly by HAL_UART_Transmit_DMA.

 

is it a bug in 10.4 HAL STM32L1 release ( maybe previous ones too ) or this behavior is normal and I need to use that "manual solution" ?

 

thanks

 

Thierry 

3 REPLIES 3
BarryWhit
Lead II

Look at HAL_DMA_IRQHandler, there is a section of code that handles an error interrupt raised by the DMA. Does a breakpoint there trigger?  If the DMA is reporting a transmission error, you want to find out why that's happening, not why the error isn't being automatically cleared by the HAL.

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.

I checked everything, including DMA and UART (should be USART because I use USART3 but it doesn't seems to be important, code has been generated by STM32CUBEMX !!!)

I make a mistake, it is HAL_UART_STATE_BUSY_TX not HAL_UART_STATE_BUSY the "flag" huart3.gState 

 

there are no errors in DMA, or in UART HAL processes, there is just something wrong when transmit is complete with DMA in normal mode, it sets the UART IT complete but only the circular DMA seems to put the "flaghuart3.gState to HAL_UART_STATE_READY

 

I checked for USART HAL library 10.4 and 10.3, it is the same behavior !!! 

So for now, I use indirectly the DMA1_Channel2_IRQHandler to reset the flag since the HAL_UART_TxCpltCallback seems to not working with normal DMA mode !!!

 

I don't know if it is the best solution, but at least it works (I don't know if properly !!)

Thierry 

I don't use Cube, but the general idea is, that after the DMA ended, the DMA IRQ Handler checks in DMA registers if the interrupt was Transfer Complete, and if so, UART_DMATransmitCplt() or equivalent is called (read: check the chain of events upon the DMA IRQ Handler/Transfer complete). That should set USARTx_CR1.TCIE bit, which when the stop bit of last byte is actually transmitted from USART, causes the USART IRQ Handler to be called, which has to call HAL_UART_IRQHandler() and that upon the USARTs_SR.TC flag calls UART_EndTransmit_IT(), which ultimately sets huart->gState = HAL_UART_STATE_READY; (read: check the chain of events upon the USART IRQ Handler/USARTx_SR.TC)).

In other words, once you use Cube/HAL, you have to play along all requirements Cube/HAL has on the user - and not all may be entirely documented. Clicking in Cube/MX should result in working solution, but not necessarily does if you don't follow the "just straighforward click from scratch" process, and/or modify any of the generated code.

Or, simply ditch Cube/HAL and just use that "manual solution".

JW