Method and device for converting RS232 or RS485 to AXI based on FPGA
By implementing the method and device of converting RS232 or RS485 to AXI on FPGA, the problem that RS232/RS485 protocol equipment cannot operate the AXI-LITE bus slave device register inside FPGA is solved, dynamic access and control of the equipment is realized, and the adaptability of the system is enhanced. sex and flexibility.
Patent Information
- Application Number
- CN202410738169.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-09-24
AI Technical Summary
Devices with the RS232/RS485 protocol cannot directly operate and control the slave device registers on the AXI-LITE bus protocol within the FPGA, resulting in the inability to achieve dynamic access and control of the slave device in some application scenarios.
Provide a method and device for converting RS232 or RS485 to AXI based on FPGA, which realizes protocol conversion by initializing the serial port, detecting falling edges, executing serial bit instructions, decoding control instructions and executing corresponding AXI write or read operation instructions, thereby allowing The RS232/RS485 protocol device operates the slave device register on the AXI-LITE bus protocol inside the FPGA.
The RS232/RS485 protocol device can effectively control the slave device register on the AXI-LITE bus protocol inside the FPGA, which solves the problem of dynamic access and control of the device and enhances the flexibility and adaptability of the system.
Smart Images

Figure CN118689818A
Abstract
Description
Technical Field
[0001] The invention belongs to the field of FPGA, and in particular relates to a method and device for converting RS232 or RS485 to AXI based on FPGA. Background Art
[0002] The AXI (Advanced Extensible Interface) bus protocol is the most important part of the AMBA (Advanced Microcontroller Bus Architecture) 3.0 protocol proposed by ARM. It is an on-chip bus for high performance, high bandwidth, and low latency. AXI-LITE (for high-performance memory-mapped requirements) belongs to a type of protocol in the AXI bus protocol. It is a lightweight address-mapped single-transmission interface that occupies very little logic resources. Xilinx has provided support for the AXI bus since the 6 series of FPGAs. Today, many of Xilinx's IP cores support the AXI-LITE interface, and some IP cores can only interact with it through the AXI-LITE interface to control its registers to implement specific functions, such as Xilinx's AXIQuad SPI IP core, this IP core can only configure its internal registers through the AXI-LITE bus to control what data the IP core's SPI bus sends and when to send data. In the process of software development, most FPGA developers will use IP cores to develop software projects to shorten the software development cycle and save development costs. There are many IP cores with AXI-LITE interfaces. These IP cores are often hung on the AXI-LITE bus as slave devices. The master device hanging on the AXI-LITE bus configures the registers of each module to realize the operation of the entire system. In some application scenarios, it is necessary to dynamically access the slave devices of the AXI-LITE bus from the outside to control the working status of the slave devices. However, in actual work, the control of the slave devices of the AXI-LITE bus requires the use of specific devices to control the register status through the AXI-LITE bus. Devices with RS232 / RS485 protocols cannot be used to operate and control the slave device registers on the AXI-LITE bus protocol inside the FPGA. Summary of the invention
[0003] The purpose of this embodiment is to provide a method and device for converting RS232 or RS485 to AXI based on FPGA, which is used to solve the problem that devices with RS232 / RS485 protocol cannot operate and control slave device registers on the AXI-LITE bus protocol inside the FPGA.
[0004] The present invention provides a method for converting RS232 or RS485 to AXI based on FPGA, comprising:
[0005] S100: Initialize the serial port, including setting the baud rate, stop bit, start bit, setting the state of the state machine to IDLE, and proceeding to step S200;
[0006] S200: Get the serial port level value, execute the serial port falling edge detection instruction, if the falling edge is true, set the state of the state machine to START, and proceed to step S300;
[0007] S300: the state machine executes a serial bit instruction to obtain serial port data according to the baud rate, stop bit, and start bit, wherein the serial bit instruction read instruction includes obtaining each frame of data according to a clock signal, and if a frame is received successfully, the state machine sets the state to STOP and proceeds to step S400;
[0008] S400: the state machine executes a decoding instruction to obtain a control instruction according to the serial port data;
[0009] If the control instruction is a write operation instruction, the state machine executes the AXI write operation instruction and proceeds to step S900;
[0010] If the control instruction is a read operation instruction, the state machine executes the AXI read operation instruction and proceeds to step S700;
[0011] S700: the state machine acquires AXI data according to the AXI read operation instruction, wherein acquiring AXI data is acquiring the state value of the slave device IP core register according to the AXI bus, including acquiring a 4-byte AXI address and a 4-byte operand from the serial port, executing an AXI write address operation instruction, and setting the state machine to the RADDR state. If the AXI write address operation is successful, the state machine is set to the RDATA state, and performs AXI bus slave device addressing and reads slave device data according to the 4-byte AXI address. The execution of reading slave device data includes acquiring the state value of the slave device IP core register, and proceeding to step S800;
[0012] S800: the state machine executes a serial port data write instruction according to the AXI data. If the serial port data write instruction is executed successfully, the state machine sets the state to IDLE.
[0013] S900: the state machine executes an AXI data write instruction according to the AXI write operation instruction, and if the AXI data write instruction is executed successfully, the state machine sets the state to IDLE; including: obtaining an operand instruction from a serial port, the operand instruction including obtaining a 4-byte address and a 4-byte operand, the 4-byte address is used by the state machine to perform slave device addressing of the AXI bus, and the 4-byte operand is used to perform IP core register modification of the slave device of the AXI bus; wherein the performing of slave device addressing of the AXI bus also includes setting the state of the state machine to WADDR, and the performing of IP core register modification of the slave device of the AXI bus also includes setting the state of the state machine to WDATA.
[0014] Furthermore, the falling edge detection instruction includes executing a change in the serial port level from high to low between two clock cycles, and determining that the falling edge is true.
[0015] Furthermore, the serial port read instruction includes counting the change of the serial port level value according to the clock signal and obtaining the bit input.
[0016] Furthermore, the serial port data write instruction includes executing the serial port data bit instruction output according to the baud rate, stop bit, and start bit.
[0017] Furthermore, the serial port data bit instruction includes executing the serial port bit output according to the clock signal.
[0018] Furthermore, the AXI data write instruction includes executing a write operation of a slave device register status value according to the AXI bus protocol.
[0019] Furthermore, the bit input includes performing bit counting according to the clock signal, and if the bit count value is 10, it is determined to be one frame.
[0020] The present invention also provides an FPGA-based RS232 / RS485 to AXI device, comprising:
[0021] Serial port initialization module: used for serial port initialization configuration, including: configuring serial port baud rate, start bit, and stop bit;
[0022] Serial port reading module: used to read the execution instructions sent by the host computer through the serial port, including executing serial port bit data reading according to the baud rate, start bit and stop bit;
[0023] Serial port sending module: used to obtain the status value of the slave device register according to the AXI bus protocol and output it to the host computer, including executing the serial port bit data output according to the baud rate, start bit and stop bit;
[0024] State machine module: used to execute protocol conversion instructions according to RS232 or RS485 protocol; including setting the state of the state machine to IDLE during initialization and executing the serial port wait instruction; detecting changes in serial port data bits, if the falling edge of the serial port data bit is true, the state machine sets the state to START, and executes serial port data bit reading, if the serial port data bit reads a frame of data successfully, the state machine state is set to STOP, and the state machine executes the protocol conversion instruction, wherein the protocol conversion instruction includes state conversion, and the state conversion includes IDLE (idle), START (start), STOP (stop), WADDR (AXI write address), WDATA (write AXI slave device data), RADDR (AXI read address), RDATA (read AXI slave device data).
[0025] Furthermore, the protocol conversion instruction also includes reading serial port data according to RS232 or RS485 and converting it into AXI bus protocol and executing it.
[0026] Furthermore, the AXI bus protocol includes executing decoding according to the frame data to obtain execution instructions, wherein the execution instructions include AXI bus slave device register read instructions and AXI bus slave device register write instructions.
[0027] The FPGA-based RS232 or RS485 to AXI conversion method and device of the present invention solves the problem that the RS232 / RS485 protocol device cannot operate and control the slave device register on the AXI-LI TE bus protocol inside the FPGA.
[0028] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 : A step diagram of the RS232 / RS485 to AXI conversion method based on FPGA provided by an embodiment of the present invention;
[0030] Figure 2 : A device structure diagram of an FPGA-based RS232 / RS485 to AXI device provided in an embodiment of the present invention;
[0031] Figure 3 : A state transition diagram of RS232 / RS485 to AXI based on FPGA provided in an embodiment of the present invention;
[0032] Figure 4 : A serial port read and write state transition diagram of RS232 / RS485 to AXI based on FPGA provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0034] The present invention provides a method for converting RS232 or RS485 to AXI based on FPGA (see Figure 1 ),include:
[0035] S100: Initialize the serial port. In this embodiment, the serial port initialization complies with the RS232 or RS485 standard, including setting the baud rate, stop bit, and start bit. The state machine function executes to set the state of the state machine to IDLE. Here, IDLE is the register state bit of the memory to store the state machine state, including the states of IDLE (idle), START (start), STOP (stop), WADDR (AXI write slave device addressing), WDATA (write AXI slave device data), RADDR (AXI read slave device addressing), and RDATA (read AXI slave device data); 3 bits are used for storage here, and step S200 is performed;
[0036] S200: Get the level value of the serial port, execute the serial port falling edge detection instruction, if the falling edge is true, set the state of the state machine to START, in this embodiment, the state machine function polls the serial port bit pin, and the falling edge detection method includes two clock instructions between two clock cycles to detect the serial port bit state, if the serial port bit changes from a high level to a low level between the two clock instructions, it is determined that the falling edge is valid; proceed to step S300;
[0037] S300: The state machine executes the serial bit command to obtain serial port data according to the baud rate, stop bit, and start bit, wherein the serial bit command reads the instruction including obtaining each frame of data according to the clock signal. If a frame is received successfully, the state machine sets the state to STOP. In this embodiment, the serial port frame data is received by the state machine (see Figure 4 -A), the state machine receives the serial data of the serial port under the control of the clock signal according to the serial port parameters baud rate, stop bit and start bit and converts it into a register value. In this embodiment, each frame of data includes a start bit, a stop bit and 8-bit data bits. A frame of data receives 10 bits. After receiving, it is placed in the memory register. It should be noted that the data placed in the register only has 8-bit data bits, and the stop bit and start bit are deleted, that is, a frame of data is one byte of data, and the state machine state is set to STOP, and step S400 is performed;
[0038] S400: the state machine executes a decoding instruction to obtain a control instruction according to the serial port data; in this embodiment, the state machine counts each frame of data, and if the count value is 3 bytes, obtains the first two bytes, and if the first two bytes are 0xAA and 0x55, it is determined to be a frame synchronization byte, which is a valid conversion instruction, and further obtains the third byte. If the third byte is 0x02, it is determined that the control instruction is an AXI write operation instruction, and step S900 is performed;
[0039] This step also includes determining that the control instruction is a read operation instruction if the data of the third byte is 0x04, and the state machine executes the AXI read operation instruction, and proceeds to step S700;
[0040] S700: the state machine acquires AXI data according to the AXI read operation instruction, the acquisition of AXI data is to acquire the state value of the IP core register of the slave device according to the AXI bus, and in this implementation, the acquisition of the state value of the slave device register includes the state machine continuing to acquire the operand instruction from the serial port, including a 4-byte AXI address and a 4-byte operand, the 4-byte AXI address and the 4-byte operand are placed in the register cache, and the AXI write address operation instruction is executed. The state machine is set to the RADDR state. If the AXI write address operation is successful, the state machine changes to the RDATA state, performs AXI bus slave device addressing and reads the slave device data according to the 4-byte AXI address, acquires the IP core register state value of the slave device according to the AXI bus, and performs step S800;
[0041] S800: The state machine executes a serial port data write instruction according to the AXI data. If the serial port data write instruction is executed successfully, the state machine sets the state to IDLE. In this embodiment, the IP core register state value write serial port instruction is executed to send the value of the IP core register to the host computer, including executing a serial port data bit instruction output according to the baud rate, stop bit, and start bit. The data bit output includes the bit output of the data of the IP core register. If successful, the state machine sets the state to IDLE.
[0042] S900: The state machine executes an AXI data write instruction according to the AXI write operation instruction. If the AXI data write instruction is executed successfully, the state machine sets the state to IDLE. In this embodiment, the state machine continues to obtain operand instructions from the serial port, obtains 8 bytes of data, including a 4-byte AXI address and a 4-byte operand, and the 4-byte AXI address and the 4-byte operand are placed in the register cache, and the AXI write address operation instruction is executed. The state machine is set to the WADDR state. If the AXI write address operation is successful, the state machine changes to the WDATA state, performs AXI bus slave device addressing according to the 4-byte AXI address and writes the IP core register status data of the slave device, and obtains the write result of the slave device data according to the AXI bus. If successful, the state machine sets the state to IDLE.
[0043] This embodiment also provides an FPGA-based RS232 / RS485 to AXI converter, comprising:
[0044] Serial port initialization module: used for serial port initialization configuration, including: configuring serial port baud rate, start bit, and stop bit;
[0045] Serial port reading module: used to read the execution instructions sent by the host computer through the serial port, including executing serial port asynchronous data reading according to the baud rate, start bit, and stop bit, and converting the valid data into 8-bit parallel data output, see Figure 4 -A shows the state machine transition diagram of serial port reception. There are three states, namely IDLE, START, and STOP. When no serial port data is sent, the state machine is in the IDLE state, that is, the idle state. When the falling edge of the serial port signal is detected, the state machine jumps to the START state. In this state, the counter starts counting according to the baud rate. Through the count value identification, the valid serial port data is stored from low to high in the register with a bit width of 8 bits. After completing the counting of one frame of data, the state machine jumps to the STOP state. At this time, the data stored in the register is output, and a data valid identification signal with a bit width of 1 bit is output at the same time. Finally, it jumps to the IDLE idle state and waits for the arrival of the next data. A frame of serial port data includes a start bit, eight data bits and 1 stop bit.
[0046] Serial port sending module: used to obtain the status value of the slave device register according to the AXI bus protocol and output it to the host computer, including executing serial port asynchronous data writing according to the baud rate, start bit and stop bit; the received data in this embodiment is sent out through the serial port protocol, see Figure 4-B shows the state machine of the serial port sending module. There are three states, namely IDLE, START and STOP. When no serial port data is sent, the state machine is in IDLE state, that is, idle state. When the serial port output pin is detected to have a rising edge trigger when data is sent, the detection method is also a single instruction between two clock cycles to obtain the state of the serial port output pin. If it changes from a low level to a high level, it is determined that the serial port is allowed to send, and the state machine jumps to the START state. In this state, the counter starts counting according to the baud rate. Through the count value mark, the 1-bit start bit, 8-bit data and 1-bit stop bit are sent in sequence. When one frame of data is counted, it means that 1 byte of data transmission is completed, and the state machine jumps to the STOP state. At this time, the output bit width of 1 bit of data is sent and the mark is completed. Finally, it jumps to the IDLE idle state and waits for the next data to arrive.
[0047] State machine module: used to execute protocol conversion instructions according to RS232 or RS485 protocol; including initializing the state machine to set the state to IDLE and execute the serial port wait instruction; detecting the change of the serial port data bit, if the falling edge of the serial port data bit is true, the state machine sets the state to START, executes the serial port data bit reading, if the serial port data bit reads a frame of data successfully, executes the frame data counting and decodes the AXI instruction, first reads three bytes of data, if the first two bytes are 0xAA55, it is determined to be a frame synchronization byte, obtains the third byte, if the third byte is 0x02, it is determined to be a write operation instruction, executes the write operation to the IP core register status value of the slave device, and the write operation is written to the slave device according to the AXI bus; if the third byte is 0x04, it is determined to be a read operation instruction, executes the read instruction to obtain the slave device IP core register status value, and the read instruction is obtained according to the AXI bus; also includes executing the state according to the serial port instruction The working state transition of the machine includes IDLE, START, STOP, WADDR (AXI write address), WDATA (write AXI slave device data), RADDR (AXI read address), RDATA (read AXI slave device data), the START state obtains serial port data, the STOP state ends the reading of a frame of data, WADDR performs address addressing of write data of the AXI bus slave device, WDATA performs address addressing of serial port data written into the IP core register, RADDR performs address addressing of read data of the AXI bus slave device, and RDATA performs the IP core register status value of the AXI bus slave device to be sent to the host computer through the serial port. The host computer executes RS232 or RS485 specifications through the serial port, including the bit serial output of the IP core register status value according to the baud rate, start bit, and stop bit. The detailed state transition process is as follows:
[0048] The default state is IDLE state. When the data sent by the serial port receiving module is 0xAA5504, it is determined to be an AXI read operation, where AA55 is the frame synchronization word and 04 is the AXI-LITE read operation command word. After receiving AA5504, the state machine enters the RADDR state. At this time, the 4-Byte data subsequently transmitted is encapsulated as the value of the read address on the AXI-LITE bus, and the read address valid signal m_axi_arvalid is output. Then the state machine enters the RDATA state, at which time the read preparation signal m_axi_rready is output. If the slave returns the read valid signal m_axi_rvalid, the data m_axi_rdata[31:0] on the bus is saved and split into 4 bytes and sent to the serial port sending module. At the same time, the data valid mark is output. When the value of the read response signal m_axi_rresp[1:0] returned by the slave is 0, it means that the read transmission status is OK, and the state machine returns to the IDLE idle state, waiting for the next data to arrive.
[0049] The FPGA-based RS232 or RS485 to AXI conversion method and device of the present invention solves the problem that the RS232 / RS485 protocol device cannot operate and control the slave device register on the AXI-LI TE bus protocol inside the FPGA.
[0050] The above description is only an embodiment of the present invention and is not intended to limit the scope of protection of the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of protection of the present invention.
Claims
1. A method of converting RS232 or RS485 to AXI based on FPGA. It is characterized in that include: S100: Initialize the serial port, including setting the baud rate, stop bit, start bit, setting the state of the state machine to IDLE, and proceeding to step S200; S200: Get the serial port level value, execute the serial port falling edge detection instruction, if the falling edge is true, set the state of the state machine to START, and proceed to step S300; S300: the state machine executes a serial bit instruction to obtain serial port data according to the baud rate, stop bit, and start bit, wherein the serial bit instruction read instruction includes obtaining each frame of data according to a clock signal, and if a frame is received successfully, the state machine sets the state to STOP and proceeds to step S400; S400: the state machine executes a decoding instruction to obtain a control instruction according to the serial port data; If the control instruction is a write operation instruction, the state machine executes the AXI write operation instruction and proceeds to step S900; If the control instruction is a read operation instruction, the state machine executes the AXI read operation instruction and proceeds to step S700; S700: the state machine acquires AXI data according to the AXI read operation instruction, wherein the acquisition of AXI data is to acquire the state value of the slave device IP core register according to the AXI bus, including acquiring a 4-byte AXI address and a 4-byte operand from the serial port, executing an AXI write address operation instruction, and setting the state machine to the RADDR state. If the AXI write address operation is successful, the state machine is set to the RDATA state, and performs AXI bus slave device addressing and reads slave device data according to the 4-byte AXI address. The execution of reading slave device data includes acquiring the state value of the slave device IP core register, and proceeding to step S800; S800: the state machine executes a serial port data write instruction according to the AXI data. If the serial port data write instruction is executed successfully, the state machine sets the state to IDLE; S900: The state machine executes an AXI data write instruction according to the AXI write operation instruction. If the AXI data write instruction is executed successfully, the state machine sets the state to IDLE; including: obtaining an operand instruction from a serial port, the operand instruction including obtaining a 4-byte address and a 4-byte operand, the 4-byte address is used by the state machine to perform slave device addressing of the AXI bus, and the 4-byte operand is used to perform IP core register modification of the slave device of the AXI bus; wherein the execution of slave device addressing of the AXI bus also includes setting the state of the state machine to WADDR, and the execution of IP core register modification of the slave device of the AXI bus also includes setting the state of the state machine to WDATA.
2. The method according to claim 1, wherein RS232 or RS485 based on FPGA turns AXI. It is characterized in that The falling edge detection instruction includes executing a change in the serial port level from high to low between two clock cycles, and determining that the falling edge is true.
3. The method according to claim 1 for converting RS232 or RS485 based on FPGA to AXI, It is characterized in that The serial port read instruction includes executing the counting of the serial port level value change according to the clock signal and obtaining the bit input.
4. The method according to claim 1 for converting RS232 or RS485 based on FPGA to AXI, It is characterized in that The serial port data write instruction includes executing a serial port data bit instruction output according to the baud rate, stop bit, and start bit.
5. The method according to claim 4 for converting RS232 or RS485 based on FPGA to AXI, It is characterized in that The serial port data bit instruction includes executing the bit output of the serial port according to the clock signal.
6. The method of converting RS232 or RS485 based on FPGA to AXI according to claim 1, It is characterized in that The AXI data write instruction includes executing a write operation of a slave device register status value according to the AXI bus protocol.
7. The method according to claim 3 for converting RS232 or RS485 based on FPGA to AXI, It is characterized in that The bit input includes performing bit counting according to a clock signal, and if the bit count value is 10, it is determined as one frame.
8. A device for converting RS232 / RS485 to AXI based on FPGA, comprising: Serial port initialization module: used for serial port initialization configuration, include: Configure the serial port baud rate, start bit, and stop bit; Serial port reading module: used to read the execution instructions sent by the host computer through the serial port, including executing serial port bit data reading according to the baud rate, start bit and stop bit; Serial port sending module: used to obtain the status value of the slave device register according to the AXI bus protocol and output it to the host computer, including executing the serial port bit data output according to the baud rate, start bit and stop bit; State machine module: used to execute protocol conversion instructions according to RS232 or RS485 protocol; including setting the state of the state machine to IDLE during initialization and executing the serial port wait instruction; detecting changes in serial port data bits, if the falling edge of the serial port data bit is true, the state machine sets the state to START, and executes serial port data bit reading, if the serial port data bit reads a frame of data successfully, the state machine state is set to STOP, and the state machine executes the protocol conversion instruction, wherein the protocol conversion instruction includes state conversion, and the state conversion includes IDLE (idle), START (start), STOP (stop), WADDR (AXI write address), WDATA (write AXI slave device data), RADDR (AXI read address), RDATA (read AXI slave device data).
9. The device for converting RS232 or RS485 to AXI based on FPGA according to claim 8, It is characterized in that The protocol conversion instruction also includes reading serial port data according to RS232 or RS485 and converting it into AXI bus protocol and executing it.
10. The device for converting RS232 or RS485 to AXI based on FPGA according to claim 8 or 9. It is characterized in that The AXI bus protocol includes executing decoding according to the frame data to obtain execution instructions, wherein the execution instructions include AXI bus slave device register read instructions and AXI bus slave device register write instructions.
Citation Information
Cited By
Chip test platform and system based on FPGA
CN120123162A
