BIGTREETECH-TouchScreenFirmware icon indicating copy to clipboard operation
BIGTREETECH-TouchScreenFirmware copied to clipboard

Simple, efficient. fast, low resource DMA TX

Open kisslorand opened this issue 1 year ago • 2 comments

Requirements

BTT or MKS TFT

Description

This PR implements DMA transmit for serial ports as opposite to the current direct (CPU-managed) mode.

Direct Memory Access (DMA) for USART transfer is often considered better than direct (CPU-managed) USART transfers for several reasons. Those applicable to this TFT firmware are:

Offloading CPU: DMA allows the UART communication to occur with minimal CPU intervention. In a direct transfer, the CPU is typically responsible for managing data transfer, which can be resource-intensive and slow down other tasks the CPU needs to perform. With DMA, the CPU sets up the transfer and then lets the DMA controller handle the data movement, freeing up the CPU for other tasks.

Improved Efficiency: DMA controllers are specifically designed to handle data transfers efficiently, with minimal overhead. This can result in faster and more efficient data transfers, especially for larger chunks of data.

Reduced Latency: With direct transfers, the CPU may introduce additional latency in servicing USART requests, leading to delays in data transfer. DMA transfers can significantly reduce this latency, as they can handle data transfers without interrupting the CPU for each byte or character.

Consistency: DMA transfers provide a level of consistency and predictability in data transfer rates, which is beneficial in real-time or time-critical applications. CPU-managed transfers can vary in speed depending on the CPU's current workload.

Multi-Channel Capability: DMA controllers support multiple channels, allowing for concurrent data transfers between different peripherals or memory locations. This is particularly useful in complex embedded systems with multiple communication peripherals (read and write from/to several serial ports at the same time such as of WiFi module, printer, etc.)

Benefits

Based on real tests it frees up more than 20% of the CPU load during print.

Notes

  1. This PR was tested rigorously for a one week period for all the involved MCUs of this FW (even more, it was also tested on GD32F305VCT6 MCU too). However unforeseen bugs might be present so take it as it is, eventually report any bugs you might encounter related to the DMA serial transmission (here or on my repository).
  2. Anyone can feel free to "get inspired" in their own implementation.
  3. @rondlh gets the credit for kicking this in motion
  4. This PR is made mostly for reference for the changelog in my repository where people can have the precompiled FW for their printers with all improvements that the FW of this repository lacks. It's also a testimony that I didn't use other's implementation in my repository.

kisslorand avatar Sep 24 '23 20:09 kisslorand

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 15 '23 06:12 stale[bot]

This PR has been automatically marked as stale because it has had no activity for the last 60 days. It will be closed in 7 days if no further activity occurs. Thank you for your contribution.

github-actions[bot] avatar Apr 20 '24 01:04 github-actions[bot]