This project aims to benchmark the performance of interfacing an STM32F103C8 microcontroller with a TFT 128x160 screen using both standard SPI and SPI with DMA. The primary goal is to compare the time efficiency between these two methods for drawing graphics on the TFT screen.
In this project, I have developed the following HAL & CMSIS peripheral drivers:
- SPI: for interfacing with the TFT ILI934 screen
- DMA: for using DMA channels with SPI for faster data transmission
- Timer: Used for benchmarking by measuring the time taken to draw graphics on the screen
- GPIO: for sending control signals during the screen interface
- NVIC: To enable interrupts and apply interrupt-driven timer and DMA functionality
- Systick: for precise delay functionalities
-
Clone the Repository:
git clone https://github.com/MahmoudSheemy127/STM32F103C8-TFT-Screen-Benchmarking.git
-
Hardware Connections:
- Connect the TFT screen to the specified GPIO pins on the STM32F103C8 as shown in the figure below.
- In this project, I am using SPI2
- Ensure proper power supply and ground connections.
| STM32F103C8 Pin | TFT ILI9341 Pin | Function |
|---|---|---|
| 3V3 | LED | Backlight Power (3.3V) |
| PA5 | SCK | SPI Clock |
| PA7 | SDA | SPI MOSI (Data In) |
| PA2 | A0 | Data/Command Selection |
| PA8 | RST | Reset |
| PA3 | CS | SPI Chip Select |
| GND | GND | Ground |
| VCC | 3V3 | Power Supply (3.3V) |
-
Application configurations:
- To start SPI DMA benchmarking set the macro flag
TRANSFER_MODEtoDMA_MODE - To start normal SPI benchmarking set the macro flag
TRANSFER_MODEtoSPI_MODE
- To start SPI DMA benchmarking set the macro flag
-
Build and Flash:
- Use your preferred STM32 development environment (e.g., STM32CubeIDE, PlatformIO) to build and flash the project to the microcontroller.
-
Run the Benchmark: The application will draw a series of graphics on the TFT screen. After drawing the graphics on the screen the final benchmark result of the SPI transfer method chosen is printed on the screen.
The benchmarking results demonstrate a significant reduction in time when using SPI with DMA for drawing graphics on the TFT screen. Working with CLK_FREQ = 8Mhz & SPI_CLK = 2 Mhz
| BENCHMARK | SPI DMA | SPI |
|---|---|---|
| TOTAL DATA TRANSMITTED | 469 KB | 469 KB |
| TOTAL TIME TAKEN FOR DATA TRANSMISSION | 453 ms | 995 ms |
| TRANSMISSION RATE | ~ 1 KB/ms | ~ 484 Bytes/ms |
Conclusion: The benchmark test shows a reduction in transmission rate by 50% when DMA is used with SPI for drawing graphics on the TFT screen.
For a complete Benchmark test demonstration check this video
This project is licensed under the MIT License.
