Aiming at the serial communication of STM32 microcontroller, a simulation method of virtual serial communication is proposed. The transmission and reception of serial communication are simulated by the combination of virtual serial port software, serial debugging assistant and Keil software.
The results show that the serial port of STM32 microcontroller can send and receive data normally by software simulation and verify the normal operation of the serial port without hardware. This method does not need hardware development board and simulator, nor does it concern whether the computer has serial port, but uses virtual serial port software (VSPD) to create virtual serial communication interface. Therefore, VSPD software, serial debugging assistant and Keil uVision 5 software need to be installed on the computer. VSPD creates virtual serial ports in pairs. These virtual serial ports are exactly the same as real physical serial ports in use.
The virtual interconnection links the created pairs of serial ports together, which is equivalent to connecting two serial ports with data lines, thus realizing the simulation of sending and receiving data. The number of new virtual serial ports is unrestricted, so the number of serial ports can be easily expanded. After opening the software, thermostatic element manage ports select two serial numbers on the interface that appears and click Add pair, then two virtual serial ports COM1 and COM2 are displayed under the Virtual ports of the Serial Ports Explorer section on the left side of the interface. These two serial ports are the created serial ports. If you need to continue to add the serial ports, just continue to select the serial port under the management ports and click Add pair. The simulation and debugging of USART can be realized by binding virtual serial port COM1 and COM2 with USART in STM32 microcontroller. After compiling and linking the compiled serial port program to generate executable files, debugging and simulation are carried out in Dubug mode. The MODE command sets the virtual serial port parameters to be bound. COMx (x = 1,2,3.
..
) For a virtual serial password, baudrate is the effective baud rate of the serial port (e.g. 1200, 2400, 9600, or 19200), parity is the parity check setting (parity is 0 for no check bit, parity is 1 for odd check, and parity is 2 for even check), databits is the number of data bits (8 for 8 bits, 7 for 7 bits), and stops are the number of stop bits.
Number (1 for 1 bit stop bit, 15 for 1.5 bit stop bit and 2 for 2 bit stop bit). The ASSIGN command binds the virtual serial port created by the computer to the simulation serial port of the microcontroller. Channel is a virtual serial COMx (x = 1,2,3…
Inreg and outreg are the input and output of MCU serial port (inreg is SxIN, outreg is SxOUT, x = 1, 2, 3). When simulating multiple serial ports, because there are many virtual serial ports created, in order to avoid entering commands in each simulation, a configuration file USART.txt can be created, and the above MODE and ASSIGN commands can be written successively. If multiple serial ports need to be bound, multiple groups of MODE and ASSIGN commands need to be written, with the same format and specific parameters according to the actual program.
Require settings. After creating the configuration file, change the suffix to. ini, such as USART. txt to USART.
ini in this article. When setting the Keil parameter, change the Initialization File path in the Debug tab.
Set the port number to create the virtual serial COM2, set the baud rate to 9600 according to the simulation program, no parity check bit, stop bit to 1 bit, data bit to 8 bits. From the test results, it can be seen that through virtual serial port, serial debugging assistant and microcontroller can receive and receive data correctly, and communication is normal.
This paper introduces the method of using virtual serial port in STM32 serial port simulation. All of them adopt the way of software simulation. It has low cost, high efficiency and greatly reduces the time of software development.
The test results verify the validity of the method, which has a good application value in practice development and teaching.