cancel
Showing results for 
Search instead for 
Did you mean: 

simple uart dma transmit for logs ?

Hvan .4
Associate II

Hello everyone,
I'm working on stm32f103.
I try to use HAL_uart_transmit_DMA, in a circular buffer for simple logs.
I created a circular buffer, on which I can write my strings.
the issue is... my circular DMA write it as as loop instead as finishing at the end of the string.
So if I write "Hello" wait enough time and "World" in 8 bit long buffer, I get:
"rld'\0'oWo" in loop.
I would have hope with some magic, dma would stop '\0', but it doesn't. This would be great option for ascii
I would have hoped dma would send the right interrupt sor it can be easy, but it's not.

I would appreciate any advice so that dma_tx in circular would work as circular buffer, but appropriate with logs.
I would love is those advice would use hal library instead of driver layer or register to keep it working between projetcs and chips.

2 REPLIES 2
DavidAlfa
Senior II

Cicular mode will do exactly that, it won't stop.

Normally it's used in a sort-of double-buffering with HT (Half transfer) and TC (Transfer complete) interrupts, so each half of the buffer is updated while the other half is being transmitted.

If you want it to stop automatically, use normal DMA, not circular.

It will issue the specified number of transfers and stop.

What you could do is have several buffers managed by the write fucntion, when one bufer is filled, configure and trigger the dma to send that buffer, then keep writing new data into the next buffer.

When transfer complete interrupt happens, check if you have more pending buffers and send them.

It's like qa circular miode, but handled in software. You can't have DMA stopping by itself on character match.

thanks, this is not great as using interrupt when I've loved to only fill a buffer.
I hoped to get a "pause" condition, either a char, a pointer or a count down... theses are quite easy to do in hdl.
Anyway, I'm using a mixture of DMA, IT, and fifo, it's not as great as I hoped but not so bad to optimise ram and speed.
Thanks for your feedback!