A battery management unit software architecture and automatic code generation method
By adding microcontroller MCU and layered software architecture to the battery management unit, the existing BMU communication robustness and development complexity are solved, and a more efficient and reliable battery management system is realized, simplifying the development process.
Patent Information
- Application Number
- CN202410398176.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-03
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-04-03
AI Technical Summary
When processing multiple battery data, the existing battery management unit (BMU) has poor communication robustness, insufficient real-time and portability of task execution, complex development and high requirements for code writing capabilities, and cannot execute control strategies such as thermal management alone.
Add a microcontroller MCU to each BMU, use SPI communication for data transmission and control, and design a software architecture divided into three layers: application layer, operation environment and board support package, which is carried out through STM32CubeMX, Matlab/Simulink and Keil and other platforms. Code generation and debugging, implement multi-task processing and real-time scheduling, and simplify the development process.
It improves BMU's data processing capabilities and communication stability, enhances the reliability and real-time nature of the system, reduces the development complexity and code writing workload, and is suitable for rapid prototyping and overall development of complex systems.
Smart Images

Figure CN118051441B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of energy storage battery management units, and in particular relates to a battery management unit software architecture and an automatic code generation method. Background Art
[0002] With the continuous development of energy storage management technology, people have higher and higher requirements for battery management units (BMUs). In the context of pursuing smarter, more efficient and reliable battery management systems, BMUs, as key components, are facing growing functional and performance expectations.
[0003] Most of the current BMUs use a daisy chain communication method to transmit data collected by the analog front end (AFE) in the BMU to the battery control and monitoring unit (BCMU). However, this method has poor flexibility and cannot independently execute control strategies such as thermal management. When the number of battery cells is large, all information is summarized in the BCMU. The output processing volume of the BCMU is relatively large, and the data storage capacity requirements are relatively high. In addition, the daisy chain communication has poor robustness, especially if a problem occurs in a node in the single-ended daisy chain communication, the entire link will lose communication.
[0004] There is also a BMU with a single-chip microcomputer. The analog front end sends data to the single-chip microcomputer in the BMU through daisy chain to SPI communication. After data preprocessing, it is transmitted to the BCMU through the CAN communication bus. However, this method mostly uses the front-end and back-end software architecture. Due to its sequential execution mode of tasks, the real-time performance of task execution is poor and the portability is poor. For example, when two tasks are ready at the same time, the tasks need to be executed sequentially. If the important tasks are placed at the back, they cannot be processed in time. In addition, there are disadvantages such as complex development, high requirements for code writing ability, and large development workload. Summary of the invention
[0005] In order to solve the above-mentioned deficiencies in the prior art, the present invention provides a battery management unit software architecture and an automatic code generation method, wherein a single-chip microcomputer MCU is added to each battery management unit BMU, wherein the BMU includes an analog front end AFE, and the AFE is responsible for collecting the voltage and temperature of each battery cell, and realizes data transmission between the MCU and the control of the AFE by the MCU through SPI communication;
[0006] A software architecture is designed based on the BMU MCU, and the software is divided into a three-layer architecture of application layer, operating environment, and board support package, and each layer of the architecture is modularly designed; in the application layer, the software is divided into a data processing module, an algorithm design module, a logic function module, and a system management module; in the operating environment, the memory management module is responsible for managing the execution of multiple tasks, and provides memory allocation and release functions; in the board support package, the software is divided into a communication module and a control module for processing communication and control operations with external devices; at the same time, a code generation method is provided for the single-chip microcomputer MCU; three development operating platforms are used, including a first operating platform, a second operating platform, and a third operating platform, and the basic peripherals and operating system configurations of the single-chip microcomputer MCU are performed through the first operating platform, and the related underlying driver code BSP and runtime environment RTE code are generated; system-level model development and algorithm design are performed through the second operating platform, and built-in tools are used for testing to generate related application layer code APP; a small amount of code is written through the third operating platform to improve the functions of the system and realize the debugging and downloading functions of the code.
[0007] Preferably, the first operating platform performs the following operations:
[0008] S11, create a project file through STM32CubeMX, select the MCU corresponding to the schematic diagram, and configure the basic peripherals;
[0009] S12, configure the clock source, select the external or internal clock source through the clock tree, set the system master clock, automatically update the frequency division and multiplication coefficients, and provide the counting frequency for the peripherals;
[0010] S13, add the operating system, directly enable the FreeRTOS component through STM32CubeMX, configure related parameters, and add content, including tasks, queues, semaphores, and mutexes;
[0011] S14, configure the project management part, select the corresponding IDE and file generation format, and generate relevant files through the code generation function.
[0012] Preferably, the second operating platform performs the following operations:
[0013] S21, establish a model file through Matlab / Simulink, and set the configuration parameters and attribute parameters of the model;
[0014] S22, create a system model, and call the controls of the Simulink library to build the algorithm and control strategy modules of the battery management system according to the demand analysis;
[0015] S23, define test cases and write the test cases required to verify the model;
[0016] S24, perform model-in-the-loop testing MIL to evaluate whether the control algorithm model accurately implements the functional requirements based on the defined test cases;
[0017] S25, analyzing and modifying the model, by analyzing the simulation and test results of the MIL test, modifying and improving the parts that do not meet the requirements, and then iterating step S24;
[0018] S26, code generation, after the MIL test passes, the code generation function is used to automatically generate the application;
[0019] S27, perform software-in-the-loop testing (SIL), and verify whether the functions implemented by the code are consistent with the MIL test results based on the defined test cases. If not, check the code generation settings and repeat steps S26 and S27.
[0020] Preferably, the third operating platform only needs to write a small amount of code, including calling AFE library functions, CAN communication processing, and EEPROM data reading and writing applications, and the compiled and combined code is compiled and burned into the microcontroller through the third operating platform for verification.
[0021] Preferably, the MCU is selected as an STM32 series chip.
[0022] Preferably, the algorithm for building the battery management system in S22 includes single cell state of charge estimation SOC and single cell state of health estimation SOH, and the control strategy of the battery management system includes voltage / temperature maximum value calculation and thermal management strategy.
[0023] Preferably, the third operating platform is any one of Keil, Eclipse IDE, STM32CubeIDE or IAR Systems.
[0024] Preferably, the Simulink controls used in S22 include commonly used module libraries, table lookup modules and Stateflow modules.
[0025] Preferably, the test case defined in S23 is a curve of the input signal related to time, and the test case can be imported into the model through the Simulink control Signal Builder; that is, the code file generated by the second operating platform is added to the file generated by the first operating platform, the third operating platform checks the code generated by the first operating platform and the second operating platform, and with the help of the third operating platform, the application is placed in the runtime environment to execute the application task.
[0026] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0027] The present invention uses a single-chip microcomputer in BMU, has a separate control function, shares the task of BCMU to data processing, and increases the stability and robustness of communication. Graphical configuration is performed with the help of the STM32CubeMX platform, and the configuration of the underlying hardware and initialization and the operating system is completed, providing developers with more flexible and reliable multi-tasking and real-time scheduling capabilities in embedded systems. Modular construction of algorithms and control strategies is carried out through Matlab / Simulink, and development and design at a more abstract and comprehensive level are achieved, allowing engineers to intuitively establish system models, perform algorithm design and simulation verification through a graphical interface, and provide more comprehensive support for the overall development of complex systems. Through the software architecture design and development of STM32CubeMX and Matlab / Simulink, hardware and software configuration is quickly realized, the workload of manually writing code is reduced, the efficiency of software development is improved, it is helpful to understand the overall architecture of the system and the data flow and interaction between each module, reduce syntax errors and logical errors, improve the reliability and stability of the system, and it is very attractive to users who are not familiar with programming or scenes that require rapid prototyping. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, what is described below is only one embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0029] Figure 1 This is a system architecture diagram used in the present invention.
[0030] Figure 2 This is a software architecture diagram of the present invention.
[0031] Figure 3 The present invention is a flow chart of a method for generating codes for an energy storage battery management unit. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of the present invention.
[0033] In view of the above problems, the present invention is applied to energy storage battery management unit equipment, and the system architecture diagram is as follows Figure 1As shown, multiple BMUs realize the collection and data processing of the voltage and temperature of multiple series-connected batteries, and each BMU includes chips such as an analog front end (AFE), a single-chip microcomputer MCU, and a storage unit.
[0034] AFE is responsible for collecting the voltage and temperature of each battery, and realizes data transmission with MCU and MCU control of AFE through SPI communication. After MCU performs data processing, it exchanges data with BCMU through CAN bus, reducing the data processing pressure of BCMU and increasing the robustness of communication.
[0035] The software architecture of a battery management unit of the present invention divides the software of the BMU into an application layer (APP), a runtime environment (RTE), and a board support package (BSP) according to the layering principle, and modularizes the functions of each layer according to the modularization principle. Figure 2 shown.
[0036] A specific BSP in the software architecture of a battery management unit mainly provides drivers, initialization codes and hardware abstraction layers related to the hardware platform. The BSP in the present invention mainly includes IIC communication with EEPROM, SPI communication with AFE, CAN communication with BCMU, LED light control for fault operation display, fan control for thermal management and watchdog control to prevent program runaway.
[0037] The RTE in a specific battery management unit software architecture provides a set of interfaces and services that enable the application layer to communicate and interact with the underlying software without having to understand the specific details of the underlying hardware. The runtime environment layer usually includes functions such as task scheduling, memory management, and communication mechanisms.
[0038] The APP in a specific battery management unit software architecture is responsible for implementing specific application functions. The application layer is usually where the application logic, algorithms, etc. are implemented. The APP in the present invention mainly includes strategies for implementing total pressure, pressure difference, and maximum voltage calculation, strategies for maximum temperature and temperature calculation, address allocation strategy, single cell SOC algorithm, single cell SOH algorithm, and thermal management strategy.
[0039] The present invention provides a method for automatically generating codes for an energy storage battery management unit, using three development operating platforms, including: a first operating platform STM32CubeMX, a second operating platform Matlab / Simulink, and a third operating platform integrated development environment (IDE) corresponding development tools. Different development tasks are implemented on different operating platforms. The specific flow chart of the method for automatically generating codes for an energy storage battery management unit is as follows: Figure 3 shown.
[0040] Specifically, the basic peripherals and operating system of the microcontroller MCU are configured through the first operating platform, and the relevant underlying driver code (BSP) and runtime environment (RTE) code are generated; system-level model development and algorithm design are carried out through the second operating platform, and built-in tools are used for testing to generate relevant application layer code (APP); a small amount of code is written through the third operating platform to improve the system's functions and realize the code debugging and downloading functions.
[0041] The first operating platform specifically performs the following operations:
[0042] S11, create a project file through STM32CubeMX, select the MCU corresponding to the schematic diagram, and configure the basic peripherals;
[0043] S12, configure the clock source, select the external or internal clock source through the clock tree, set the system master clock, automatically update the frequency division and multiplication coefficients, and provide the counting frequency for the peripherals;
[0044] S13, add the operating system, directly enable the FreeRTOS component through STM32CubeMX, configure related parameters, add tasks, queues, semaphores, mutexes, etc.;
[0045] S14, configure the project management part, select the appropriate IDE and file generation format, and generate relevant files through the code generation function.
[0046] The MCU should be a chip from the STM32 series, or chips from other manufacturers that are compatible with the STM32 series, such as the GigaDevice GD32F303RET6 that is compatible with the STM32F103RET6.
[0047] The specific second operating platform performs the following operations:
[0048] S21, establish a model file through Matlab / Simulink, and set the configuration parameters and attribute parameters of the model;
[0049] S22, create a system model, and call the controls of the Simulink library to build the algorithm and control strategy modules of the battery management system according to the demand analysis;
[0050] S23, define test cases and write the test cases required to verify the model;
[0051] S24, conduct model-in-the-loop testing (MIL) to evaluate whether the control algorithm model accurately implements the functional requirements based on the defined test cases;
[0052] S25, analyzing and modifying the model, by analyzing the simulation and test results of the MIL test, modifying and improving the parts that do not meet the requirements, and then iterating the S4 step;
[0053] S26, code generation, after the MIL test passes, the code generation function is used to automatically generate the application;
[0054] S27, perform software-in-the-loop testing (SIL) to verify whether the functions implemented by the code are consistent with the MIL test results based on the defined test cases.
[0055] The algorithms of the battery management system include single cell state of charge estimation (SOC) and single cell health state estimation (SOH), the control strategy includes voltage / temperature maximum value calculation, thermal management strategy, etc., and the Simulink controls used include commonly used module libraries, table lookup modules and Stateflow modules.
[0056] The test case is a curve of an input signal related to time, and the test case can be imported into the model through the Simulink control SignalBuilder.
[0057] Specifically, the code file generated by the second operating platform is added to the file generated by the first operating platform, the third operating platform checks the codes generated by the first operating platform and the second operating platform, and the application is placed in the runtime environment with the help of the third operating platform to execute the application task.
[0058] The third operating platform includes development tools such as Keil, Eclipse IDE, STM32CubeIDE, and IAR Systems.
[0059] The third operating platform only needs to write a small amount of code, including the calling of AFE library functions, CAN communication processing and EEPROM data reading and writing application programs.
[0060] Specifically, the compiled and combined code is compiled and burned into the single-chip microcomputer through a third operating platform for verification.
[0061] The above description is combined with the accompanying drawings to fully illustrate the specific embodiments of this article so that those skilled in the art can practice them. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. The scope of the embodiments of the present invention includes the entire scope of the claims, and all available equivalents of the claims. In the present invention, the terms "first", "second", etc. are only used to distinguish one element from another, without requiring or implying any actual relationship or order between these elements. In fact, the first element can also be called the second element, and vice versa. Moreover, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that the structure, device or equipment including a series of elements includes not only those elements, but also other elements that are not explicitly listed, or also include elements inherent to such structure, device or equipment. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the structure, device or equipment including the elements. Each embodiment is described in a progressive manner herein, and each embodiment focuses on the differences from other embodiments, and the same and similar parts between the embodiments can be referred to each other.
[0062] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0063] Although the above describes the specific implementation methods of the present invention, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.
Claims
1. A method for automatically generating code for a battery management unit, characterized in that: A single-chip microcomputer (MCU) is added to each battery management unit (BMU). The BMU includes an analog front end (AFE). The AFE is responsible for collecting the voltage and temperature of each battery cell, and realizes data transmission between the MCU and the control of the AFE by the MCU through SPI communication. Design a software architecture based on the BMU MCU, divide the software into three layers: application layer, operating environment, and board support package, and perform modular design on each layer; At the application layer, the software is divided into a data processing module, an algorithm design module, a logic function module and a system management module; In the operating environment, the memory management module is responsible for managing the execution of multiple tasks and provides memory allocation and release functions; in the board support package, the software is divided into a communication module and a control module for processing communication and control operations with external devices; The method is applied to a single-chip microcomputer MCU, and the method comprises: Use three development operating platforms, including the first operating platform, the second operating platform and the third operating platform. Use the first operating platform to configure the basic peripherals and operating system of the MCU, and generate the relevant underlying driver code BSP and runtime environment RTE code; use the second operating platform to develop system-level models and design algorithms, and use built-in tools to test and generate relevant application layer code APP; use the third operating platform to write a small amount of code to improve the system's functions and realize the debugging and downloading functions of the code; The first operating platform performs the following operations: S11, create a project file through STM32CubeMX, select the MCU corresponding to the schematic diagram, and configure the basic peripherals; S12, configure the clock source, select the external or internal clock source through the clock tree, set the system master clock, automatically update the frequency division and multiplication coefficients, and provide the counting frequency for the peripherals; S13, add the operating system, directly enable the FreeRTOS component through STM32CubeMX, configure related parameters, and add content, including tasks, queues, semaphores, and mutexes; S14, configure the project management part, select the corresponding IDE and file generation format, and generate relevant files through the code generation function; The second operating platform performs the following operations: S21, establish a model file through Matlab / Simulink, and set the configuration parameters and attribute parameters of the model; S22, create a system model, and according to the demand analysis, call the controls of the Simulink library to build the algorithm and control strategy modules of the battery management system; S23, defining test cases, writing test cases required for model verification; defining test cases, which are curves of input signals related to time, and importing the test cases into the model through the Simulink control Signal Builder; that is, adding the code files generated by the second operating platform to the files generated by the first operating platform, the third operating platform viewing the codes generated by the first operating platform and the second operating platform, and using the third operating platform to put the application into the runtime environment to execute the application task; S24, perform model-in-the-loop testing MIL to evaluate whether the control algorithm model accurately implements the functional requirements based on the defined test cases; S25, analyzing and modifying the model, by analyzing the simulation and test results of the MIL test, modifying and improving the parts that do not meet the requirements, and then iterating step S24; S26, code generation, after the MIL test passes, the code generation function is used to automatically generate the application; S27, perform software-in-the-loop testing (SIL), and verify whether the functions implemented by the code are consistent with the MIL test results based on the defined test cases. If not, check the code generation settings and repeat steps S26 and S27.
2. A method for automatically generating a battery management unit code according to claim 1, characterized in that: The third operating platform only needs to write a small amount of code, including calling AFE library functions, CAN communication processing and EEPROM data reading and writing applications, and the compiled and combined code is compiled and burned into the single-chip microcomputer through the third operating platform for verification.
3. A method for automatically generating a battery management unit code according to claim 1, characterized in that: The MCU is selected as STM32 series chip.
4. A method for automatically generating a battery management unit code according to claim 1, characterized in that: The algorithm for building the battery management system in S22 includes single cell state of charge estimation SOC and single cell state of health estimation SOH, and the control strategy of the battery management system includes voltage / temperature maximum value calculation and thermal management strategy.
5. A method for automatically generating a battery management unit code as claimed in claim 2, characterized in that: The third operating platform is any one of Keil, Eclipse IDE, STM32CubeIDE or IAR Systems.
6. A method for automatically generating codes for a battery management unit according to claim 1, characterized in that: The Simulink control used in S22 includes a commonly used module library, a table lookup module and a Stateflow module.
