This project is an expansion board for RT-Thread’s open source hardware ART-Pi. Expanded VGA and USB interfaces for ART-Pi. It can be used to connect a VGA monitor and keyboard to turn ART-Pi into a "PC"-like device. Or as a simple GUI development platform.
First of all, I strongly recommend everyone to watch this video, link: This may be the worst graphics card in the world . In this video, the author made a "graphics card" on a breadboard that can output a VGA signal. The author's explanation of the VGA signal is very simple and easy to understand, and is suitable for friends who have never understood VGA.
VGA signals include control signals (synchronization signals) and data signals. For our project, the first thing we need to pay attention to is the timing of the VGA control signals:
This timing diagram also explains the specific working method of VGA: the displayed content is sent line by line. After the content of a line is sent, the display device is notified of the content of the current line through a pulse called Horizontal Sync Pulse (HSP). The transfer is complete, then the next line is transferred. This cycle continues until the entire screen's content is transmitted and a Vertical Sync Pulse (VSP) pulse is sent. At this point, one frame is transmitted. Then continue transmitting the next frame.
VGA is a pure analog signal, which is prepared for CRT monitors. The display device determines the format of the signal entirely through the length of the two pulses HSP and VSP and the interval between the pulses. Because there is no digital communication process, the timing accuracy is required to be high. And due to the limitations of the display, in fact we cannot freely determine the signal length and spacing of HSP and VSP. Here are some commonly used signal formats:
Knowing the format of the signal, how can we generate accurate signal timing? Some students may say that you can just use a timer. This is indeed a method, but it is more troublesome to implement. Here we do not use it but use LTDC, a peripheral of ART-Pi's main control STM32H750XB, to generate VGA signals.
The full name of LTDC is "LCD-TFT display controller", which is the LCD display device controller. As the name implies, LTDC is used to control the peripherals of LCD liquid crystal displays. It has two working modes: DE mode and HV mode. The difference is that DE mode only uses DE signals for frame synchronization, while HV mode requires the use of HSYNC and VSYNC two signals to synchronize data frames.
After seeing how VGA signals work, I believe you will be familiar with HSYNC and VSYNC in HV mode. In fact, the working principle of LTDC's HV mode is highly consistent with the principle of VGA signal. It's just that LTDC transmits digital signals. This is also the theoretical basis for us to use LTDC to generate VGA signals.
Let’s look at the signal timing diagram of LTDC (HV mode):
At first glance, it seems that the timing of the VGA signal is completely different, but in fact, you will find out if you analyze it carefully. Its working principle is exactly the same as that of VGA, except that the SYNC PULSE is drawn to the front in this picture, so it just looks a little inconsistent.
So we only need to adjust the parameter timing of the LTDC controller to be consistent with the expected VGA signal timing to generate an accurate VGA synchronization signal. The next question is, which signal format do we use? Going back to the commonly used VGA signal format table, you can see that the frequencies of most signals are non-integer multiples, and generating non-integer multiples of signals is a very laborious task. We need to do it in the clock configuration of STM32 Just make a bigger compromise. Therefore, the most suitable signal is this:
A 40MHz signal is a very easy to implement round number. Then the resolution and refresh rate of 800x600@60Hz are also more suitable.
Then we can view the specific parameters of this signal format:
We need to use these parameters to configure the LTDC controller of STM32H750. It is recommended to configure via CubeMX here, which is convenient and less error-prone:
The other configurations of the LTDC are the same as those used when using the LCD screen normally, and will not be described again here.
The control signal meets the requirements, and the next step is to send the display content. LTDC sends digital signals, while VGA display devices need to receive analog signals. Obviously, we need a DAC (digital-to-analog converter) to do this job.
Let’s first look at the standards of the VGA physical interface:
Among them, HSYNC and VSYNC are synchronization signals. We have just introduced them. Now we need to focus on the three pins labeled RGB, Pin1, 2, and 3. These three pins are used to send the corresponding color data. signal pin.
We notice that the signal has an impedance of 75Ω at the terminal and source ends. In a simple model, we can think that the signal has a resistance of 75Ω to ground. Then the voltage range of the signal is 0~0.7V. That is to say, we need to convert the digital signals of the RGB channels into 0~0.7V analog signals and transmit them through these three lines.
We can use a resistor voltage divider network to convert RGB565 digital signals to analog signals. This method is low-cost but the display effect is not very ideal. In order to improve the image quality, we can use ADV7123, a dedicated VGA signal DAC, to convert digital signals to analog signals.
Relative to using a resistor network to achieve digital-to-analog conversion. ADV7123 requires an additional pixel clock signal for data synchronization. We can directly use the pixel clock signal output by the LTDC controller. Then there is nothing more to say. Just design the circuit according to the ADV7123 data sheet. The final circuit is as follows:
Since it needs to be connected to an external VGA device and considering the possible ESD damage, here we add an additional dedicated ESD protection chip before the DAC and the final VGA output terminal.
At this point, we have completed all preparations for outputting VGA signals.
In order to connect a USB keyboard, we need a USB Host interface. There’s actually not much to say about this, there’s a lot of information online. The electrical connection is also relatively simple.
Since the USB interface of the STM32H750 is relatively fragile, in order to protect against possible short circuits and electrostatic breakdown, a dedicated ESD protection chip and USB short circuit protection chip are added here.
Considering that the power supply of the ART-Pi body may be insufficient, an additional power supply circuit is added here with reverse connection protection and over-current protection, which can directly accept an input voltage of 6~12V to power the ART-Pi and expansion board.
The PCB directly uses the form factor of ART-Pi. It should be noted that since the LTDC interface of the ART-Pi is led out through the FPC socket, the LTDC interface of the expansion board will be connected to the ART-Pi body using an FPC soft cable.
Final design renderings:
The design idea of this expansion board is to provide the hardware foundation for realizing a PC-like device similar to ColorMixmate (of course, you can also use this expansion board not according to my design idea at all). In the current Demo, I implemented a small console, transplanted a command line library, and embedded a small BASIC interpreter. In the command line environment, you can use some of my built-in commands to mount the SD card, switch file paths, view pictures, and play videos. In a BASIC environment, you can code using the BASIC language. I implemented the control of GPIO in the BASIC environment, so you can also use BASIC to implement some basic GPIO operations.
The Demo code was developed in trueStudio and is completely open source. Please jump to the attachment to download.
cd test
; Return to the root directory: cd /
; Return to the upper directory:cd ..
op "123.jpg"
; Open the video aerith.avi: op aerith.avi
JPEG picture file limit: no larger than the screen resolution (800x600) AVI video file limit : MJPEG encoding, no audio, below 25FPS, resolution no higher than 800x600First, we need to create an entry function for the command. The function can be one of the following types:
Using this approach, an example of a function definition is as follows:
int func(int argc, char *agrv[])
{
printf("%dparameter(s)
", argc);
for (char i = 1; i < argc; i++)
{
printf("%s
", argv[i]);
}
}
Then, use the macro registration command outside the function:
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), testcmd, func, test);
The first parameter is a fixed form, the second parameter is the command name, that is, the name of the command executed on the command line, the third parameter is the command entry function name, and the fourth parameter is the comment.
Then we can call this command in the terminal:
letter:/$ testcmd "hello world"
2 parameter(s)
hello world
Using this method, the shell will automatically convert the parameters. Currently, it supports automatic processing of binary, octal, decimal, and hexadecimal integers, characters, and strings. Examples are as follows:
int func(int i, char ch, char *str)
{
printf("input int: %d, char: %c, string: %s
", i, ch, str);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), func, func, test);
Terminal call
letter:/$ func 666 'A' "hello world"
input int: 666, char: A, string: hello world
The current Demo only implements the output function of GPIO. Before operating a certain GPIO, you need to use the following command to set the corresponding GPIO to output mode:
PINMODE 2,1
The first parameter is the GPIO number, the second parameter is the mode, 1 indicates the output mode. The corresponding relationship between the GPIO number and the real GPIO is defined in the host.c file:
static const BASICPinDef supportedOutputPins[] = {
{2, GPIOH, GPIO_PIN_12},
{3, GPIOH, GPIO_PIN_11},
{4, GPIOA, GPIO_PIN_8},
{17, GPIOA, GPIO_PIN_15},
{22, GPIOH, GPIO_PIN_13},
{10, GPIOI, GPIO_PIN_3},
{9, GPIOI, GPIO_PIN_2},
{11, GPIOI, GPIO_PIN_1},
{5, GPIOH, GPIO_PIN_7},
{6, GPIOH, GPIO_PIN_9},
{13, GPIOB, GPIO_PIN_13},
{19, GPIOI, GPIO_PIN_7},
{26, GPIOI, GPIO_PIN_4},
};
If you want to add GPIO support, you can also add it in this array.
After setting the output mode, you can use the following command to control the output status of the GPIO
PIN 2,1
The first parameter is the GPIO number, the second parameter is the output level, 0 means low level, 1 means high level.
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet