cancel
Showing results for 
Search instead for 
Did you mean: 

Questions regarding using STM32 as a UART "relay"

StephanMair
Senior

Hi, our hardware engineer kinda messed up and I'm forced to use an onboard STM32C8T6 and lowball it as a UART "relay", basically UART1 reads whatever that's putting in with likely a buffer of 32 bytes, and immediately sends them out over UART3.

The dumb way to do it of course would be to use polling, a loop that keeps reading the buffer and then send things out, but I want to do it right, with speed and swag.

This is my plan:

UART1 reads stuff that fed to it, use DMA to house these data. This process should have minimal if anything, zero core processing unit involvement.

After the data got updated into the DMA RAM region, it immediately uses the DMA (yes, again) to push the data to UART3.

Sounds straightforward enough except I don't know how any of the DMA stuff works. I understand it will be lightening fast but how would I do it? Do I need to get interrupt and a handler involved?

Are there any ready made examples?

Please help, thanks in advance!

9 REPLIES 9
TDK
Guru

There are UART examples in the CubeMX repository for your chip.

> STM32C8T6

This isn’t a part. Missing some important digits.

If it’s strictly a relay, consider using an interrupt to send it directly to the other UART. If they are the same speed, this is bulletproof and avoids complexity of DMA buffers and handling.

If you feel a post has answered your question, please click "Accept as Solution".

its probably an stm32f103c8t6

we dont need to firmware by ourselves, lets talk
Javier1
Principal

This helped me to implement an UART->DMA thing

https://www.youtube.com/watch?v=Bo6MC5A8uTE

we dont need to firmware by ourselves, lets talk

This type of DMA needs more management than you're imagining.

Sending a block of data can decimate the interrupt loading, but you'll need timeouts on the reception.​

I'd probably do Interrupts on byte receive, or as a DMA ring buffer I swept periodically.​

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

Sorry, can't believe I missed the 103 part.

And in reality, I'm using STM32RET6. Just confirmed. My apologies.

Good thinking. I'll probably go with it since simple solutions often times are the best.

While we are at it... how does one do the interrupt handler thing? Do you have to register it at the initialization for the Rx UART or you just have to implement certain handler in the stm32f103x_it.c and enable the relevant interrupt? I'm guessing based on my experience it's the latter.

STM32F103RET6?

😂

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
S.Ma
Principal

If same baud rate, use 2 channels rx and tx and use each uart as dma trigger to read from o e and write without address increment on the other. This way, if baudrate is same and it works, only communication errors will generate interrupt from each peripheral. Would have been nice to have a crossbar mux in the mcu to get a simpler way with optional level shifting bonus if the mcu has vddio2 as well....