USB virtual multi-serial communication system based on domestic single-chip microcomputer
By integrating a communication interface layer, a data management and routing layer, a hardware acceleration and peripheral layer, and a system protection layer, based on a domestically produced microcontroller, the USB virtual to multi-serial port communication system solves the problems of high cost, limited functionality, and poor reliability in existing technologies, and achieves low-cost and highly reliable multi-serial port communication.
Patent Information
- Application Number
- CN202610488119.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-14
- Publication Date
- 2026-07-10
AI Technical Summary
Existing USB-to-serial port solutions are costly, have limited functionality, poor reliability, and pose supply chain and security risks, making it difficult to meet the needs of low-cost and high-reliability industrial applications.
A USB virtual to multi-serial communication system based on a domestic microcontroller is adopted, which integrates a communication interface layer, a data management and routing layer, a hardware acceleration and peripheral layer, and a system protection layer to realize multiple virtual interfaces, data routing and filtering, serial communication, and self-recovery capabilities.
Significantly reduces costs, improves system reliability and flexibility, supports multiple CDC and MSC virtual USB drives, SD log storage, RS485 direction control, reduces downtime due to system crashes, and adapts to different application scenarios.
Smart Images

Figure CN122364134A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the USB to multi-serial port technology in the field of computer application technology. More specifically, it relates to a USB virtual to multi-serial port communication system based on domestic microcontrollers. Background Art
[0002] USB to multi-serial port is a technology or device that expands multiple independent serial communication ports through a single USB interface, and can support the expansion of dual-channel to eight-channel or even more serial ports. It is widely used in industrial control, embedded development, and automated test scenarios that require connecting multiple serial port devices simultaneously. However, most of the common USB to serial port and multi-serial port expansion solutions on the market currently use dedicated bridge chips or multi-chip stacking to achieve. Although the convenience of plug and play is achieved by using dedicated bridge chips, in actual industrial applications and complex scenarios, their shortcomings have become increasingly prominent.
[0003] From the cost aspect, multi-serial port expansion relies on multiple dedicated chips or high-cost controllers. Taking 4-channel serial port expansion as an example, the traditional solution requires 1 USB HUB chip and 2 dual-serial port bridge chips, so the single BOM cost exceeds 40 yuan. And as the number of serial ports increases, the cost increases linearly, making it difficult to meet the batch application requirements of low-cost projects.
[0004] From the function aspect, most products only support simple transparent transmission between USB and serial ports, and cannot implement advanced functions such as channel mapping, internal bridging, and data mirroring. In the multi-device linkage debugging scenario, engineers need to build an external data forwarding system additionally, which not only increases the system complexity but also reduces the debugging efficiency. Therefore, in automated testing, multi-port data synchronous acquisition and analysis cannot be achieved, restricting the test coverage.
[0005] From the reliability level, existing solutions generally lack a complete fault detection and self-recovery mechanism. When the USB endpoint encounters abnormal data packets, or the serial port is blocked or the buffer overflows due to external device failures, the device is very likely to have "port dropout" or even freeze, and manual reinsertion or restart of the device is required. In the unattended environment of the industrial site, serious consequences such as production line shutdown may be caused.
[0006] From the expansion ability aspect, traditional solutions are difficult to integrate composite functions such as SD card log storage, virtual U disk export, and RS485 automatic direction control on a low-cost basis. If data local storage is required, an independent storage control module needs to be added additionally, which further pushes up the cost, and there is no unified management interface between each function module, making configuration and maintenance difficult.
[0007] Furthermore, supply chain and security risks cannot be ignored. Some high-end solutions rely on imported bridging chips, which are subject to supply disruptions due to international circumstances and production capacity limitations. Additionally, some chips lack secure encryption mechanisms, making data transmission vulnerable to eavesdropping and tampering, posing potential security risks to industrial control systems.
[0008] Therefore, there is an urgent need for a USB-to-multi-serial-port communication system based on a domestically produced low-cost microcontroller, which can significantly reduce costs while ensuring performance, and possess configurable data routing, storage export, and highly reliable self-recovery capabilities. (Invention Content) The summary section of this application is intended to provide a brief overview of the concepts, which will be described in detail in the detailed description section below. This summary section is not intended to identify key or essential features of the claimed technical solutions, nor is it intended to limit the scope of the claimed technical solutions.
[0009] To address the problems and shortcomings of existing technologies, this invention aims to provide a USB virtual to multi-serial port communication system based on a domestically produced microcontroller. This system achieves stable concurrent communication with low CPU usage by using four virtual COM ports, and supports SD logging, virtual USB drive export, RS485 direction control, channel mapping / bridging, and filtering / rate limiting. It also features port loss detection and self-recovery capabilities. This addresses the problems mentioned in the background section.
[0010] To achieve the above objectives, the present invention provides the following technical solution: As a first aspect of the present invention, the present invention discloses a USB virtual to multi-serial port communication system based on a domestic microcontroller, including a communication interface layer, a data management and routing layer, a hardware acceleration and peripheral layer and a system protection layer integrated within the same domestic microcontroller; The communication interface layer is used to interact and communicate with the host computer. It enumerates multiple virtual interfaces in a composite device manner. The virtual interfaces include multiple communication CDC interfaces and storage MSC interfaces. The data management and routing layer is connected to the communication interface layer and includes an endpoint and interface management module, a channel routing filtering and rate limiting module, and a buffer and queue module, which are used to distribute, route, filter, rate limit, and speed match the data obtained by the virtual interface. The hardware acceleration and peripheral layer is connected to the data management and routing layer, and includes a hardware data acceleration module, a serial communication peripheral module, an external serial port module, and an SD log module, which are used to realize efficient transfer of processed data, serial physical communication, and log storage. The system protection layer is connected to the aforementioned layers and includes a dropout detection and self-recovery module, which is used to monitor the system's operating status and perform hierarchical strategy recovery operations.
[0011] Preferably, the communication interface layer includes six CDC interfaces and one MSC interface; wherein, four CDC interfaces are used to provide virtual COM ports to realize data pass-through between the host computer and external serial port devices; one CDC interface serves as a configuration command communication port, used to receive host computer instructions to flexibly configure GPIO port status or modify system operating parameters; one CDC interface serves as a real-time log port, used to output system real-time logs to the host computer for monitoring; and the storage MSC interface is used to simulate the internal storage medium as a virtual USB flash drive, allowing the host computer to read log files, upgrade firmware, or read and write configuration files.
[0012] Preferably, the channel routing filtering and rate limiting module intelligently processes the data passing through it, including planning the data transmission path through a preset routing table to implement the routing mode with flexible communication modes; the routing table data structure contains a global routing table with four entries, each entry corresponding to a virtual serial port channel, including routing mode, target channel number, filtering mode, keyword and its length, and maximum frame length; the routing modes include a default transparent transmission mode that implements one-to-one bidirectional transparent transmission, a mirror mode that implements one-input-many-output, a bidirectional bridging mode that implements transparent bridging between two UARTs, a forwarding mode that implements cross-channel uplink forwarding, a merging mode that implements many-input-one-output, and a channel closing mode.
[0013] Preferably, the channel routing filtering and rate limiting module further includes a filtering mechanism and a rate limiting mechanism. The filtering mechanism configures filtering rules independently for each routing entry, including four strategies: keyword whitelist filtering, keyword blacklist filtering, length limit filtering, and no filtering. Filtering checks are performed before data enters the routing distribution, and data that fails to pass is directly discarded. The rate limiting mechanism includes a single-transmission length limit, a buffer backpressure limit, and a receive buffer overflow protection. The single-transmission length limit restricts the maximum length of data retrieved and sent from the buffer in a single transaction in the mirror mode and bridging mode. The buffer backpressure limit advances the buffer pointer based on the actual number of bytes consumed by the USB endpoint, reserving unconsumed data for the next round of processing. The receive buffer overflow protection forcibly discards old data when the buffer usage exceeds a preset threshold.
[0014] Preferably, the hardware data acceleration module is an eight-channel DMA, with each UART occupying one DMA channel for receiving and transmitting, and the four UARTs occupying a total of eight DMA channels, each corresponding to the virtual COM port, for directly transmitting data between the virtual COM port transmit / receive buffer and the UART; the serial communication peripheral module includes four UART ports, UART1~UART4, which are internal hardware serial ports of the microcontroller; the external serial port module is an RS485 interface, serving as the external physical interface for the four UARTs; the SD log module is used to write the log data transmitted from the real-time log port to the SD card after queue buffering and log encapsulation, and to provide it to the host computer for reading in a block mapping manner through the storage MSC interface.
[0015] Preferably, the dropout detection self-recovery module includes a multi-dimensional status monitoring unit for monitoring the USB endpoint status, UART transmission status, DMA transmission status, and buffer queue status. Specifically, the USB endpoint monitoring determines the physical connection status by reading changes in the USB frame number register within a preset time window; the UART transmission status monitoring determines whether the connection is stuck by maintaining a busy transmission flag and checking its duration; the DMA transmission status monitoring is achieved by checking the transmission error flag and the receive overflow flag; and the buffer queue monitoring determines overflow risk by calculating the ring buffer usage rate in real time.
[0016] Preferably, the dropout detection self-recovery module further includes a hierarchical recovery unit, which includes a complete reset mechanism, a lightweight recovery mechanism, and a system-level recovery mechanism. The lightweight recovery mechanism clears the UART transmit busy flag buffer data, causing the transmit scheduler to re-trigger DMA transmission. The complete reset mechanism automatically escalates execution when the lightweight recovery is repeatedly triggered more than a preset number of times within a preset time window. This includes pausing the DMA channel and disabling the UART peripheral, deinitializing the DMA and clearing the status flag, clearing the transmit ring queue, switching the RS485 transceiver back to receive mode, reconfiguring the DMA channel parameters, and re-enabling the UART peripheral. The system-level recovery mechanism triggers a soft reset of the MCU when the USB connection is disconnected for more than a preset time, causing the entire system to reinitialize and re-enumerate the USB.
[0017] Preferably, the external serial port module enables half-duplex direction switching. Each UART is configured with an independent GPIO pin to control DE / RE, which defaults to receive mode upon power-up. Before sending data, the DE pin is first set high to put the transceiver into transmit mode, and then DMA is started to transfer the data to the UART data register. After the DMA transfer is completed, the UART hardware transmit completion flag TC is set, and the hardware automatically sets the flag after transmission is complete. When all the data to be transmitted is sent, a hardware timer is started to perform a configurable microsecond delay. After the timer expires, the DE pin is pulled low to restore the receive mode.
[0018] Preferably, GPIO configuration, management, and programming adaptation can be achieved through the configuration command communication port, and the following are also included: The host computer sends structured configuration frames through the configuration command communication port; After receiving the configuration frame, accumulating it, synchronizing the header, and combining the frames, ConfigCmd_Process() is called to distribute and process it uniformly. The validity of the target pin is verified by querying the preset GPIO pin whitelist. The level of the target pin is only allowed to be set if it exists in the whitelist; otherwise, an invalid pin error is returned. By sequentially pulling the BOOT pin of the target device high, then pulling the RESET pin low and then high again using the GPIO_SET command, the target device enters the serial port programming wait state. Execute the ROUTE_SET command to configure the specified virtual COM port and the corresponding UART channel to the default pass-through mode, and establish a data path between the host computer and the target device programming interface; The host computer sends the programming protocol data through the virtual COM port. After receiving the data, the system automatically transfers it to the corresponding UART's transmit register via DMA, and then sends it to the target device's bootloader via the external serial port module to complete the firmware download. After the flashing is complete, execute the GPIO_SET command again to pull the BOOT pin of the target device low and then pull the RESET pin low and then high again, so that the target device can boot from the new firmware.
[0019] As a second aspect of the present invention, the present invention also discloses a USB virtual to multi-serial port communication method based on a domestic microcontroller. The method is implemented using a USB virtual to multi-serial port communication system based on a domestic microcontroller, including downlink transmission from a host computer to an external serial port device. The host computer sends data through four virtual COM ports. The endpoint and interface management module is responsible for managing the connection status of all virtual COM ports and identifying the interface to which the data belongs in the data transmission queue. Then, the data enters the channel routing filtering and rate limiting module to determine the target channel according to the preset mapping rules and perform filtering and rate limiting mechanism checks. The checked data is sent to the buffer and queue module of the corresponding channel for temporary storage. The hardware data acceleration module automatically moves the data from the memory buffer to the corresponding UART's transmit register. Finally, the data is sent down through the external serial port module driving the bus. It also includes uplink transmission from external serial port devices to the host computer. The external device sends data through the external serial port module, which receives it through the serial communication peripheral module. The serial communication peripheral module assembles the serial data into bytes. When a byte is received or a trigger threshold is reached, the hardware data acceleration module automatically moves the data to the buffer and queue module. The channel routing filtering and rate limiting module checks the data source and determines the data destination according to the currently effective routing table configuration. Data distribution is performed according to the routing configuration. Ordinary data is forwarded to the corresponding virtual COM port for the host computer to read. Log data is sent to the SD log module, formatted and encapsulated, and then written to the SD card. The data transmitted to the host computer is encapsulated into USB format and allocated to the correct virtual COM port through the endpoint and interface management module. Finally, the data is uploaded to the host computer, where the USB driver restores it to the corresponding virtual COM port, completing data acquisition and monitoring.
[0020] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention aims to provide a USB virtual to multi-serial port communication system based on a domestically produced microcontroller, comprising a communication interface layer, a data management and routing layer, a hardware acceleration and peripheral layer, and a system protection layer integrated within the same domestic microcontroller. The communication interface layer interacts with the host computer, enumerating multiple virtual interfaces in a composite device manner. These virtual interfaces include multiple communication CDC interfaces and storage MSC interfaces. The data management and routing layer connects to the communication interface layer and includes an endpoint and interface management module, a channel routing filtering and rate limiting module, and a buffer and queue module, used for distributing, routing, filtering, rate limiting, and speed matching of multi-channel data. The hardware acceleration and peripheral layer connects to the data management and routing layer and includes a hardware data acceleration module, a serial communication peripheral module, an external serial port module, and an SD log module, used for efficient data transfer, serial physical communication, and log storage. The system protection layer connects to the aforementioned layers and includes a dropout detection and self-recovery module, used for monitoring the system's operating status and performing tiered recovery operations. This invention utilizes a domestically produced low-cost microcontroller to implement a four-port USB virtual serial port, reducing the number of dedicated bridging chips, significantly lowering BOM costs, ensuring security and controllability, and providing more stable supply. The four UART ports transmit and receive data in parallel via an eight-channel DMA, resulting in low CPU usage and more stable throughput. Using a dropout detection combined with a self-recovery mechanism reduces downtime caused by freezes or dropouts. It also supports multiple CDC and MSC virtual USB drives, SD log storage, RS485 direction control, routing bridging, and filtering / rate limiting. The six CDC interfaces include four virtual COM ports, one configuration command port, and one real-time log port. Furthermore, routing rules, filtering / rate limiting, GPIO, and programming adaptation can be customized to suit different products and application scenarios. The domestically produced microcontroller used in this invention is the N32G435CBL7, which costs only 3 yuan, thus greatly reducing operating costs. (See attached figures.) The accompanying drawings, which form part of this application, are used to provide a further understanding of the application and to make other features, objects, and advantages of the application more apparent. The illustrative embodiments and descriptions of this application are used to explain the application and do not constitute an undue limitation of the application. In the drawings: Figure 1 This is a hierarchical connection diagram of the USB virtual to multi-serial communication system based on a domestically produced microcontroller in an embodiment of the present invention; Figure 2 This is an overall connection diagram of the USB virtual to multi-serial communication system based on a domestically produced microcontroller in an embodiment of the present invention; Figure 3 This is a schematic diagram of an eight-channel DMA system based on a domestically produced microcontroller for USB virtual to multi-serial communication in an embodiment of the present invention. Figure 4 This is a data flow diagram of the channel routing filtering and rate limiting module of the USB virtual to multi-serial communication system based on a domestic microcontroller in an embodiment of the present invention; Figure 5 This is a data flow diagram of the dropout detection and self-recovery module of the USB virtual to multi-serial communication system based on a domestic microcontroller in an embodiment of the present invention; Figure 6 This is a data flow diagram of the SD log module of the USB virtual to multi-serial communication system based on a domestic microcontroller in an embodiment of the present invention; Figure 7 This is a flowchart illustrating the GPIO configuration, management, and programming adaptation process of a USB virtual to multi-serial communication system based on a domestically produced microcontroller, as described in this embodiment of the invention. Figure 8 This is a flowchart illustrating the half-duplex direction switching process of a USB virtual to multi-serial communication system based on a domestically produced microcontroller in an embodiment of the present invention. Detailed Implementation
[0021] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0022] It should also be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings. Unless otherwise specified, the embodiments and features described in this disclosure can be combined with each other.
[0023] Example 1 This invention discloses a USB virtual to multi-serial port communication system based on a domestically produced microcontroller. The following will describe this disclosure in detail with reference to the accompanying drawings and embodiments.
[0024] like Figure 1 and Figure 2 As shown, this invention includes a communication interface layer, a data management and routing layer, a hardware acceleration and peripheral layer, and a system protection layer integrated within the same domestically produced microcontroller. The domestically produced microcontroller used in this invention is the N32G435CBL7, which costs only 3 yuan, thus greatly reducing the cost of use.
[0025] The communication interface layer serves as the entry point for interaction with the host computer; all external communication is primarily initiated through the host computer (PC). However, in bridged or forwarded modes, data streams can also be directly transmitted between two external serial port devices without host computer intervention. Multiple virtual interfaces are enumerated as composite devices, such as... Figure 1As shown, the system includes six CDC interfaces and one MSC interface. Four CDC interfaces correspond to four virtual COM ports. One CDC interface serves as a configuration command communication port for flexibly setting the high / low status of a specific GPIO port, and the other CDC interface serves as a real-time LOG port for outputting real-time system logs for monitoring by the host computer. The MSC interface is used to present the storage medium as a "virtual USB drive" to the host for reading logs. The MSC interface (Mass Storage Class) simulates the microcontroller's internal storage medium (such as Flash, SD card, etc.) as a "virtual USB drive" for firmware upgrades, configuration file reading / writing, or log file export. When the MSC interface is accessed by the host (i.e., the host is opening the "virtual USB drive" to browse files), the SD card or Flash should be temporarily taken offline from the log writing system or switched to read-only mode. Otherwise, simultaneous writing by the system while the host is reading a file may corrupt the file system. After enumerating the USB as a composite device, the host computer (such as a computer) can directly read the log files stored within it, just like accessing a regular USB drive, enabling convenient log export and viewing.
[0026] The data management and routing layer includes an endpoint and interface management module, a channel routing filtering and rate limiting module, and a buffering and queuing module. The endpoint and interface management module manages the connection status and data transmission / reception queues of all virtual interfaces, enabling data distribution and priority control across different interfaces. For example, it sets a high priority for the real-time LOG port to ensure no log data loss. The channel routing filtering and rate limiting module intelligently processes the data passing through it, including planning data transmission paths using a pre-defined routing table to achieve flexible communication modes such as one-input-many-output, many-input-one-output, and bidirectional bridging. It also includes pre-defined filtering and rate limiting mechanisms that discard, reshape, or rate-limit invalid or abnormal data packets according to rules, while preventing device overload and ensuring system stability. The buffering and queuing module provides a FIFO buffer for each channel to solve the speed matching problem between high-speed USB and low-speed UART. For example, when UART1 processes data slowly, the buffer can temporarily store subsequent data to prevent data loss, while the queuing mechanism ensures the orderliness of data transmission.
[0027] Specifically, the routing table data structure contains a global routing table g_route[4] with 4 entries, each corresponding to a UART channel (UART1,2,4,3). In the default transparent transmission mode, VCP0~VCP3 correspond one-to-one with UART1, UART2, UART4, and UART3 respectively; by modifying the routing table configuration, this correspondence can be changed to realize the dynamic mapping between VCP and UART. The structure fields include routing mode (mode), destination channel number (dst,03), filtering mode (filter), keyword and its length (kw,kw_len), and maximum frame length (max_len). The routing table supports persistent storage in text format in the ROUTE.CFG file (FAT12 Flash) of the virtual USB flash drive, and can also be modified and saved online through the configuration instructions of the dedicated CDC endpoint. Its six routing modes include default pass-through, one-input multiple-output, bidirectional bridging, forwarding, multiple-input one-output, and channel shutdown, namely: NORMAL (default pass-through): Data received by UART[i] is sent to the corresponding CDC[i] endpoint, and data sent by CDC[i] is sent to UART[i], realizing one-to-one bidirectional pass-through. MIRROR (one-input multiple-output / mirroring): Data received by UART[i] is simultaneously sent to both the CDC[i] endpoint and the UART[dst] transmit port, realizing one input data being simultaneously output to the USB host and another UART. Mirroring is based on the actual number of bytes consumed by USB and limits the mirroring forwarding length to avoid blocking. BRIDGE (bidirectional bridging): Data received by UART[i] is directly forwarded to the UART[dst] transmit port, without passing through the USB CDC endpoint. A transparent bridge is formed between the two UART channels. The USB downlink direction is also blocked (CDC data is not sent to UART in BRIDGE mode). The system performs loop detection during configuration, traversing the bridging links to prevent closed loops. FORWARD forwards data received by UART[i] to the CDC[dst] endpoint (instead of CDC[i]), enabling cross-channel uplink forwarding. MERGE merges data received from multiple UART channels into a single CDC[dst] endpoint. Multiple source channels can point dst to the same target channel. OFF discards data received by this channel, and no data is sent to the UART in the USB downlink direction.
[0028] The filtering mechanism allows for independent configuration of filtering rules for each route entry. A `RouteCfg_Filter()` check is performed before data enters the route distribution process. The configured filtering rules include: Keyword Whitelist (`KW_PASS`): Searches the received data for a preset whitelist keyword (maximum 8 bytes). Data is allowed to pass only if it contains the keyword; otherwise, it is discarded. Keyword Blacklist (`KW_BLOCK`): Searches the received data for a preset blacklist keyword. If the keyword is found, the data is discarded; otherwise, it passes. Length Limit (`MAXLEN`): Data frames exceeding a preset maximum length are discarded; this is used to filter abnormally long frames. No Filtering (`NONE`): All data passes directly without any checks. Filtering occurs before route distribution. After data is retrieved from the UART's receive buffer, the filtering function is called to determine if it passes. If it fails, the buffer pointer is pushed forward and the data is consumed. If it passes, the data is then forwarded through the routing mode's switch branch.
[0029] The rate limiting mechanism includes single-transmission length limit, buffer backpressure limit, and receive buffer overflow protection. The single-transmission length limit is set to UART_TX_MAX_CHUNK (64 bytes) for each data transmission from the buffer to the target UART in both BRIDGE (bidirectional bridging) and MIRROR (one-in-many-out / mirroring) modes. For example, sending 64 bytes to a low-speed UART (e.g., 9600bps) takes approximately 67ms, which is close to the typical cycle of the system's main loop. This limitation prevents a single forwarding from occupying the main loop for an extended period, ensuring timely responses from other channels. Without this limitation, a single forwarding would occupy main loop resources for a long time, causing other communication channels to fail to respond promptly and leading to system lag. The buffer backpressure limit is the core of adaptive rate control. When calling USB_Vcp_SendData() to send data, the function returns the actual number of bytes consumed; if the USB endpoint is busy, it will return 0 or a partial number of bytes consumed. The buffer tail pointer only advances the consumed portion; unconsumed data remains in the buffer, awaiting processing in the next main loop. This essentially adds a valve to the system, automatically slowing down data transmission when the USB endpoint's processing capacity is insufficient, preventing the buffer from overflowing. It also achieves natural flow shaping and backpressure conduction. Receive buffer overflow protection is a fallback for high-load scenarios. When the UART receive buffer usage exceeds a preset threshold, the system activates overflow protection. It forcibly discards old data in the buffer to make room for new data, preventing DMA loop writes from overwriting unread data and ensuring the system doesn't crash under high load.
[0030] like Figure 4As shown, the routing distribution logic in the main loop polls the four channels in a round-robin fashion. For each channel, the routing table is first read to obtain the current mode and target channel number. In the USB downlink direction, it is determined whether the current mode is BRIDGE or OFF. If so, CDC data is blocked from being written to the UART; otherwise, CDC[i] data is sent to UART[i]. In the UART uplink direction, data is distributed to different branches based on the mode field, and data is obtained from the RX buffer of UART[i]. A filtering function is called to check the data. If the filtering check passes, the corresponding data forwarding operation is performed according to the mode, and the buffer tail pointer is advanced according to the actual consumption. If the filtering check fails, the data is discarded and the tail pointer is advanced. After the above is completed, the next channel is processed. When configuring BRIDGE mode, the system calls RouteCfg_CheckCircular() to traverse along the bridge link starting from the target channel, recording the visited nodes. If the system returns to the source channel, it determines that a loop exists and rejects the configuration to prevent data from looping infinitely between UART channels.
[0031] The hardware acceleration and peripheral layer includes a hardware data acceleration module, a serial communication peripheral module, an external serial port module, and an SD log module. The hardware data acceleration module is an eight-channel DMA that can directly transfer data between the USB virtual serial port's transmit / receive buffer and UART1~UART4, reducing CPU resource usage and significantly improving the efficiency of multi-serial port parallel communication. The serial communication peripheral module corresponds to the microcontroller's internal hardware serial port units UART1~UART4, responsible for asynchronous serial communication with external devices, supporting core functions such as parameter configuration and data transmission / reception, and is the basic hardware carrier for serial communication. The external serial port module is the external RS485 serial port, which is the external physical interface of UART1~UART4. Through industrial bus protocols such as RS485, it connects to external industrial equipment, sensors, etc., and belongs to the physical access part of the peripheral layer. The SD log module stores device operation logs to an SD card for subsequent troubleshooting and data backtracking. The DMA channel is configured in either circular or normal mode. For the receive channel, the DMA circular buffer function is enabled, and an interrupt is generated when it is half full or fully full to prevent data overwriting. For the transmit channel, a completion interrupt is generated after the single transmission mode is completed.
[0032] like Figure 3As shown, the microcontroller uses an eight-channel DMA to implement parallel communication of four UARTs. Each UART's receive (RX) channel occupies one DMA channel, and its transmit (TX) channel occupies another. The four UARTs (UART1~UART4) occupy exactly eight DMA channels. The eight-channel DMA rapidly transfers data between the UARTs and the memory buffer, while the CPU primarily handles routing, queue management, and anomaly detection. Specifically, the virtual serial port device is a communication interface based on the USB protocol, responsible for converting USB data from the computer into serial communication commands recognizable by the microcontroller. The eight-channel DMA is a hardware data transfer module within the microcontroller, capable of directly transferring data between the virtual serial port device and the microcontroller's internal peripherals (such as UARTs and CAN devices) without consuming CPU resources. When the computer sends data through the virtual serial port device, the data is first buffered in the microcontroller's receive buffer. The eight-channel DMA automatically detects the arrival of data and directly transfers the data from the receive buffer to the corresponding peripheral (such as the UART's transmit register). Conversely, data received by the peripheral is also directly transferred to the transmit buffer via DMA and then sent to the computer by the virtual serial port device via USB. The eight-channel configuration means that it can provide independent DMA transfer channels for eight different combinations of virtual serial ports and peripherals simultaneously, while each of the four CDC virtual serial ports corresponds to one of the four UART peripherals for parallel communication. Each channel can transmit data independently without interference, perfectly supporting the needs of multi-serial port parallel communication.
[0033] like Figure 6 As shown, the SD log module stores real-time log data transmitted via the LOG port, supports large-capacity SD card expansion, and can record the device's operating status for extended periods. Logs are categorized and stored according to channel number, data direction, timestamp, and other information for convenient offline analysis. Data acquired and input from serial communication and the virtual COM port first enters a queue buffer for temporary storage and orderly queuing, preventing data loss or transmission congestion and ensuring stable data writing. Next, the log encapsulation stage formats the raw data, adding timestamps, data identifiers, and verification information to give the data a traceable and identifiable structure for easy reading and analysis. Finally, the encapsulated data is written to the SD card as a file, completing persistent data storage. The MSC virtual USB drive export method involves a PC initiating a read request from the USB drive, establishing a connection with the system through the MSC interface, a standard interface for PCs to recognize external storage devices. Through a block mapping stage, the storage blocks of the SD card are mapped to the PC's read request, precisely locating the data to be read. Then, the SD file read operation is performed to read the packaged data file from the SD card, and then the data is transferred to the PC through the MSC interface to complete the data export and read.
[0034] The system protection layer consists of a failover detection and self-recovery module. This module uses multi-dimensional status monitoring to monitor the device's power supply status, USB endpoint connection status, UART communication status, DMA transfer status, and buffer queue operation in real time. When anomalies such as power failure, endpoint unresponsiveness, DMA timeout, UART overflow, or queue congestion are detected, a tiered automatic recovery process is automatically executed: DMA transfer is paused, the data queue is cleared or rebuilt, the UART and DMA modules are reinitialized, and endpoint transfer is resumed. The entire process requires no manual intervention, ensuring continuous and stable system operation. Multi-dimensional status monitoring includes continuous monitoring of the USB endpoint, UART status, DMA transfer status, and buffer queue. Specifically, USB endpoint monitoring: Utilizing the characteristic of the USB protocol that the host sends SOF frames every 1ms, a hardware timer periodically reads the USB frame number register. If the frame number does not change within a preset time window (e.g., 5 seconds), the USB physical connection is determined to be disconnected. Simultaneously, the transmission status flags of each endpoint are monitored during data transmission to determine whether the endpoint is busy or unresponsive.
[0035] UART Transmission Status Monitoring: Maintain a transmit busy flag (TxBusy) for each UART channel. Periodically check the duration of this flag in the main loop. If it exceeds the preset timeout threshold (e.g., 5 seconds), the UART transmission path is determined to be stuck.
[0036] DMA transfer status monitoring: Periodically check the transfer error flags of each DMA channel, and trigger recovery once a DMA transfer error is detected. At the same time, check the receive overflow flag (OREF) in each UART interrupt to prevent the UART from locking due to overflow.
[0037] Buffer queue monitoring: Calculates the usage rate of each receive ring buffer in real time, and outputs an alarm when the usage rate exceeds a preset threshold (such as 90%); when the buffer is close to full, it forcibly discards some old data to prevent DMA loop writing from overwriting unprocessed data.
[0038] The recovery mechanism employs a tiered strategy and uses a sliding time window for debouncing control. A preset sliding time window of 10 seconds is used to record the number of abnormal triggers. If a lightweight recovery is triggered more than 3 times within 10 seconds, it is considered a persistent fault and escalates to a complete reset. If no abnormality occurs within two consecutive time windows (20 seconds), the reset count is reset to zero. Specifically, Lightweight recovery: Only the UART transmit busy flag is cleared, leaving the buffer data unchanged, allowing the transmit scheduler to detect the idle state again and automatically trigger the next round of DMA transfer. This method restores communication at minimal cost and minimizes data loss.
[0039] Complete Reset: If the problem cannot be resolved by repeated triggering of Light Recovery within a preset time window (e.g., more than 3 times within 10 seconds), it will automatically escalate to a complete reset. The process is as follows: suspend the DMA channel and disable the UART peripheral within the critical section → deinitialize the DMA channel and clear all status flags → clear the transmit ring queue (head and tail pointers are reset to zero) → switch the RS485 transceiver back to receive mode → reconfigure the DMA channel parameters → reinitialize the DMA and enable the UART peripheral within the critical section.
[0040] System-level recovery: When the USB connection is disconnected for more than a preset time, the MCU is triggered to perform a soft reset, which reinitializes the entire system and performs USB re-enumeration.
[0041] Furthermore, such as Figure 5 The diagram shows the process flow for interface disconnection monitoring and self-recovery. When the system detects a communication anomaly, it first determines the type of anomaly. If the USB disconnection lasts for more than 5 seconds, it enters the USB link recovery process; if it's a UART transmit busy timeout (T: Busy Timeout), it enters the serial link recovery process. For USB disconnections lasting more than 5 seconds, the system further checks whether the number of recovery attempts within the most recent 10-second time window is less than 3. If it's less than 3, a lightweight recovery is performed, which clears the USB disconnection flag but retains all data in the buffer, only reinitializes the USB controller and triggers re-enumeration, incrementing the recovery window count for that channel upon completion. If more than 3 recovery attempts have been made within 10 seconds (i.e., continuous and repeated disconnections), it's considered a serious fault, and lightweight recovery is no longer performed. Instead, a complete reset is executed, i.e., the MCU performs a soft reset, the entire system reinitializes the USB, re-enumerates, and all states return to their power-on initial values. For UART transmit busy timeouts (T: Busy Timeout), the system executes a complete serial link lightweight recovery process without resetting the MCU. First, the DMA transfer for the corresponding UART channel is paused, and the UART peripheral is turned off. The DMA process deinitializes the channel, clearing all status flags. The head and tail pointers of the transmit queue are reset to zero, discarding all stale data to be transmitted. The RS485 control pin DE is pulled low, switching the bus to receive mode and releasing bus occupancy. The DMA channel parameters are reinitialized, and the UART peripheral is re-enabled. The T:Bussy timeout flag is cleared, retaining valid data in the buffer that has not yet been transmitted, allowing the transmit scheduler to re-detect the idle state and trigger DMA transmission. The core of this mechanism lies in distinguishing fault levels. Repeated USB disconnections are considered a serious system-level fault, directly triggering an MCU soft reset. However, a single UART channel transmit busy timeout is considered a local peripheral fault, achieving hot recovery through a refined "pause → cleanup → reconfigure" process, without affecting the other three UART channels or normal communication between USB and the PC.
[0042] Below, we will explain the USB virtual to multi-serial port communication method based on a domestic microcontroller from two directions: uplink (external serial port device → host computer) and downlink (host computer → external serial port device). The downlink data flow is as follows: The host computer sends data through four virtual COM ports. The endpoint and interface management module is responsible for managing the connection status of all virtual COM ports, identifying the interface to which the data belongs, and then the data enters the channel routing filtering and rate limiting module to determine the target channel according to the preset mapping rules and perform filtering and rate limiting mechanism checks. The checked data is sent to the corresponding channel's buffer and queue module for temporary storage. The hardware data acceleration module automatically moves the data from the memory buffer to the corresponding UART's transmit register, and finally, the data is sent down via the external serial port module driving the bus. The uplink data flow is as follows: External devices send data through the external serial port module, which receives the data via the serial communication peripheral module. The serial communication peripheral module assembles the serial data into bytes. When a byte is received or the trigger threshold is reached, the hardware data acceleration module automatically moves the data to the buffer and queue module. The channel routing filtering and rate limiting module checks the data source and determines the data destination based on the currently effective routing table configuration. Data distribution is performed according to the routing configuration. Ordinary data is forwarded to the corresponding virtual COM port for the host computer to read. Log data is sent to the SD log module, formatted and encapsulated, and then written to the SD card. Data transmitted to the host computer is encapsulated into USB format and allocated to the correct virtual COM port through the endpoint and interface management module. Finally, the data is uploaded to the host computer, where the USB driver restores it to the corresponding virtual COM port, completing data acquisition and monitoring.
[0043] Example 2 Direction control of an RS485 transceiver is implemented based on a USB virtual to multi-serial port communication system using a domestically produced microcontroller, as described in Example 1. Specifically, the system transmits the DE / RE preamplifier bit, and after transmission, resumes the receiving state after a configured delay. Switching parameters can be adjusted according to the baud rate and frame length.
[0044] like Figure 8As shown, the system uses software to control the DE / RE pins of the RS485 transceiver to achieve half-duplex direction switching. Each UART channel is configured with an independent GPIO pin, which defaults to receive mode (DE pin low) upon power-up. Before sending data, the DE pin is first set high to put the transceiver into transmit mode, and then DMA is started to move the buffered data to the UART data register. After the DMA transfer is complete, it waits for the UART hardware transmit complete flag (TC) to be set—this flag is automatically set by hardware after all bits (including stop bits) of the last frame have been sent in the shift register, naturally adapting to the current baud rate and frame format, without requiring software to calculate the frame duration. If there is still data to be sent in the buffer, DMA continues to be scheduled (DE remains in transmit mode); if all data has been sent, direction switching begins. After the TC flag is triggered, a hardware timer (such as TIM6) is started for a microsecond-level delay (configurable, default 5μs). After the timer expires, the DE pin is pulled low in the interrupt to restore the receive mode and the transmit busy flag is cleared. This delay is used to compensate for the transceiver chip's direction switching setup time and bus electrical propagation delay. The delay duration can be adjusted by configuration parameters according to the actual baud rate and transceiver characteristics.
[0045] Example 3 Based on the USB virtual to multi-serial communication system using a domestically produced microcontroller as described in Embodiment 1, flexible GPIO configuration, management, and programming adaptation are achieved. Serial port parameters, routing rules, and GPIO modes are configured via the USB management command channel. It also supports bridging a specified CDC channel to the target UART for serial programming / downloading, and can control reset / boot related pins.
[0046] In addition to the four virtual COM ports, the system has an independent CDC management command channel, namely the configuration command port, specifically for receiving and responding to configuration commands. This channel does not carry user data; it only transmits structured configuration frames. The command frame format is: | AA 55 | CMD | LEN | DATA[0..LEN-1] | CHK | 0D 0A |, where CHK is the XOR checksum of the CMD, LEN, and DATA fields. The response frame sets the highest bit of CMD to 1 (OR 0x80) as an acknowledgment flag and includes a STATUS status code (0x00 = success, 0x01 = invalid command, 0x02 = invalid pin, 0x03 = checksum error, 0x04 = frame format error). In the main loop, the data received from the configuration command port is accumulated, the packet header is synchronized, frames are assembled, and then ConfigCmd_Process() is called for unified distribution and processing.
[0047] The system defines a GPIO pin whitelist, gpio_whitelist[], which only allows control of the following pins via management commands: PA4, PA5, PA6, PB6, PB7, PB8, and PB9. These pins can be used to connect to control signals such as reset and boot mode selection for the target device. The whitelist is securely searched using the Find_GPIO() function: inputting the port number (0x00=GPIOA, 0x01=GPIOB) and pin number (0~15), it compares each pin in the whitelist one by one, allowing operation only on matching pins to prevent accidental operation from affecting critical system pins. ConfigCmd_Init() configures all pins in the whitelist to push-pull output mode during system startup, with a default low level. GPIO control commands include GPIO_SET (0x01) and GPIO_GET (0x02). GPIO_SET (0x01) indicates that the data field is [PORT,PIN,VAL], setting the level of the specified pin. VAL=1 pulls it high, VAL=0 pulls it low. First, the system checks the whitelist to verify its validity. If the pin is not on the whitelist, it returns a BAD_PIN error. GPIO_GET (0x02) indicates that the data field is [PORT, PIN], reads the current level of the specified pin, and returns it in the response. It also requires whitelist verification. Through these two commands, the host computer can remotely control the RESET and BOOT pins of the target device.
[0048] The USB CDC protocol defines the SET_LINE_CODING standard request, used by the host to send serial port parameters to the device. When the host opens a VCP port and sets the baud rate, data bits, stop bits, and parity, the device-side USART_Config() function determines the corresponding UART channel based on the USB interface number and calls the corresponding UpdateConfig function (e.g., USART1_UpdateConfig). The UpdateConfig function first disables the UART peripheral, reconfigures USART_InitStructure (baud rate, data bit width, stop bits, parity type), and then re-enables the UART peripheral. This process is completed online without restarting the device. The management command channel supports the following routing configuration commands, including: ROUTE_SET (0x10) indicates that the data field is [CH, MODE, DST], setting the routing mode and target channel for the specified channel. In BRIDGE mode, loop detection is automatically performed to prevent closed loops. ROUTE_GET (0x11) indicates querying the current routing mode, target channel, and filtering mode for the specified channel. ROUTE_FILTER (0x14) sets the filtering rules for the specified channel, supporting keyword whitelists / blacklists (with keyword data) and maximum frame length limits. ROUTE_SAVE (0x12) serializes the current routing table into text format and writes it to the ROUTE.CFG file in Flash for persistent storage. ROUTE_RELOAD (0x13) reloads and parses the routing configuration from Flash, enabling hot reloading of the configuration.
[0049] like Figure 7 As shown, the serial port programming process for the target device can be achieved through the combination of GPIO control and routing configuration: The host computer pulls the BOOT pin of the target device high (enters Bootloader mode) using the GPIO_SET command, then pulls the RESET pin low and then pulls it high again (resets the target device), putting the target device into the serial port programming waiting state. The host computer sets the specified VCP channel to NORMAL mode (CDC[i] transparently transmits UART[i]) using the ROUTE_SET command. This UART is physically connected to the serial port programming interface of the target device. If necessary, the baud rate can be adjusted via SET_LINE_CODING to adapt to the Bootloader communication rate. The host computer sends programming protocol data through this VCP channel, which is transmitted to the target device's Bootloader via USB CDC→UART, completing the firmware download. After programming is complete, the host computer pulls the BOOT pin low using GPIO_SET (restores normal boot mode) and resets the target device again to boot from the new firmware. The entire process is remotely controlled through the USB management command channel, without the need for manual intervention of hardware jumpers.
[0050] All technologies not described in detail in this invention are existing technologies. The above descriptions are merely some preferred embodiments of this disclosure and explanations of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the embodiments of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalent features without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in the embodiments of this disclosure.
Claims
1. A USB virtual to multi-serial port communication system based on a domestically produced microcontroller, characterized in that: This includes a communication interface layer, a data management and routing layer, a hardware acceleration and peripheral layer, and a system protection layer, all integrated within the same domestically produced microcontroller. The communication interface layer is used to interact and communicate with the host computer. It enumerates multiple virtual interfaces in a composite device manner. The virtual interfaces include multiple communication CDC interfaces and storage MSC interfaces. The data management and routing layer is connected to the communication interface layer and includes an endpoint and interface management module, a channel routing filtering and rate limiting module, and a buffer and queue module, which are used to distribute, route, filter, rate limit, and speed match the data obtained by the virtual interface. The hardware acceleration and peripheral layer is connected to the data management and routing layer, and includes a hardware data acceleration module, a serial communication peripheral module, an external serial port module, and an SD log module, which are used to realize efficient transfer of processed data, serial physical communication, and log storage. The system protection layer is connected to the aforementioned layers and includes a dropout detection and self-recovery module, which is used to monitor the system's operating status and perform hierarchical strategy recovery operations.
2. The USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 1, characterized in that: The communication interface layer includes six CDC interfaces and one MSC interface. Four CDC interfaces provide virtual COM ports for data pass-through between the host computer and external serial devices. One CDC interface serves as a configuration command communication port, receiving host computer commands to flexibly configure GPIO port states or modify system operating parameters. One CDC interface acts as a real-time log port, outputting real-time system logs to the host computer for monitoring. The storage MSC interface simulates the internal storage medium as a virtual USB drive, allowing the host computer to read log files, upgrade firmware, or read / write configuration files.
3. The USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 2, characterized in that: The channel routing filtering and rate limiting module intelligently processes the data passing through it, including planning data transmission paths using a preset routing table to implement routing modes with flexible communication modes. The routing table data structure contains a global routing table with four entries, each corresponding to a virtual serial port channel, including routing mode, target channel number, filtering mode, keyword and its length, and maximum frame length. The routing modes include a default transparent transmission mode that implements one-to-one bidirectional transparent transmission, a mirror mode that implements one-input-many-output, a bidirectional bridging mode that implements transparent bridging between two UARTs, a forwarding mode that implements cross-channel uplink forwarding, a merging mode that implements many-input-one-output, and a channel closing mode.
4. The USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 3, characterized in that: The channel routing filtering and rate limiting module also includes a filtering mechanism and a rate limiting mechanism. The filtering mechanism configures filtering rules independently for each routing entry, including four strategies: keyword whitelist filtering, keyword blacklist filtering, length limit filtering, and no filtering. Filtering checks are performed before data enters the routing distribution, and data that fails to pass is directly discarded. The rate limiting mechanism includes single-transmission length limit, buffer backpressure limit, and receive buffer overflow protection. The single-transmission length limit restricts the maximum length of data retrieved and sent from the buffer in a single transaction in the mirror mode and bridging mode. The buffer backpressure limit advances the buffer pointer based on the actual number of bytes consumed by the USB endpoint, reserving unconsumed data for the next round of processing. The receive buffer overflow protection forcibly discards old data when the buffer usage exceeds a preset threshold.
5. A USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 4, characterized in that: The hardware data acceleration module is an eight-channel DMA, with each UART's receive and transmit functions occupying one DMA channel. The four UARTs occupy a total of eight DMA channels, each corresponding to the virtual COM port, used for direct data transmission between the virtual COM port's transmit / receive buffer and the UARTs. The serial communication peripheral module includes four UART ports, UART1 to UART4, which are internal hardware serial ports of the microcontroller. The external serial port module is an RS485 interface, serving as the external physical interface for the four UARTs. The SD log module is used to write the log data transmitted from the real-time log port to the SD card after queue buffering and log encapsulation, and to provide it to the host computer for reading via the storage MSC interface in a block-mapped manner.
6. A USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 5, characterized in that: The dropout detection self-recovery module includes a multi-dimensional status monitoring unit for monitoring USB endpoint status, UART transmission status, DMA transmission status, and buffer queue status. Specifically, the USB endpoint monitoring determines the physical connection status by reading changes in the USB frame number register within a preset time window; the UART transmission status monitoring determines whether the connection is stuck by maintaining a busy transmission flag and checking its duration; the DMA transmission status monitoring is achieved by checking the transmission error flag and the receive overflow flag; and the buffer queue monitoring determines overflow risk by calculating the ring buffer usage rate in real time.
7. A USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 6, characterized in that: The dropout detection self-recovery module also includes a tiered recovery unit, which includes a complete reset mechanism, a lightweight recovery mechanism, and a system-level recovery mechanism. The lightweight recovery mechanism clears the UART transmit busy flag buffer data, causing the transmit scheduler to re-trigger DMA transmission. The complete reset mechanism automatically escalates execution when the lightweight recovery is triggered more than a preset number of times within a preset time window. This includes pausing the DMA channel and disabling the UART peripheral, deinitializing the DMA and clearing the status flag, clearing the transmit ring queue, switching the RS485 transceiver back to receive mode, reconfiguring the DMA channel parameters, and re-enabling the UART peripheral. The system-level recovery mechanism triggers a soft reset of the MCU when the USB connection is disconnected for more than a preset time, causing the entire system to reinitialize and re-enumerate the USB.
8. A USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 7, characterized in that: The external serial port module enables half-duplex direction switching. Each UART is configured with an independent GPIO pin to control DE / RE, which defaults to receive mode upon power-up. Before sending data, the DE pin is first set high to put the transceiver into transmit mode, and then DMA is started to transfer the data to the UART data register. After the DMA transfer is completed, the UART hardware transmit completion flag TC is set, and the hardware automatically sets the flag after transmission is complete. When all the data to be transmitted is sent, a hardware timer is started to perform a configurable microsecond delay. After the timer expires, the DE pin is pulled low to restore the receive mode.
9. A USB virtual to multi-serial port communication system based on a domestically produced microcontroller according to claim 7, characterized in that: GPIO configuration, management, and programming adaptation can be achieved by configuring the command communication port, and the following content is also included. The host computer sends structured configuration frames through the configuration command communication port; After receiving the configuration frame, accumulating it, synchronizing the header, and combining the frames, ConfigCmd_Process() is called to distribute and process it uniformly. The validity of the target pin is verified by querying the preset GPIO pin whitelist. The level of the target pin is only allowed to be set if it exists in the whitelist; otherwise, an invalid pin error is returned. By sequentially pulling the BOOT pin of the target device high, then pulling the RESET pin low and then high again using the GPIO_SET command, the target device enters the serial port programming wait state. Execute the ROUTE_SET command to configure the specified virtual COM port and the corresponding UART channel to the default pass-through mode, and establish a data path between the host computer and the target device programming interface; The host computer sends the programming protocol data through the virtual COM port. After receiving the data, the system automatically transfers it to the corresponding UART's transmit register via DMA, and then sends it to the target device's bootloader via the external serial port module to complete the firmware download. After the flashing is complete, execute the GPIO_SET command again to pull the BOOT pin of the target device low and then pull the RESET pin low and then high again, so that the target device can boot from the new firmware.
10. A USB virtual to multi-serial port communication method based on a domestically produced microcontroller, implemented using a USB virtual to multi-serial port communication system based on a domestically produced microcontroller, characterized in that: This includes the downlink transmission from the host computer to the external serial port device. The host computer sends data through four virtual COM ports. The endpoint and interface management module is responsible for managing the connection status of all virtual COM ports, identifying the interface to which the data belongs in the data transmission and reception queue, and then the data enters the channel routing filtering and rate limiting module to determine the target channel according to the preset mapping rules and perform filtering and rate limiting mechanism checks. The checked data is sent to the corresponding channel's buffer and queue module for temporary storage. The hardware data acceleration module automatically moves the data from the memory buffer to the corresponding UART's transmit register, and finally the external serial port module drives the bus to complete the downlink transmission. It also includes uplink transmission from external serial port devices to the host computer. The external device sends data through the external serial port module, which receives it through the serial communication peripheral module. The serial communication peripheral module assembles the serial data into bytes. When a byte is received or a trigger threshold is reached, the hardware data acceleration module automatically moves the data to the buffer and queue module. The channel routing filtering and rate limiting module checks the data source and determines the data destination according to the currently effective routing table configuration. Data distribution is performed according to the routing configuration. Ordinary data is forwarded to the corresponding virtual COM port for the host computer to read. Log data is sent to the SD log module, formatted and encapsulated, and then written to the SD card. The data transmitted to the host computer is encapsulated into USB format and allocated to the correct virtual COM port through the endpoint and interface management module. Finally, the data is uploaded to the host computer, where the USB driver restores it to the corresponding virtual COM port, completing data acquisition and monitoring.