STM32F4 Serial Port Forwarding Architecture

38 views Asked by At

System Architecture Diagram

Data Flow Diagram

The system consists of three modules: a 4G module, a GNSS module, and an STM32 processor, with the modules connected to the STM32 via UART. In terms of program functionality, the STM32 needs to implement data forwarding and saving. It receives data from the GNSS module, forwards it to the 4G module while creating a copy to save on the SD card; it also receives data from the 4G module, forwards it to the GNSS module while creating a copy to save on the SD card as well.

To achieve the above logic, I have used UART DMA、Ringbuf and Free-RTOS. UART DMA is set to DMA circular reception mode with HT, TC, and UART IDLE interrupt enabled. Data is first transferred to a fixed DMA Buff through DMA, then manually moved to Ringbuf in the callback function. In the processing function, data from Ringbuf is moved to the SD Ringbuf and to the sending Ringbuf. Corresponding operations, such as SD card writing and DMA sending, are executed in their respective threads.

This is roughly the framework of my code, which meets my requirements. I wonder if there's a better framework for forwarding UART data, allowing for more direct UART1 RX -> UART2 TX forwarding, and optimizing the whole process.

My question is, in the mentioned routine, if UART1 and UART2 have the same baud rate, and if UART1 is receiving data at full load, UART2's transmission experiences packet loss. I'm not sure where this problem occurs. Could there be a DMA conflict? Is it impossible for the same DMA bus to handle full-rate receiving and sending simultaneously? Also, in this scenario, should I use UART DMA FIFO? How should it be used?

0

There are 0 answers