Method for processing diagnostic data in ECU based on SPI communication and ECU

By using SPI communication method in the ECU, setting the priority of diagnostic messages and performing checksum encryption, and using the GPIO signal line for two-way notification, the problem of low cross-core data transmission efficiency in the ECU is solved, and more efficient and reliable data transmission is achieved.

CN119644977AActive Publication Date: 2025-03-18CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202411551251.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-01
Publication Date
2025-03-18
Estimated Expiration
2044-11-01

AI Technical Summary

Technical Problem

In the prior art, the ECU's mid-span core data transmission efficiency is low, resulting in insufficient system performance and reliability.

Method used

Using SPI communication method, the diagnostic packets are prioritized and checksum encrypted through SoC, and two-way notification is used for GPIO signal lines to improve the efficiency and reliability of cross-core data transmission.

Benefits of technology

Through priority processing and encryption and decryption, we ensure rapid response of important diagnostic requests, improve cross-core data transmission efficiency, and enhance the security and stability of data transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119644977A_ABST
    Figure CN119644977A_ABST
Patent Text Reader

Abstract

The invention relates to a method for processing diagnostic data in an ECU (Electronic Control Unit) based on SPI (Serial Peripheral Interface) communication and the ECU, the ECU comprises a master device and a slave device, an SoC (System on Chip) is integrated on the master device, an MCU (Microprogrammed Control Unit) is integrated on the slave device, the method comprises the following steps: the SoC sets a priority for a diagnostic message sent by a client, and verifies and encrypts the diagnostic message after the priority is set; after verification and encryption are completed, the SoC notifies the slave device to receive data based on the first signal line; after receiving the notification sent by the SoC based on the first signal line, the MCU notifies the SoC to receive the processed diagnosis message based on the second signal line, decrypts and analyzes the processed diagnosis message sent by the MCU based on the third signal line, and sends a diagnosis response message to the SoC based on the fourth signal line; and the SoC transmits the diagnosis response message back to the client. According to the method and the device, the problem of relatively low cross-core data transmission efficiency in the ECU in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of automobile communications, and in particular to a method for processing diagnostic data in an ECU based on SPI communication, and an ECU. Background Art

[0002] With the rapid development of automotive electronic technology, the number of electronic control units (ECUs) in vehicles is increasing. These ECUs need to exchange data and diagnose through various communication protocols. The electronic systems of modern automobiles often include complex network architectures, which use a variety of different communication protocols, such as controller area network (CAN), local interconnect network (LIN), Flex Ray, and Ethernet. In order to improve the performance and reliability of the system, especially in the application of diagnostic and control systems, an efficient and reliable cross-core data transmission and processing algorithm is needed. In order to meet the cross-core diagnostic data transmission requirements between the system-on-chip (SoC) module and the microcontroller unit (MCU) in the ECU, the current method is to use a dedicated gateway device to achieve protocol conversion, or to process data through software algorithms, but the existing method has the problem of low data transmission efficiency in practical applications. Summary of the invention

[0003] The present application provides a method for processing diagnostic data in an ECU based on SPI communication and an ECU to solve the problem of low cross-core data transmission efficiency in the ECU in the prior art.

[0004] In a first aspect, the present application provides a method for processing diagnostic data in an ECU based on SPI communication, characterized in that the ECU includes a master device and a slave device, the master device is integrated with a system on chip SoC, and the slave device is integrated with a microcontroller unit MCU, and the method includes: the SoC sets a priority for the diagnostic message sent by the client, and verifies and encrypts the diagnostic message after the priority is set; after the verification and encryption are completed, the SoC notifies the slave device to receive data based on a first signal line; wherein the first signal line corresponds to the general input and output GPIO1 pin in the master device and the slave device; after receiving the notification sent by the SoC based on the first signal line, the MCU notifies the SoC to receive the processed diagnostic message based on the second signal line, and decrypts and parses the processed diagnostic message sent by the MCU based on the third signal line, and sends a diagnostic response message to the SoC based on the fourth signal line; wherein the second signal line corresponds to the general input and output GPIO2 pin in the master device and the slave device; the third signal line corresponds to the master-output slave-input data line MISO, and the fourth signal line corresponds to the master-input slave-output data line MOS; the SoC returns the diagnostic response message to the client.

[0005] In a second aspect, the present application provides an electronic control unit ECU, the ECU comprising a master device and a slave device, the master device being integrated with a system on chip SoC, and the slave device being integrated with a microcontroller unit MCU; the SoC being used to set a priority for a diagnostic message sent by a client, and to verify and encrypt the diagnostic message after the priority is set; after the verification and encryption are completed, the slave device is notified to receive data based on a first signal line; wherein the first signal line corresponds to a general-purpose input and output GPIO1 pin in the master device and the slave device; the MCU being used to notify the SoC to receive the processed diagnostic message based on a second signal line after receiving the notification sent by the SoC based on the first signal line, and to decrypt and parse the processed diagnostic message sent by the MCU based on a third signal line, and to send a diagnostic response message to the SoC based on a fourth signal line; wherein the second signal line corresponds to a general-purpose input and output GPIO2 pin in the master device and the slave device; the third signal line corresponds to a master-output slave-input data line MISO, and the fourth signal line corresponds to a master-input slave-output data line MOS; the SoC is used to transmit the diagnostic response message back to the client.

[0006] In a third aspect, the present application provides an electronic device comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus, wherein the processor is configured to execute the method for processing diagnostic data in an ECU based on SPI communication as described in the first aspect of the present application.

[0007] In a fourth aspect, the present application further provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the method for processing diagnostic data in an ECU based on SPI communication as described in the first aspect of the present application.

[0008] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: In the embodiment of the present application, the SoC in the master device receives the diagnostic message sent by the client, and performs priority processing on the diagnostic message, and performs verification and encryption according to the priority. By setting the priority of the diagnostic message, it can be ensured that important diagnostic requests can be responded to quickly. In addition, the master device and the slave device can perform two-way notification based on the GPIO1 pin and the GPIO2 pin, that is, when the SoC can send data to the MCU, it can first send a notification to the MCU based on the GPIO1 pin, and then the MCU sends a notification to the SoC based on the GPIO2 pin that it can receive data, thereby avoiding frequent polling of the SoC and improving the synchronization and coordination efficiency between cores. In addition, the data can be verified and encrypted in the master device, and the received slave device can decrypt the data, and the reliability and stability of the data during the transmission process are improved by encryption and decryption. It can be seen that, through the method of the embodiment of the present application, the problem of low efficiency of cross-core data transmission in the prior art is solved, the data transmission efficiency is improved, and the security during the data transmission process is also guaranteed. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0010] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0011] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0012] Figure 1 A schematic diagram of the structure of an ECU provided in an embodiment of the present application;

[0013] Figure 2 A flow chart of a method for processing diagnostic data in an ECU based on SPI communication provided in an embodiment of the present application;

[0014] Figure 3 This is a schematic diagram of the structure of the ECU in a specific example of this application;

[0015] Figure 4 This is a flow chart of data processing based on SPI by ECU in a specific example of this application;

[0016] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0017] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0018] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.

[0019] In order to solve the problem of low cross-core data transmission efficiency in ECU in the prior art, the present application provides a method for processing diagnostic data in ECU based on SPI communication, such as Figure 1 As shown, the ECU in the embodiment of the present application includes a master device and a slave device, wherein the master device is integrated with a system on chip SoC, and the slave device is integrated with a microcontroller unit MCU. Based on this, the method in the embodiment of the present application is as follows: Figure 2 As shown, the following steps may be included:

[0020] Step 201, the SoC sets a priority for the diagnostic message sent by the client, and verifies and encrypts the diagnostic message after the priority is set;

[0021] Step 202, after verification and encryption are completed, notify the slave device to receive data based on the first signal line; wherein the first signal line corresponds to the general-purpose input and output GPIO1 pin in the master device and the slave device;

[0022] In an embodiment of the present application, by setting priorities, critical tasks or critical data packets can be processed preferentially to ensure that important diagnostic requests can be responded to quickly. For example, the current diagnostic message can be used to read ECU information, fault codes, and perform fault diagnosis and ECU flashing. The priority of the diagnostic message for fault diagnosis can be set to the highest, followed by the priority of the diagnostic message for reading fault codes, followed by the priority of the diagnostic message for reading ECU information, and the priority of the diagnostic message for ECU flashing is the lowest. The above is only an example, and the priority setting of the diagnostic message can be set accordingly according to actual needs in a specific application scenario.

[0023] It should be noted that the signal lines in the embodiments of the present application are all based on the SPI (Serial Peripheral Interface) protocol for data transmission. In the embodiments of the present application, six signal lines may be specifically included, namely, a clock line (Serial Clock, SCK), a master input slave input data line (Master Input Slave Output, MISO), a master input slave output data line (Master Output Slave Input, MOSI) and a chip select line (Chip Select, CS), and a signal line composed of a GPIO1 pin and a GPIO2 pin; wherein, the clock line and the chip select line will be used in the actual data transmission process, that is, the clock line is used to trigger the clock signal, and the chip select line is used to generate a chip select signal so that the master chip selects the slave chip.

[0024] Step 203, after receiving the notification sent by the SoC based on the first signal line, the MCU notifies the SoC based on the second signal line to receive the encrypted diagnostic message, decrypts and parses the processed diagnostic message sent by the MCU based on the third signal line, and sends a diagnostic response message to the SoC based on the fourth signal line; wherein the second signal line corresponds to the universal input and output GPIO2 pin in the master device and the slave device; the third signal line corresponds to the master-output slave-input data line MISO, and the fourth signal line corresponds to the master-input slave-output data line MOS;

[0025] It should be noted that before there are signal lines based on GPIO1 pin and GPIO2 pin, the existing MCU end cannot actively notify the SoC of the data status, resulting in the need for frequent polling on the SoC end, resulting in a high data processing delay. In the embodiment of the present application, the GPIO1 pin and the GPIO2 pin can be used to realize two-way notification when the master device and the slave device exchange data. Therefore, the MCU can actively notify the data status (whether it can receive data) through the GPIO2 pin, thereby reducing the delay of data processing, improving the real-time performance of the system for data processing, and also improving the efficiency of cross-core synchronization and coordination.

[0026] Step 204: The SoC sends a diagnostic response message back to the client.

[0027] Through the above steps 201 to 204, in an embodiment of the present application, the SoC in the master device receives the diagnostic message sent by the client, and prioritizes the diagnostic message, and verifies and encrypts it according to the priority. By setting the priority of the diagnostic message, it can be ensured that important diagnostic requests can be responded to quickly. In addition, the master device and the slave device can perform two-way notification based on the GPIO1 pin and the GPIO2 pin, that is, when the SoC can send data to the MCU, it can first send a notification to the MCU based on the GPIO1 pin, and then the MCU sends a notification to the SoC based on the GPIO2 pin that it can receive data, thereby avoiding frequent polling of the SoC and improving the cross-core synchronization and coordination efficiency. In addition, the data can be verified and encrypted in the master device, and the received slave device can decrypt the data, and the reliability and stability of the data during the transmission process are improved by encryption and decryption. It can be seen that, through the method of the embodiment of the present application, the problem of low efficiency of cross-core data transmission in the prior art is solved, the data transmission efficiency is improved, and the security during the data transmission process is also guaranteed.

[0028] In the embodiment of the present application, the received diagnostic message can be prioritized, that is, the priority is set according to the importance of the diagnostic message to ensure that the diagnostic message with high importance is processed first. Therefore, the SoC involved in the above step 201 sets the priority of the diagnostic message sent by the client, and the method of verifying and encrypting the diagnostic message after setting the priority can further include the following steps:

[0029] Step 11, the SoC caches the diagnostic message sent by the client, and sets a corresponding priority for the cached diagnostic message according to the importance of the diagnostic message;

[0030] In this regard, caching the received data can directly obtain data from the cache relative to frequent UDS (Unified Diagnostic Services) requests, instead of long-term data exchange through the network or ECU each time, which can significantly improve the response speed and efficiency of the system. In addition, by caching UDS requests, the number of direct accesses to the ECU can be reduced, thereby reducing the load on the ECU, extending its life, and improving the stability of the entire vehicle system.

[0031] Step 12: The SoC parses the diagnostic message in the buffer area according to the priority to obtain the payload data of the unified diagnostic service, and verifies and encrypts the payload data.

[0032] Through the above steps 11 and 12, different priorities can be set for diagnostic messages, and key tasks or data packets can be processed preferentially to ensure that important diagnostic requests can be responded to quickly. At the same time, for diagnostic messages with high priority, they are parsed to obtain the payload data of UDS (Unified Diagnostic Services). In the embodiment of the present application, UDS data is used to diagnose and diagnose electronic devices connected to the vehicle network. UDS diagnostic data is usually transmitted through CAN (Controller Area Network) or FlexRay network. In the CAN network, each message consists of the following parts: 1) Identifier: This is a unique ID used to specify the destination of the message. 2) Control Field: Contains the attributes of the message, such as priority and data length. 2) Data Field: This is the actual data payload, which can be DTC (Diagnostic Trouble Code), PID (Parameter Identifier) ​​value, or other diagnostic information. 3) CRC (Cyclic Redundancy Check): Used to detect errors in message transmission.

[0033] Further, in the embodiment of the present application, the method for the SoC involved in the above step 12 to verify and encrypt the payload data may further include:

[0034] Step 21, verifying the diagnostic session ID of the payload data, and reorganizing the payload data after the verification; wherein the reorganized data type is the data type that the MCU can receive;

[0035] Step 22, the SoC determines a corresponding check algorithm according to the data length of the reorganized data, determines a check code of the reorganized data according to the check algorithm, and appends the check code to the end of the reorganized data to obtain a complete data frame;

[0036] In step 23, the SoC generates an encryption key and uses a preset encryption algorithm to encrypt the complete data frame.

[0037] In an embodiment of the present application, the payload data obtained by parsing can be reorganized into a data type that can be received by the MCU end, specifically in the format of CANID (MCU request ID) + payload. This method simplifies the unpacking process, directly passes the parsed payload data to the other end, and improves the efficiency of transmission. In the embodiment of the present application, the role of data verification is to detect and correct diagnostic data errors during transmission, ensuring the accuracy and integrity of data transmission. In addition, in the embodiment of the present application, CRC (Cyclic Redundancy Check) can be used for verification. In a specific example, the verification process can be: 1) Determine the verification algorithm: determine the length of the data frame. If the length is less than or equal to 256 bytes, CRC-16 is used. If the length is greater than 256 bytes, CRC-32 verification is used. 2) Calculate the check code: calculate the check code of the data according to the selected check algorithm. 3) Attach the check code: attach the calculated check code to the back of the data to form a complete data frame. Taking 8 bytes of data as an example, a 2-byte CRC-16 check code can be attached.

[0038] In addition, data encryption is used to protect the data security during transmission and prevent the data from being illegally intercepted and tampered with. Therefore, in the embodiment of the present application, AES (Advanced Encryption Standard, symmetric encryption algorithm) can be used for data encryption, and the specific process includes: 1) Select an encryption algorithm: Select a suitable symmetric encryption algorithm, such as AES-128, AES-192 or AES-256. For example, select the AES-128 encryption algorithm, which has a fast encryption and decryption speed and can ensure the real-time performance of data transmission. The encryption key length is 128 bits. 2) Preset encryption key, generate or preset encryption key. Take a 16-byte (128-bit) key as an example: {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}. 3) Encrypted data: Use an encryption algorithm to encrypt the data. Taking 8-byte data as an example, AES-128 can be used for encryption.

[0039] In the embodiment of the present application, bidirectional notification can be performed through the GPIO1 pin and the GPIO2 pin to improve the data transmission efficiency. Therefore, the method of the SoC involved in the above step 201 to notify the slave device of receiving data based on the first signal line may further include:

[0040] Step 31, the SoC initializes the GPIO1 pin and the GPIO2 pin, as well as the serial peripheral interface SPI properties of the signal line;

[0041] Step 32, the SoC sets the signal of the GPIO1 pin from a low level to a high level to notify the slave device to receive data.

[0042] In an embodiment of the present application, the GPIO pins (including the GPIO1 pin and the GPIO2 pin) and SPI properties are initialized in the constructor of the encapsulated SPI class, such as whether the SPI is synchronous communication or asynchronous communication, or whether it supports full-duplex communication or half-duplex communication, master-slave mode, and multi-slave management and other properties; then, a thread is created to register the FD (FileDescriptor) of GPIO2 with the epoll instance, and the epoll_wait function is called to block and wait for the event to occur, and detect whether it is a rising edge (the level signal changes from a low level to a high level). If so, the semaphore is released for notification, and finally a thread is created for blocking the acquisition of the semaphore to put the processed data back into the callback function epoll_wait.

[0043] Based on this, the method for the SoC involved in the above step 203 to send the processed diagnostic message to the MCU based on the third signal line can further be: when the SoC determines that the signal of the GPIO2 pin changes from a low level to a low level to a high level as a rising edge, the complete data frame is sent to the MCU based on the third signal line.

[0044] In this regard, in a specific example, the incoming data is first stored in the MCU's ring buffer, and GPIO1 is pulled high (the level signal changes from low level to high level) to notify the MCU to receive data, based on the above epoll_wait function blocking, and judging whether GPIO2 is a rising edge level signal from low level to high level, if so, release the semaphore, pull down GPIO1, and send data. If not, continue to wait.

[0045] Furthermore, in the embodiment of the present application, for the slave device, since the received data is encrypted data, it is necessary to decrypt the received data. Based on this, the method in which the MCU involved in 203 in the embodiment of the present application decrypts the processed diagnostic message may further include:

[0046] Step 41, the MCU extracts the encrypted data from the received data frame;

[0047] Step 42, the MCU decrypts the encrypted data using a decryption algorithm and an encryption key corresponding to a preset encryption algorithm;

[0048] Step 43, the MCU calculates a check code for the decrypted data, and determines that the received data is correct when the calculated check code is consistent with the received check code.

[0049] For the above steps 41 to 43, in a specific example, after receiving the data from the buffer, the MCU will decrypt the data, verify the decrypted data, and respond to it. In this regard, the decryption of the data may include the following processes: 1) Extracting encrypted data. Extracting encrypted data from the received data frame. 2) Decrypting data: Decrypting the encrypted data using the same encryption key and decryption algorithm.

[0050] The data verification process may include: after the data is decrypted, it is necessary to calculate the check code of the received data and compare it with the received check code. The specific process is: 1) Extract the check code. Extract the check code from the received data frame. Taking a 10-byte data frame as an example, extract the last 2 bytes as the check code. 2) Calculate the check code. Calculate the check code for the received data part (excluding the check code). 3) Verification comparison: Compare the calculated check code with the received check code. If they are consistent, the data transmission is correct; if they are inconsistent, an error occurs in the data transmission and needs to be retransmitted, that is, the SoC needs to retransmit the processed diagnostic message to the MCU.

[0051] In the embodiment of the present application, the method of sending the diagnostic response message based on the fourth signal line by the MCU involved in the above step 203 may further include:

[0052] Step 51, the MCU determines the source of the diagnostic request according to the diagnostic session ID, and generates a corresponding diagnostic response message according to the unified diagnostic service protocol;

[0053] Step 52: The MCU sends a diagnostic response message to the SoC based on the fourth signal line.

[0054] It can be seen that in the embodiment of the present application, the diagnostic session ID can be specifically the CANID of the data, that is, the source of the diagnostic request can be determined according to the CANID, and then the corresponding diagnostic response message is generated according to the UDS protocol, and the diagnostic response message is transmitted to the SoC through the SPI callback function. The SoC parses and strips the received CAN message to obtain the final diagnostic response data, and stores it in the data buffer, and finally transmits the diagnostic response data back to the client through the DoIP protocol.

[0055] The present application is explained below in conjunction with the specific implementation of the embodiment of the present application, which provides a cross-core diagnostic data transmission and processing method based on SPI communication. Figure 3 The figure shows the system architecture diagram of the cross-core diagnostic data transmission and processing algorithm based on six-wire SPI communication. The system includes three parts: SoC, MCU and six-wire SPI communication interface. Among them, SoC is used for scheduling and controlling diagnostic tasks. The SoC includes a doipserver module and a datahandle module. The doipserver module is used to receive diagnostic messages, including a data buffer and a priority processing unit; the datahandle module is used for data parsing and processing, data verification and encryption to ensure the integrity and security of data transmission, which may specifically include data parsing and processing, data verification and encryption. MCU is used for diagnostic data processing, which may specifically include receiving diagnostic messages, data verification and decryption, parsing data, processing data, and returning results. MCU includes a data buffer, a data verification and decryption unit, and a parsing and processing unit.

[0056] In addition, the existing SPI communication between SoC and MCU adopts a 4-wire system. The 4-wire SPI communication interface includes a clock line (SCK), a master-output slave-input data line (MISO), a master-input slave-output data line (MOSI) and a chip select line (CS). However, the existing method lacks a two-way notification mechanism, which leads to difficulties in synchronization and coordination. The MCU end cannot actively notify the SoC of the data status, resulting in the need for frequent polling on the SoC end, and a high delay in data processing. Therefore, the embodiment of the present application adds two signal lines to the original four-wire SPI, that is, the embodiment of the present application is based on a six-wire SPI communication interface for data transmission between the master core and the slave core, such as Figure 3 As shown in the figure, the two newly added signal lines are marked as SPI5 and SPI6. These two idle GPIO pins are used to realize the bidirectional notification function when exchanging data between the SOC host and the MCU slave.

[0057] exist Figure 3 On the basis of Figure 4 The figure shows a cross-core diagnostic data transmission and processing flow based on SPI communication. Based on this, the steps of the cross-core diagnostic data transmission and processing method based on SPI communication include:

[0058] Step 301, doipclient (communication protocol client based on Ethernet) simulates diagnostic instrument, sends diagnostic message to SoC based on DOIP (Diagnostic communication over Internet Protocol, communication protocol based on Ethernet), and the data buffer of doipserver in SoC stores the requested UDS service. In addition, the priority processing module in doipserver sets different priorities for data packets, and parses the diagnostic message with high priority to obtain payload.

[0059] In this way, for frequent UDS requests, data can be directly obtained from the cache instead of long-term data exchange through the network or ECU each time, which can significantly improve the response speed and efficiency of the system. In addition, by caching UDS requests, the number of direct accesses to the ECU can be reduced, thereby reducing the load on the ECU, extending its life, and improving the stability of the entire vehicle system.

[0060] Step 302: Pass the payload into the datahandle (data operation) module to verify its diagnostic session ID.

[0061] By verifying the diagnostic session ID, it can be ensured that the ECU can continuously track and correctly process requests, maintain consistency in diagnostic status and context, and ensure the effectiveness of security and authorization verification. It is also essential for implementing complex diagnostic and programming operations, maintaining communication consistency, and preventing unauthorized access. After the diagnostic session ID is verified, data structure conversion, verification, and encryption processing are required. The process includes:

[0062] 1) Data structure conversion: The payload data obtained from the doipsever module is reorganized into a data type that can be received by the MCU. In the embodiment of the present application, it is reorganized in the format of CANID (MCU request ID) + payload. This method simplifies the unpacking process and directly passes the parsed payload data to the other end, thereby improving the transmission efficiency.

[0063] 2) Data verification: Data verification is used to detect and correct diagnostic data errors during transmission to ensure the accuracy and integrity of data transmission. This patent uses CRC (Cyclic Redundancy Check). The following are the steps to implement data verification:

[0064] Step 61, determine the verification algorithm, that is, determine the length of the data frame. If the length is less than or equal to 256 bytes, use CRC-16. If the length is greater than 256 bytes, use CRC-32 verification.

[0065] Step 62, calculating the check code, that is, calculating the check code of the data according to the selected check algorithm.

[0066] Step 63, appending a check code, that is, appending the calculated check code to the end of the data to form a complete data frame.

[0067] 3) Data encryption: Data encryption is used to protect the security of data during transmission and prevent data from being illegally intercepted and tampered with. The encryption algorithm used in the embodiment of the present application is AES, and then a suitable symmetric encryption algorithm is selected, such as AES-128, AES-192 or AES-256. In the embodiment of the present application, the AES-128 encryption algorithm is selected. The encryption and decryption speed of this algorithm is fast, and the real-time performance of data transmission can be guaranteed. The encryption key length is 128 bits. Then, the encryption key is preset, that is, an encryption key is generated or preset, such as a 16-byte (128-bit) key. Finally, the data is encrypted. Specifically, an encryption algorithm can be used to encrypt the data. For example, taking 8-byte data as an example, AES-128 is used for encryption.

[0068] Step 303, the reassembled encrypted complete data frame is transmitted to the data buffer area of ​​the MCU via SPI, which is used to temporarily store the data during the transmission process. The data buffer area uses a FIFO (First In First Out) mechanism to manage data to ensure that the data is processed and transmitted in the order received. The process of SPI transmission of diagnostic data includes SPI initialization and transmission of data.

[0069] The SPI initialization process is as follows: Initialize the GPIO pins (including GPIO1 and GPIO2) and SPI attributes in the constructor of the encapsulated SPI class. Then, create a thread to register the FD of GPIO2 to the epoll instance, call the epoll_wait function to block and wait for the event to occur, and detect whether it is a rising edge and release the semaphore. Finally, create a thread for blocking the acquisition of the semaphore to put the processed data back to the callback function.

[0070] The process of data transmission is as follows: the datahandle module first calls the SPI transmission interface and passes in the first address and length of the encrypted complete data frame. Then, the incoming data is stored in the ring buffer, and GPIO1 is pulled high to notify the MCU to receive the data. Finally, the epoll_wait function is blocked and it is determined whether GPIO2 is a rising edge. If so, the semaphore is released, GPIO1 is pulled low, and the data is sent. If not, it continues to wait.

[0071] Step 304, after receiving the data from the buffer of diagAPP, the MCU will decrypt the data, perform post-received verification and data response processing.

[0072] In this regard, the data decryption process is as follows: Extract the encrypted data. Extract the encrypted data from the received data frame and encrypt the data in 8 bytes. Decrypt the data: Decrypt the encrypted data using the same encryption key and decryption algorithm.

[0073] In addition, the verification process of the data in the embodiment of the present application is: after the data is decrypted, the system needs to calculate the check code for the received data and compare it with the received check code. The specific process may be: first extract the check code, that is, extract the check code from the received data frame. Taking a 10-byte data frame as an example, extract the last 2 bytes as the check code. Then, calculate the check code, that is, calculate the check code for the received data part (excluding the check code). Finally, perform a check comparison, that is, compare the calculated check code with the received check code. If they are consistent, the data transmission is correct; if they are inconsistent, an error occurs in the data transmission and needs to be retransmitted.

[0074] Step 305, in the diagnostic response processing module of diagAPP, first determine the source of the diagnostic request according to CANID, then generate the corresponding diagnostic response message according to the UDS protocol, and pass it to the response callback function registered by SPI initialization. The SPI callback function transmits the diagnostic response message to the priority processing module on the doipserver side, which parses and strips the received CAN message to obtain the final diagnostic response data, stores it in the data buffer, and finally transmits the diagnostic response data back to the DoIP client through the DoIP protocol.

[0075] Corresponding to the above Figure 2 , the present application embodiment provides an electronic control unit ECU, such as Figure 1 As shown, the ECU includes a master device and a slave device, the master device is integrated with a system on chip SoC, and the slave device is integrated with a micro control unit MCU;

[0076] SoC, used to set the priority of the diagnostic message sent by the client, and verify and encrypt the diagnostic message after the priority is set; after the verification and encryption are completed, notify the slave device to receive data based on the first signal line; wherein the first signal line corresponds to the general input and output GPIO1 pin in the master device and the slave device;

[0077] The MCU is used to notify the SoC to receive the processed diagnostic message based on the second signal line after receiving the notification sent by the SoC based on the first signal line, decrypt and parse the processed diagnostic message sent by the MCU based on the third signal line, and send a diagnostic response message to the SoC based on the fourth signal line; wherein the second signal line corresponds to the universal input and output GPIO2 pin in the master device and the slave device; the third signal line corresponds to the master-output slave-input data line MISO, and the fourth signal line corresponds to the master-input slave-output data line MOS;

[0078] SoC is also used to send diagnostic response messages back to the client.

[0079] In an optional implementation manner of an embodiment of the present application, the SoC in the embodiment of the present application is also used to cache the diagnostic messages sent by the client, and set corresponding priorities for the cached diagnostic messages according to the importance of the diagnostic messages; and parse the cached diagnostic messages according to the priorities to obtain payload data of the unified diagnostic service, and verify and encrypt the payload data.

[0080] In an optional implementation of the embodiment of the present application, the SoC in the embodiment of the present application is further used to reorganize the unified diagnostic service data in the format of the controller area network CANID and the payload; wherein the CANID is the request ID of the MCU;

[0081] In an optional implementation manner of an embodiment of the present application, the SoC in the embodiment of the present application is also used to determine the corresponding verification algorithm according to the data length of the reorganized data, and determine the verification code of the reorganized data according to the verification algorithm, and append the verification code to the end of the reorganized data to obtain a complete data frame; and the SoC is also used to generate an encryption key and use a preset encryption algorithm to encrypt the complete data frame.

[0082] In an optional implementation of an embodiment of the present application, the SoC in the embodiment of the present application is also used to initialize the GPIO1 pin and the GPIO2 pin, and the serial peripheral interface SPI properties of the signal line; and to set the signal of the GPIO1 pin from a low level to a high level to notify the slave device to receive data.

[0083] In an optional implementation manner of the embodiment of the present application, the SoC in the embodiment of the present application is also used to determine that when the signal of the GPIO2 pin changes from a low level to a low level to a high level as a rising edge, send a complete data frame to the MCU based on the third signal line.

[0084] In an optional implementation manner of an embodiment of the present application, the MCU in the embodiment of the present application is also used to extract encrypted data from a received data frame, and use a decryption algorithm and an encryption key corresponding to a preset encryption algorithm to decrypt the encrypted data, and perform check code calculation on the decrypted data, and when the calculated check code is consistent with the received check code, determine that the received data is correct.

[0085] In an optional implementation manner of an embodiment of the present application, the MCU in the embodiment of the present application is also used to determine the source of the diagnostic request based on the diagnostic session ID, generate a corresponding diagnostic response message according to the unified diagnostic service protocol, and send a diagnostic response message to the SoC based on the fourth signal line.

[0086] like Figure 5 As shown, an embodiment of the present application provides an electronic device, including a processor 511, a communication interface 512, a memory 513 and a communication bus 514, wherein the processor 511, the communication interface 512, and the memory 513 communicate with each other through the communication bus 514.

[0087] Memory 513, used for storing computer programs;

[0088] In one embodiment of the present application, the processor 511 is used to execute the program stored in the memory 513 to implement the method for processing diagnostic data in the ECU based on SPI communication provided by any of the aforementioned method embodiments, and its role is similar and will not be repeated here.

[0089] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for processing diagnostic data in an ECU based on SPI communication as provided in any of the aforementioned method embodiments are implemented.

[0090] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0091] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0092] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.

[0093] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for processing diagnostic data in an ECU based on SPI communication, characterized in that: The ECU includes a master device and a slave device, wherein a system on chip SoC is integrated on the master device, and a microcontroller unit MCU is integrated on the slave device. The method includes: The SoC sets a priority for the diagnostic message sent by the client, and verifies and encrypts the diagnostic message after the priority is set; After verification and encryption are completed, the SoC notifies the slave device to receive data based on the first signal line; wherein the first signal line corresponds to the general-purpose input and output GPIO1 pin in the master device and the slave device; After receiving the notification sent by the SoC based on the first signal line, the MCU notifies the SoC based on the second signal line to receive the processed diagnostic message, decrypts and parses the processed diagnostic message sent by the MCU based on the third signal line, and sends a diagnostic response message to the SoC based on the fourth signal line; wherein the second signal line corresponds to the universal input and output GPIO2 pin in the master device and the slave device; the third signal line corresponds to the master-output slave-input data line MISO, and the fourth signal line corresponds to the master-input slave-output data line MOS; The SoC transmits the diagnosis response message back to the client.

2. The method according to claim 1, characterized in that The SoC sets a priority for the diagnostic message sent by the client, and verifies and encrypts the diagnostic message after the priority is set, including: The SoC caches the diagnostic message sent by the client, and sets a corresponding priority for the cached diagnostic message according to the importance of the diagnostic message; The SoC parses the cached diagnostic message according to the priority to obtain the payload data of the unified diagnostic service, and verifies and encrypts the payload data.

3. The method according to claim 2, characterized in that The SoC verifies and encrypts the payload data, including: The SoC verifies the diagnostic session ID of the payload data, and reorganizes the payload data after the verification; wherein the reorganized data type is a data type that the MCU can receive; The SoC determines a corresponding check algorithm according to the data length of the reorganized data, determines a check code of the reorganized data according to the check algorithm, and appends the check code to the reorganized data to obtain a complete data frame; The SoC generates an encryption key and encrypts the complete data frame using a preset encryption algorithm.

4. The method according to claim 3, characterized in that The SoC notifies the slave device to receive data based on the first signal line, including: The SoC initializes the GPIO1 pin and the GPIO2 pin, and the serial peripheral interface SPI properties of the signal line; The SoC sets the signal of the GPIO1 pin from a low level to a high level to notify the slave device to receive data.

5. The method according to claim 4, characterized in that The SoC sends a processed diagnostic message to the MCU based on the third signal line, including: When the SoC determines that the signal of the GPIO2 pin changes from a low level to a low level and then to a high level as a rising edge, the SoC sends the complete data frame to the MCU based on the third signal line.

6. The method according to claim 5, characterized in that The MCU decrypts the processed diagnostic message, including: The MCU extracts encrypted data from the received data frame; The MCU decrypts the encrypted data using a decryption algorithm and an encryption key corresponding to the preset encryption algorithm; The MCU calculates a check code for the decrypted data, and determines that the received data is correct when the calculated check code is consistent with the received check code.

7. The method according to claim 6, characterized in that The MCU sends a diagnostic response message based on the fourth signal line, including: The MCU determines the source of the diagnostic request according to the diagnostic session ID, and generates a corresponding diagnostic response message according to the unified diagnostic service protocol; The MCU sends the diagnostic response message to the SoC based on the fourth signal line.

8. An electronic control unit ECU, characterized in that: The ECU includes a master device and a slave device, wherein the master device is integrated with a system on chip SoC, and the slave device is integrated with a micro control unit MCU; The SoC is used to set a priority for the diagnostic message sent by the client, and to verify and encrypt the diagnostic message after the priority is set; after the verification and encryption are completed, the slave device is notified to receive data based on the first signal line; wherein the first signal line corresponds to the general-purpose input and output GPIO1 pin in the master device and the slave device; The MCU is used to notify the SoC to receive the processed diagnostic message based on the second signal line after receiving the notification sent by the SoC based on the first signal line, decrypt and parse the processed diagnostic message sent by the MCU based on the third signal line, and send a diagnostic response message to the SoC based on the fourth signal line; wherein the second signal line corresponds to the universal input and output GPIO2 pin in the master device and the slave device; the third signal line corresponds to the master-output slave-input data line MISO, and the fourth signal line corresponds to the master-input slave-output data line MOS; The SoC is used to transmit the diagnosis response message back to the client.

9. An electronic device, comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor coupled to the at least one bus; At least one memory connected to the at least one bus, wherein the processor is configured to execute the method for processing diagnostic data in an ECU based on SPI communication according to any one of claims 1 to 7.

10. A computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the method for processing diagnostic data in an ECU based on SPI communication according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Automobile diagnosis data processing method and system

    CN111221317A

  • Communication method between two chips and chip

    CN114844740A

  • SPI bus-based data communication method, SPI communication device and SPI communication system

    CN116010322A

  • Automobile diagnosis method and device, automobile and storage medium

    CN117032179A

  • Processing method for solving communication data transmission conflict in SoC

    CN117312005A