MCU upgrade methods and systems for motor controllers

By constructing a state machine with three ring buffers in the motor controller, efficient upgrades of the master MCU and slave MCU are achieved, solving the problems of low transmission efficiency and bootloader bloat, and ensuring system stability and data integrity.

CN123067889APending Publication Date: 2026-11-10NANJING HENGLI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611068279.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-17
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

In motor controllers, the master MCU and slave MCU share the same CAN connector. Existing upgrade methods result in low transmission efficiency and bloated bootloader, making it impossible to perform efficient program upgrades.

Method used

Three fixed-size ring-shaped buffers are constructed at the end of the main MCU's Flash memory. The operation of the buffer state machine is controlled by DMA interrupt. The SPI data transmission time is folded into the CAN data reception time, and CRC verification is performed during MCU upgrade to ensure data integrity.

Benefits of technology

It improves transmission efficiency, reduces bootloader size, and prevents system anomalies in case of upgrade failure, ensuring system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123067889A_ABST
    Figure CN123067889A_ABST
Patent Text Reader

Abstract

This invention relates to the field of motor controller technology, and provides a method and system for upgrading an MCU in a motor controller. The method includes: when the master MCU receives an upgrade command from the slave MCU, it receives the firmware program via interrupt, writes the firmware program into a receive buffer, switches the state of the receive buffer to a ready-to-send state after the receive buffer is full, and sends the firmware program in the ready-to-send buffer to the slave MCU via SPI. After the transmission is complete, the state is switched to an idle state. In this invention, during slave MCU upgrades, the master MCU controls three buffers to operate in a mutually exclusive state machine of receiving / ready-to-send / idle. The firmware program is written to the receive buffer sequentially via interrupt, resulting in minimal code increments. The buffer that has completed data reception is sent to the slave MCU via SPI, folding the data transmission time into the data reception time, which not only improves data transmission efficiency but also reduces the size of the bootloader.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of motor controller technology, and specifically to a method and system for upgrading an MCU in a motor controller. Background Technology

[0002] In the motor controller of construction machinery (such as pure electric loaders and excavators), the master MCU (Micro Controller Unit) and the slave MCU generally share the same CAN (Controller Area Network) physical connector. The host computer can only communicate with one of the MCUs through a unique upgrade CAN ID (Identifier).

[0003] To enable program upgrades, both the master MCU and the slave MCU have a bootloader of equal size embedded at the beginning of the Flash memory. When the slave MCU is upgraded, the master MCU runs in bootloader mode and does not perform motor control tasks. The master MCU caches and parses the entire program and then forwards it to the slave MCU. This not only results in slow transmission efficiency but also causes the bootloader to swell. Summary of the Invention

[0004] To address the aforementioned technical problems, the first objective of this invention is to propose a method for upgrading the MCU of a motor controller, which allows the SPI (Serial Peripheral Interface) data transmission time to be folded into the CAN data reception time, thereby improving transmission efficiency and reducing the size of the bootloader.

[0005] The second objective of this invention is to provide an MCU upgrade system for a motor controller.

[0006] The technical solution adopted in this invention is as follows:

[0007] An embodiment of the first aspect of the present invention provides a method for upgrading an MCU of a motor controller. The motor controller includes a master MCU and a slave MCU. The upgrade method includes the following steps: a host computer sends an upgrade command to the master MCU via CAN communication; when the master MCU receives the upgrade command, it parses the memory address of the upgrade command; the master MCU judges the upgrade command based on the memory address; if the master MCU judges that the upgrade command is a master MCU upgrade command, the master MCU receives the firmware program corresponding to the upgrade command and performs a program upgrade based on the firmware program; if the master MCU judges that the upgrade command is a slave MCU upgrade command, the master MCU controls an idle buffer to receive the firmware program corresponding to the upgrade command via DMA (Direct Memory Access) interrupt, and modifies the state of the idle buffer to a receiving state, writes the received firmware program into the receiving buffer, and after the receiving buffer is full, switches the state of the receiving buffer to a ready-to-send state, and the master MCU transmits the firmware program in the ready-to-send buffer via SPI. The DMA sends data to the slave MCU. After the data in the transmit buffer is sent, the state of the transmit buffer is switched to the idle state. The receive buffer, the idle buffer, and the transmit buffer are located at the end of the Flash memory of the master MCU.

[0008] The MCU upgrade method for the motor controller proposed above in this invention may also have the following additional technical features:

[0009] According to one embodiment of the present invention, the main MCU receives the firmware program corresponding to the upgrade instruction and performs a program upgrade based on the firmware program. Specifically, the main MCU receives the firmware program corresponding to the upgrade instruction and performs CRC (Cyclic Redundancy Check) block verification. After the verification passes, the received firmware program is written into the download area of ​​the main MCU. After all data of the firmware program is received, the main MCU performs a CRC overall verification on the firmware program. After the verification passes, the firmware program is transferred from the download area of ​​the main MCU to the running area. The main MCU controls itself to restart, completing the main MCU upgrade.

[0010] According to an embodiment of the present invention, the MCU upgrade method for the motor controller further includes: performing CRC block verification after the slave MCU receives each block of data in the transmit buffer; if the verification passes, the slave MCU writes the received data into the download area of ​​the slave MCU and replies with an ACK (Acknowledgement) response to the master MCU; if the verification fails, the slave MCU replies with a NACK (Negative Acknowledgement) response to the master MCU.

[0011] According to an embodiment of the present invention, the MCU upgrade method for the motor controller further includes: when the master MCU receives the ACK response, it continues to send the firmware program of the buffer to be sent to the slave MCU until all data of the firmware program is sent; when the master MCU receives the NACK response, it resends the firmware program of the current buffer to be sent to the slave MCU; the master MCU determines whether the number of times the NACK response is received consecutively has reached a set number, and if so, it stops sending the firmware program to the slave MCU.

[0012] According to an embodiment of the present invention, the above-described MCU upgrade method for the motor controller further includes: after all data of the firmware program is sent, the master MCU sends a data transmission completion instruction to the slave MCU; after receiving the data transmission completion instruction sent by the master MCU, the slave MCU performs a CRC overall verification on the received firmware program, and after the verification is passed, the slave MCU moves the firmware program from the download area to the running area, thereby completing the slave MCU upgrade.

[0013] A second aspect of the present invention provides an MCU upgrade system for a motor controller, comprising: a host computer and a master MCU and a slave MCU of the motor controller; wherein, the host computer is used to send an upgrade command to the master MCU via CAN communication; the master MCU is used to, upon receiving the upgrade command, parse the memory address of the upgrade command, and determine the upgrade command based on the memory address; if the upgrade command is determined to be a master MCU upgrade command, then the master MCU receives the firmware program corresponding to the upgrade command and performs a program upgrade based on the firmware program; if the upgrade command is determined to be a slave MCU upgrade command, then the master MCU controls an idle buffer to receive the firmware program corresponding to the upgrade command via DMA interrupt, modifies the state of the idle buffer to a receiving state, writes the received firmware program into the receiving buffer, switches the state of the receiving buffer to a waiting-to-send state after the receiving buffer is full, and sends the firmware program in the waiting-to-send buffer to the slave MCU via SPI DMA; after the data in the waiting-to-send buffer is sent, the master MCU switches the state of the waiting-to-send buffer to an idle state; the receiving buffer, the idle buffer, and the waiting-to-send buffer are located at the end of the Flash memory of the master MCU.

[0014] The MCU upgrade system for the motor controller proposed above in this invention may also have the following additional technical features:

[0015] According to one embodiment of the present invention, the main MCU is specifically used for: receiving the firmware program corresponding to the upgrade instruction and performing CRC block verification; after the verification is passed, writing the received firmware program into the download area of ​​the main MCU; after all the data of the firmware program is received, performing a CRC overall verification on the firmware program; after the verification is passed, transferring the firmware program from the download area of ​​the main MCU to the running area; and controlling itself to restart to complete the upgrade of the main MCU.

[0016] According to one embodiment of the present invention, the slave MCU is specifically used to: perform CRC block verification after receiving each block of data in the transmit buffer; if the verification passes, write the received data into the download area of ​​the slave MCU and reply with an ACK response to the master MCU; if the verification fails, reply with a NACK response to the master MCU.

[0017] According to one embodiment of the present invention, the master MCU is further configured to: upon receiving the ACK response, continue to send the firmware program of the buffer to be sent to the slave MCU until all data of the firmware program is sent; upon receiving the NACK response, resend the firmware program of the current buffer to be sent to the slave MCU; determine whether the number of consecutive NACK responses received has reached a set number, and if so, stop sending the firmware program to the slave MCU.

[0018] According to one embodiment of the present invention, the slave MCU is further configured to: after receiving the data transmission completion instruction sent by the master MCU, perform a CRC overall verification on the received firmware program; after the verification is passed, transfer the firmware program from the download area of ​​the slave MCU to the running area to complete the slave MCU upgrade.

[0019] The beneficial effects of this invention are:

[0020] This invention constructs three fixed-size ring-shaped buffers at the end of the Flash memory in the main MCU. During the upgrade of the slave MCU, the main MCU controls the three buffers to operate in a mutually exclusive state machine of receiving / pending transmission / idle. The firmware program is written to the current receiving buffer sequentially by interrupt, with minimal code increment. The buffer that has completed data reception is read by SPI DMA and sent to the slave MCU, so that the SPI data transmission time is folded into the CAN data reception time, which improves the transmission efficiency and reduces the size of the bootloader.

[0021] The MCU will only move the upgrade firmware from the download area to the running area after the global CRC of the firmware received in the download area passes. If the overall verification fails, the upgrade firmware will not be moved and the system will be forced to start from the running area. Even if the download area data is abnormal due to power failure, communication failure, etc. during the direct writing process, the abnormal data will not be selected for execution, which can prevent the running system from becoming bricked due to upgrade failure. Attached Figure Description

[0022] Figure 1 This is a flowchart of a method for upgrading an MCU of a motor controller according to an embodiment of the present invention;

[0023] Figure 2 This is a schematic diagram of the structure of an MCU upgrade system according to an embodiment of the present invention;

[0024] Figure 3 This is a flowchart of the upgrade process for a main MCU according to an embodiment of the present invention;

[0025] Figure 4 This is a schematic diagram of the buffer area of ​​the main MCU according to an embodiment of the present invention;

[0026] Figure 5 This is a flowchart of a method for upgrading an MCU of a motor controller according to another embodiment of the present invention. Detailed Implementation

[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0028] Figure 1 This is a flowchart of a motor controller MCU upgrade method according to an embodiment of the present invention. Figure 2 This is a schematic diagram of the structure of an MCU upgrade system according to an embodiment of the present invention. Wherein, as... Figure 2 As shown, the motor controller includes a master MCU and a slave MCU. The master MCU and the slave MCU communicate via SPI. The host computer communicates with the master MCU and the slave MCU via CAN. The master MCU and the slave MCU share the same CAN physical connector. The host computer communicates with one of the MCUs through a unique upgrade CAN ID. In this invention, the host computer communicates with the master MCU through a unique upgrade CAN ID.

[0029] like Figure 1 As shown, the MCU upgrade method for the motor controller includes the following steps:

[0030] Step S1: The host computer sends an upgrade command to the main MCU via CAN communication.

[0031] Step S2: When the main MCU receives the upgrade command, it parses the memory address of the upgrade command.

[0032] Step S3: The main MCU determines the upgrade instruction based on the memory address.

[0033] Specifically, when an MCU needs to be upgraded, the host computer sends an upgrade command via CAN. The upgrade command corresponds to the standard UDS (Unified Diagnostic Services) 0x34 service. The master MCU listens for the unique upgrade CANID, parses the memory address parameters in the standard UDS 0x34 service, compares them with a predefined address range mapping table, determines the upgrade target, and switches the forwarding state. For example, if the memory address is 0x440000, the upgrade target belongs to the master MCU; if it is 0x494000, the upgrade target belongs to the slave MCU.

[0034] Step S4: If the main MCU determines that the upgrade instruction is a main MCU upgrade instruction, then the main MCU receives the firmware program corresponding to the upgrade instruction and performs program upgrade according to the firmware program.

[0035] In one specific embodiment of the present invention, such as Figure 3As shown, in step S4, the main MCU receives the firmware program corresponding to the upgrade command and performs a program upgrade based on the firmware program, specifically including:

[0036] S41: The main MCU receives the firmware program corresponding to the upgrade command and performs CRC block verification. After the verification is successful, the received firmware program is written to the download area of ​​the main MCU.

[0037] S42, after all the data of the firmware program has been received, the main MCU performs a CRC check on the firmware program. After the check passes, the firmware program is moved from the download area of ​​the main MCU to the running area.

[0038] S43, the main MCU controls its own restart to complete the main MCU upgrade.

[0039] Specifically, if the main MCU determines that the upgrade command is for the main MCU, then the main MCU receives the firmware program corresponding to the upgrade command in blocks. For example, the main MCU performs CAN reception in 512-byte block boundaries, and performs CRC block verification after each block of data is received. After the verification passes, the received data is written to the main MCU's download area Flash. After all the data of the firmware program has been received, the main MCU performs a full CRC verification on the firmware program. After the verification passes, the entire data of the firmware program is transferred from the main MCU's download area to the runtime area. Finally, the main MCU controls itself to restart, completing the main MCU upgrade.

[0040] Step S5: If the master MCU determines that the upgrade command is a slave MCU upgrade command, the master MCU controls the idle buffer to receive the firmware program corresponding to the upgrade command via DMA interrupt, and changes the state of the idle buffer to the receive state. The received firmware program is written to the receive buffer. After the receive buffer is full, the state of the receive buffer is switched to the ready-to-transmit state. The master MCU sends the firmware program in the ready-to-transmit buffer to the slave MCU via SPI DMA. After the data transmission in the ready-to-transmit buffer is complete, the state of the ready-to-transmit buffer is switched back to the idle state. The receive buffer, idle buffer, and ready-to-transmit buffer are located at the end of the master MCU's Flash memory.

[0041] Specifically, such as Figure 4As shown, three fixed-byte buffers are set at the end of the main MCU's Flash memory, including buffer A, buffer B, and buffer C. These buffers do not intrude on the running area and the Bootloader area of ​​the same size. The size of each buffer can be 512 bytes. This size is determined by a trade-off between an integer multiple of the CAN frame payload (typically 8 bytes) and Flash write alignment (typically 256 / 512 byte sector boundaries), taking into account both SPI DMA efficiency and Flash erase / write granularity. The three buffers operate as a mutually exclusive state machine. The three fixed-byte buffers constitute a decoupled micro pipeline of "receiving-waiting to transmit-idle".

[0042] Specifically, if the master MCU determines that the upgrade command is a slave MCU upgrade command, then the master MCU controls the idle buffer to start receiving the firmware program corresponding to the upgrade command via DMA interrupt, and changes the state of the buffer to the receive buffer. After the receive buffer is full, the state of the receive buffer is switched to the ready-to-send state, and the firmware program in the ready-to-send buffer is sent to the slave MCU via SPI DMA. After the data in the ready-to-send buffer is sent, the state of the ready-to-send buffer is switched to the idle state, and so on.

[0043] For example, buffer A is the receive buffer. Each time a frame (e.g., 8 bytes) is received, an interrupt is triggered. The master MCU's CPU (Central Processing Unit) uses a very small cycle to program and write these 8 bytes into the Flash address of the current buffer. Since the CAN speed is below 250kbps, the frame interval is much longer than the time required for the CPU to write to Flash, resulting in extremely low CPU load. Buffer B is the transmit buffer, which is full of data. The master MCU reads 512 bytes from the Flash address of this transmit buffer and sends them to the slave MCU via SPI DMA. Since the SPI transmission rate is 5MHz, the transmission is completed in approximately 0.8ms, earlier than the next block fill time. Buffer C is an idle buffer, waiting to receive data in rotation.

[0044] Therefore, the SPI transmission time is completely folded and hidden in the CAN connector reception time. The total upgrade time is approximately equal to the CAN link time, and the forwarding code of the main MCU is only a state machine with a few dozen lines of interrupts, with minimal Bootloader increments.

[0045] In one embodiment of the present invention, such as Figure 5 As shown, the above-mentioned MCU upgrade method for motor controllers also includes:

[0046] S6 performs CRC block verification after receiving each block of data from the MCU's transmit buffer.

[0047] S7. If the verification passes, the MCU writes the received data to the MCU's download area and sends an ACK response back to the master MCU.

[0048] S8, if the verification fails, the MCU sends a NACK response to the main MCU.

[0049] Specifically, the slave MCU receives data (including the block header) sent by the master MCU via interrupt using SPI. For each received block (512 bytes), the slave MCU calculates the CRC32 value and compares it with the CRC carried in the block header for CRC block verification. If the verification passes, the slave MCU writes the received data to its download area and sends an ACK response to the master MCU; if the verification fails, the slave MCU sends a NACK response to the master MCU and discards the data block.

[0050] In one embodiment of the present invention, such as Figure 5 As shown, the above-mentioned MCU upgrade method for motor controllers also includes:

[0051] S9. When the master MCU receives the ACK response, it continues to send the firmware program in the buffer to be sent to the slave MCU until all firmware program data has been sent.

[0052] S10 When the master MCU receives a NACK response, it resends the firmware program of the current buffer to be sent to the slave MCU.

[0053] S11, the main MCU determines whether the number of consecutive NACK responses received has reached the set number. If yes, proceed to step S12; otherwise, proceed to step S13.

[0054] S12, the master MCU stops sending firmware programs to the slave MCU.

[0055] S13, after all data in the firmware program has been sent, the master MCU sends a data transmission completion command to the slave MCU.

[0056] S14: After receiving the data transmission completion instruction from the main MCU, the MCU performs a CRC check on the received firmware program. If the check passes, the firmware program is moved from the download area of ​​the MCU to the running area, completing the upgrade from the MCU.

[0057] Specifically, when the master MCU receives an ACK response, it continues to send the firmware program in the pending buffer to the slave MCU until all firmware program data has been sent. When the master MCU receives a NACK response, it resends the firmware program in the current pending buffer to the slave MCU, and then checks whether the number of consecutive NACK responses received has reached a set number (e.g., 3 times). If 3 consecutive NACK responses are received, it stops sending the firmware program to the slave MCU and exits the slave MCU upgrade process.

[0058] After all firmware data has been sent, the master MCU sends a completion command to the slave MCU. Upon receiving the completion command, the slave MCU performs a global CRC check on the data in its download area. If the check passes, the slave MCU sets its download area validity flag to valid (Download Area Validity Flag = Valid) and its runtime area validity flag to invalid (Runtime Area Validity Flag = Invalid). It then moves the firmware from the slave MCU's download area to the runtime area, sets the runtime area validity flag to valid, resets the system, and restarts the slave MCU, completing the upgrade. If the check fails, the slave MCU erases its download area data or clears its download area validity flag and reports the upgrade failure to the master MCU.

[0059] Before the validity flag from the MCU download area is set, the bootloader will always jump back to the running area to start. Therefore, even if the download area data is abnormal due to power failure, communication failure, or other reasons during the direct write process, the abnormal data will not be selected for execution, which can prevent the running system from becoming bricked due to upgrade failure.

[0060] In summary, the MCU upgrade method for the motor controller according to embodiments of the present invention constructs three fixed-size circular buffers at the end of the Flash memory in the main MCU. During the upgrade of the slave MCU, the main MCU controls the three buffers to operate in a mutually exclusive state machine of receiving / pending transmission / idle. The firmware program is written sequentially to the current receiving buffer via interrupt, with minimal code increments. The buffers that have completed data reception are read by SPI DMA and sent to the slave MCU, folding the SPI data transmission time into the CAN data reception time, improving transmission efficiency and reducing the Bootloader size. The slave MCU only moves the upgrade firmware program from the download area to the running area after the global CRC of the firmware program received in the download area passes. If the overall verification fails, the upgrade firmware program is not moved and the system is forced to start from the running area. Even if power failure or communication abnormalities occur during the direct writing process, causing data abnormalities in the download area, the abnormal data will not be selected for execution, preventing the running system from becoming bricked due to upgrade failure.

[0061] Corresponding to the above-mentioned MCU upgrade method for motor controllers, the present invention also proposes an MCU upgrade system for motor controllers.

[0062] like Figure 2 As shown, the MCU upgrade system for the motor controller includes a host computer and a master MCU and a slave MCU of the motor controller. The host computer sends upgrade commands to the master MCU via CAN communication. Upon receiving an upgrade command, the master MCU parses the memory address of the command and determines its suitability. If the command is determined to be a master MCU upgrade command, it receives the corresponding firmware program and performs the upgrade accordingly. If the command is determined to be a slave MCU upgrade command, it controls the idle buffer to receive the corresponding firmware program via DMA interrupt, changes the idle buffer's state to receive, writes the received firmware program into the receive buffer, and switches the receive buffer's state to "ready to send" after it is full. The firmware program in the ready-to-send buffer is then sent to the slave MCU via SPI DMA. After the data transmission to the ready-to-send buffer is complete, the ready-to-send buffer's state is switched back to idle. The receive buffer, idle buffer, and ready-to-send buffer are located at the end of the master MCU's Flash memory.

[0063] According to one embodiment of the present invention, the main MCU is specifically used for: receiving the firmware program corresponding to the upgrade command and performing CRC block verification; after the verification is passed, writing the received firmware program into the download area of ​​the main MCU; after all the data of the firmware program is received, performing a CRC overall verification on the firmware program; after the verification is passed, transferring the firmware program from the download area of ​​the main MCU to the running area; controlling itself to restart, and completing the main MCU upgrade.

[0064] According to one embodiment of the present invention, the slave MCU is specifically used to: perform CRC block verification after receiving each block of data in the transmit buffer; if the verification passes, write the received data into the download area of ​​the slave MCU and reply with an ACK response to the master MCU; if the verification fails, reply with a NACK response to the master MCU.

[0065] According to one embodiment of the present invention, the master MCU is further configured to: upon receiving an ACK response, continue to send the firmware program of the buffer to be sent to the slave MCU until all data of the firmware program has been sent; upon receiving a NACK response, resend the firmware program of the current buffer to be sent to the slave MCU; determine whether the number of consecutive NACK responses received has reached a set number, and if so, stop sending the firmware program to the slave MCU.

[0066] According to one embodiment of the present invention, the slave MCU is further configured to: after receiving a data transmission completion instruction sent by the master MCU, perform a CRC overall verification on the received firmware program; after the verification is passed, transfer the firmware program from the download area of ​​the slave MCU to the running area to complete the upgrade from the slave MCU.

[0067] In summary, the MCU upgrade system for the motor controller according to embodiments of the present invention constructs three fixed-size circular buffers at the end of the Flash memory in the main MCU. During the upgrade of the slave MCU, the main MCU controls the three buffers to operate in a mutually exclusive state machine of receiving / pending transmission / idle. The firmware program is written sequentially to the current receiving buffer via interrupt, with minimal code increments. The buffers that have completed data reception are read by SPI DMA and sent to the slave MCU, folding the SPI data transmission time into the CAN data reception time, improving transmission efficiency and reducing the bootloader size. The slave MCU only moves the upgrade firmware program from the download area to the running area after the global CRC of the firmware program received in the download area passes. If the overall verification fails, the upgrade firmware program is not moved and the system is forced to start from the running area. Even if power failure or communication abnormalities occur during the direct writing process, causing data abnormalities in the download area, the abnormal data will not be selected for execution, preventing the running system from becoming bricked due to upgrade failure.

[0068] Those skilled in the art will understand that all or part of the steps of the methods described in the above embodiments can be implemented by a program instructing related hardware, and the program can be stored in a computer-readable storage medium. When executed, the program includes one or a combination of the steps of the method embodiments.

[0069] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. A method for upgrading an MCU in a motor controller, characterized in that, The motor controller includes a master MCU and a slave MCU, and the upgrade method includes the following steps: The host computer sends an upgrade command to the main MCU via CAN communication; When the main MCU receives the upgrade command, it parses the memory address of the upgrade command; The main MCU determines the upgrade instruction based on the memory address; If the main MCU determines that the upgrade instruction is a main MCU upgrade instruction, then the main MCU receives the firmware program corresponding to the upgrade instruction and performs a program upgrade based on the firmware program; If the master MCU determines that the upgrade instruction is a slave MCU upgrade instruction, the master MCU controls the idle buffer to receive the firmware program corresponding to the upgrade instruction via DMA interrupt, and modifies the state of the idle buffer to the receive state, writes the received firmware program into the receive buffer, and switches the state of the receive buffer to the send-ready state after the receive buffer is full. The master MCU sends the firmware program in the send-ready buffer to the slave MCU via SPI DMA. After the data in the send-ready buffer is sent, the state of the send-ready buffer is switched to the idle state. The receive buffer, the idle buffer, and the send-ready buffer are located at the end of the master MCU's Flash memory.

2. The MCU upgrade method for a motor controller according to claim 1, characterized in that, The main MCU receives the firmware program corresponding to the upgrade command and performs a program upgrade based on the firmware program, specifically including: The main MCU receives the firmware program corresponding to the upgrade instruction and performs CRC block verification. After the verification is successful, the received firmware program is written into the download area of ​​the main MCU. After all data of the firmware program is received, the main MCU performs a CRC check on the firmware program. If the check passes, the firmware program is moved from the download area of ​​the main MCU to the running area. The main MCU restarts itself to complete the main MCU upgrade.

3. The MCU upgrade method for a motor controller according to claim 1, characterized in that, Also includes: After receiving each block of data from the MCU's buffer, a CRC block check is performed. If the verification passes, the slave MCU writes the received data into the slave MCU's download area and sends an ACK response back to the master MCU; If the verification fails, the slave MCU sends a NACK response to the master MCU.

4. The MCU upgrade method for the motor controller according to claim 3, characterized in that, Also includes: When the master MCU receives the ACK response, it continues to send the firmware program in the buffer to be sent to the slave MCU until all the data of the firmware program has been sent. When the master MCU receives the NACK response, it resends the firmware program of the current buffer to be sent to the slave MCU. The master MCU determines whether the number of consecutive NACK responses received has reached a set number. If so, it stops sending the firmware program to the slave MCU.

5. The MCU upgrade method for a motor controller according to claim 3, characterized in that, Also includes: After all data in the firmware program has been sent, the master MCU sends a data transmission completion command to the slave MCU. After receiving the data transmission completion instruction from the master MCU, the slave MCU performs a CRC check on the received firmware program. If the check passes, the firmware program is moved from the download area to the runtime area of ​​the slave MCU, thus completing the slave MCU upgrade.

6. An MCU upgrade system for a motor controller, characterized in that, include: The host computer and the main MCU and slave MCU of the motor controller; wherein, The host computer is used to send upgrade commands to the main MCU via CAN communication; The master MCU, upon receiving the upgrade instruction, parses the memory address of the upgrade instruction and determines the upgrade instruction based on the memory address. If the upgrade instruction is determined to be a master MCU upgrade instruction, the master MCU receives the firmware program corresponding to the upgrade instruction and performs a program upgrade based on the firmware program. If the upgrade instruction is determined to be a slave MCU upgrade instruction, the master MCU controls the idle buffer to receive the firmware program corresponding to the upgrade instruction via DMA interrupt, modifies the state of the idle buffer to receive state, writes the received firmware program into the receive buffer, switches the state of the receive buffer to the send state after the receive buffer is full, and sends the firmware program in the send buffer to the slave MCU via SPI DMA. After the data in the send buffer is sent, the state of the send buffer is switched to the idle state. The receive buffer, the idle buffer, and the send buffer are located at the end of the master MCU's Flash memory.

7. The MCU upgrade system for a motor controller according to claim 6, characterized in that, The main MCU is specifically used for: The firmware program corresponding to the upgrade instruction is received and CRC block verification is performed. After the verification is passed, the received firmware program is written into the download area of ​​the main MCU. After all data of the firmware program is received, a CRC check is performed on the firmware program. If the check passes, the firmware program is moved from the download area of ​​the main MCU to the running area. Control its own restart to complete the main MCU upgrade.

8. The MCU upgrade system for a motor controller according to claim 6, characterized in that, The MCU is specifically used for: After each block of data in the buffer to be sent is received, a CRC block check is performed. If the verification passes, the received data is written to the download area of ​​the MCU and an ACK response is sent back to the main MCU; If the verification fails, a NACK response is sent back to the main MCU.

9. The MCU upgrade system for a motor controller according to claim 8, characterized in that, The main MCU is also used for: Upon receiving the ACK response, continue sending the firmware program in the buffer to be sent to the slave MCU until all data of the firmware program has been sent. Upon receiving the NACK response, the firmware program for the current buffer to be sent is resent to the slave MCU; Determine whether the number of consecutive NACK responses received has reached a set number. If so, stop sending the firmware program to the slave MCU.

10. The MCU upgrade system for a motor controller according to claim 8, characterized in that, The slave MCU is further configured to: after receiving the data transmission completion instruction sent by the master MCU, perform a CRC overall verification on the received firmware program; after the verification is successful, transfer the firmware program from the download area of ​​the slave MCU to the running area, thereby completing the slave MCU upgrade.