Skip to main content
PCu1
Senior
July 1, 2020
Solved

Emul usart AN4457 issue

  • July 1, 2020
  • 14 replies
  • 4340 views

Hello,

Has anyone ever used the emulated usart provided by ST (AN4457) based on timer and DMA?

I need it for transmit, not for reception.

In my test, most of the time TX characters are corrupted, sometimes it works.

I checked with scope and it appears that the startBit is missing, but the rest of the byte is correct.

Here example with the 'a', white trace is the correct one, yellow is the measured trace.

0693W000001rvWYQAY.bmp

It seems that the Start bit is present in the 'calculated' buffer for DMA, but the timer overflow early...

Thank you,

Pierre

This topic has been closed for replies.
Best answer by waclawek.jan

Try to clear TIMx_DIER.CC1DE (__HAL_TIM_DISABLE_DMA(&TimHandle, TIM_DMA_CC1) ? I don't know, I don't speak the Cube/HAL gibberish) as the first thing in UART_Emul_DMATransmitCplt().

(It's equivalent to what TDK suggested with clearing the TIMx_SR register, except that with the DMA trigger signals rather than the interrupt trigger signals

https://community.st.com/s/question/0D50X00009XkaAtSAJ/how-to-clear-pending-dma-request

).

JW

14 replies

waclawek.jan
Super User
July 8, 2020

Fig 1 - DMA1 has no connectivity to AHB buses including the one where GPIO sits.

UART Tx can be implemented also in a different way, using a TIMx_CHy pin as output, toggling it using Output compare in Toggle mode with precalculated TIMx_CCRy values, autoloaded by DMA triggered by that same compare. That method can be pulled out using DMA1. It's the same as generating arbitrary waveform with timer - there are examples for that in Cube, and it's described in some appnote (maybe the timer cookbook?).

JW

PCu1
PCu1Author
Senior
July 9, 2020

Yes, you are right.

On figure 23 it is expanded:

0693W000001sVJaQAM.png

Thank you for the tips using Timer Channel + DMA. Not possible for the actual project but for the future it could be a solution.

Thanks again,

Pierre

mshoj.1
Visitor II
September 2, 2021

Dear ST commute

HI,

I want make echo serial with uart emulation.

I want receive data from terminal and send it back (echo) with DMA uart emulation.

I was use the AN4457 example code, the issue is when use receiver and transmitter for just once , everything is ok . but put this code in while for continuous echo , stm32 after echo first time will hang.

please guide me for find a solution. 0693W00000Dm1opQAB.jpg0693W00000Dm1riQAB.jpg 

Tesla DeLorean
Guru
September 2, 2021

>>stm32 after echo first time will hang. please guide me for find a solution.

Does it just go to the ErrorHandler() to die there? Perhaps handle the error conditions.

Might want to try a solution that receives data at an individual byte level, and concurrently sends back the byte(s) it has accumulated, rather than this larger buffer ping-pong arrangement you have now.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..