Program flashing method and device of controller, controller and storage medium

By obtaining the embedded controller's operating space usage information and starting address for program flashing, the problem of cumbersome program flashing in existing technologies is solved, improving development efficiency and stability.

CN113885917BActive Publication Date: 2026-02-10CHINA FAW CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111208423.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-18
Publication Date
2026-02-10
Estimated Expiration
2041-10-18

AI Technical Summary

Technical Problem

The existing embedded controller program flashing process is cumbersome, requiring repeated determination of running parameters, resulting in low development efficiency.

Method used

By obtaining the runtime space usage information of the code content of the program to be flashed, and writing the program into the memory space based on the flashing start address and runtime space usage information, the program flashing is performed by estimating the runtime memory size and start address of the program to be flashed.

Benefits of technology

It improved the success rate of program flashing, reduced the testing time for running parameters, and improved the development efficiency and operational stability of the controller.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113885917B_ABST
    Figure CN113885917B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a program flashing method and device of a controller, the controller and a storage medium. The method comprises: obtaining a to-be-flashed program according to a preset storage structure; determining running space occupation information of code content of the to-be-flashed program; and writing the to-be-flashed program into a memory space based on a flashing start address and the running space occupation information. The to-be-flashed program is written into the memory space by estimating the running memory size and the start address of the to-be-flashed program, so that the memory space is effectively saved, the success rate of program flashing is improved, and the stability of the controller is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the field of automation control technology, and particularly to a program flashing method and device of a controller, the controller and a storage medium. BACKGROUND

[0002] Currently, embedded controllers gradually enrich people's daily life, and the embedded controllers need to write corresponding programs before executing functions. When writing programs into the controller, the starting address, code segment, data segment, calibration segment and memory occupation of the program running parameters need to be written by the embedded development engineer. This development mode of the controller leads to a complicated development process. Even if different control programs are flashed for the same hardware device, the running parameters corresponding to the control program need to be determined, which requires the embedded development engineer to repeatedly determine the running parameters of the control program, greatly affecting the development efficiency of the controller. Therefore, there is an urgent need for a fast and safe controller flashing method. SUMMARY

[0003] Embodiments of the present application provide a program flashing method, device, controller and storage medium of a controller to realize accurate program flashing, reduce the testing workload of running parameters and improve the stability of the controller running.

[0004] In a first aspect, embodiments of the present application provide a program flashing method of a controller, which comprises:

[0005] obtaining a to-be-flashed program according to a preset storage structure;

[0006] determining running space occupation information of code content of the to-be-flashed program;

[0007] writing the to-be-flashed program into a memory space based on a flashing starting address and the running space occupation information.

[0008] In a second aspect, embodiments of the present application provide a program flashing device of a controller, which comprises:

[0009] a program receiving module configured to obtain a to-be-flashed program according to a preset storage structure;

[0010] a space information module configured to determine running space occupation information of code content of the to-be-flashed program;

[0011] a program flashing module configured to write the to-be-flashed program into a memory space based on a flashing starting address and the running space occupation information.

[0012] In a third aspect, embodiments of the present application provide a controller, which comprises:

[0013] one or more central processing units;

[0014] a memory for storing one or more programs,

[0015] When the one or more programs are executed by the one or more central processing units, the one or more central processing units implement the program flashing method of the controller as described in the embodiments of the present application.

[0016] In a third aspect, the embodiments of the present application provide a computer readable storage medium having a program stored thereon, wherein the program, when executed by a central processing unit, implements the program flashing method of the controller as described in the embodiments of the present application.

[0017] The technical solution of the embodiments of the present application acquires the to-be-flashed program according to a preset storage structure, determines the running space occupation information of the code content of the to-be-flashed program, and writes the to-be-flashed program into the memory space based on the flashing start address and the running space occupation information. The above technical solution writes the to-be-flashed program into the memory space based on the estimated running memory size and start address of the to-be-flashed program, effectively saves the memory space, can improve the success rate of program flashing, thereby improving the stability of the controller running, can reduce the test time for determining the running parameters of the to-be-flashed program, and can improve the development efficiency of the controller. BRIEF DESCRIPTION OF DRAWINGS

[0018] Figure 1 is a flowchart of the program flashing method of the controller provided by the first embodiment of the present application;

[0019] Figure 2 is a flowchart of the program flashing method of the controller provided by the second embodiment of the present application;

[0020] Figure 3 is a flowchart of the memory occupation amount determination of the code content provided by the second embodiment of the present application;

[0021] Figure 4 is an implementation effect diagram of the program flashing method of the controller provided by the embodiments of the present application;

[0022] Figure 5 is an example diagram of another program flashing method of the controller provided by the embodiments of the present application;

[0023] Figure 6 is a structural block diagram of the program flashing device of the controller provided by the third embodiment of the present application;

[0024] Figure 7 is a structural diagram of the controller provided by the fourth embodiment of the present application. DETAILED DESCRIPTION

[0025] The application will be described in further detail below with reference to the drawings and embodiments. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not to be used to limit the scope of the application. In addition, it is to be understood that, for ease of description, only the parts related to the application are shown in the drawings rather than all the parts.

[0026] Before the example embodiments are discussed in further detail, it should be mentioned that some of the example embodiments are described as processes or methods depicted as flow charts. While the steps of the processes are depicted as sequential processes, many of the steps can be performed in parallel, concurrently or at the same time. In addition, the order of the steps can be re-arranged. The processes can be terminated when their operations are completed, but can also have additional steps not included in the figure. The processes can correspond to methods, functions, routines, subroutines, etc.

[0027] Embodiment One

[0028] Figure 1 is a flow chart of a program flashing method of a controller according to an embodiment of the application. The embodiment can be applicable to the case of flashing code of the controller. The method can be performed by a program flashing device of the controller according to an embodiment of the application. The device can be implemented in software and / or hardware. The device can be configured in the controller.

[0029] As shown in Figure 1 , the program flashing method of the controller according to an embodiment of the application specifically includes the following steps.

[0030] S110, obtaining the program to be flashed according to a preset storage structure.

[0031] The preset storage structure can be a data structure for storing the program to be flashed. The data structure can store code segments, data segments, calibration segments and data segments of interrupt memory size of the flashing program. The embodiments of the application do not limit the types of the stored data.

[0032] The program to be flashed can be a program for realizing the functions of the controller, such as code for realizing the update function, the deletion function, etc. The embodiments of the application do not limit the specific functions realized by the program to be flashed.

[0033] In the embodiments of the application, the preset storage structure can include code segments, data segments, calibration segments and data segments of interrupt memory size. After receiving the program to be flashed, the code of the program to be flashed can be stored in the code segments, the global variables can be stored in the data segments, the calibration quantity can be stored in the calibration segments and the interrupt data can be stored in the data segments of interrupt memory size.

[0034] S120, determine running space occupation information of code content of the to-be-flashed program.

[0035] The code content can be program text constituting processing logic of the to-be-flashed program, and can include global variables, calibration quantities and interrupts. The running space occupation information can be information reflecting memory space size required by the code content during program running, and can include information of memory stored by the to-be-flashed program itself and information of memory occupied during program running.

[0036] In the embodiment of the present application, the information of memory stored by the to-be-flashed program itself can be determined by code segments stored in the pre-stored structure, and the information of memory occupied during program running of the global variables, calibration quantities and interrupts can be determined by data segments, calibration segments and interrupt memory size data segments stored in the pre-stored structure.

[0037] For example, if there is one global variable in the code content of the to-be-flashed program, the memory occupied by the global variable during running can be 10 bytes. If there are 8 calibration quantities in the code content of the to-be-flashed program, the memory size occupied by each calibration quantity during running can be 2 bytes at most, so the memory size occupied by the calibration quantities of the to-be-flashed program during running can be 8*2 bytes, i.e. 16 bytes. If the depth of the interrupt in the code content of the to-be-flashed program is 2, the memory size occupied by one interrupt during running can be 10 Kbytes (KB), so the memory size occupied by the interrupt in the code content of the to-be-flashed program during running can be 2*10 KB, i.e. 20 KB.

[0038] S130, write the to-be-flashed program into the memory space based on the flashing start address and the running space occupation information.

[0039] The address can refer to a number, and can identify a partial region in a space. The write start address can be a start address of a memory space in which a program to be written is stored, and the write start address can point to a region in the memory space that has not been occupied. The running space occupation information can represent information of a memory space used by the program to be written to run, and can include information of a size of the program to be written itself and information of a size of the memory space occupied when the program runs. The memory space can be a storage region in the controller, and can be used to save the program and data when the process runs. The memory space can be a region in the unoccupied memory space, or a region in the occupied memory space. The program to be written can be written to any position of the memory space, and the size of the memory space can satisfy complete and accurate storage of the program to be written. For example, the region written by the program to be written can be a region at the front of the memory space, the start address of the program to be written in the memory space can be 0, and the end address of the program to be written in the memory space can be a sum of 0 and a value of the size of the memory space corresponding to the running space occupation information of the program to be written. For another example, the region written by the program to be written can be a last region of the memory space, and the last region can completely and accurately store the program to be written. The start address of the program to be written in the memory space can be a termination address of the memory space minus the size of the memory space corresponding to the running space occupation information of the program to be written.

[0040] In the embodiment of the present application, after the running space occupation information of the program to be written is determined, the write start address of the program to be written is used to start writing the program to be written into the memory space. The storage position of the program to be written in the memory space can be accurately controlled according to the write start address, the accuracy of program writing control can be improved, the waste of memory space can be reduced, and the fragmentation degree of the memory space can be reduced.

[0041] The technical scheme of the embodiment of the present application comprises the following steps: obtaining the program to be written according to a preset storage structure; determining the running space occupation information of the code content of the program to be written; and writing the program to be written into the memory space pointed to by the write start address based on the write start address and the running space occupation information. The above technical scheme writes the program to be written into the memory space based on the estimated running memory size and start address of the program to be written, effectively saves the memory space, improves the success rate of program writing, thereby improving the stability of the controller running, reduces the test time for determining the running parameters of the program to be written, and improves the development efficiency of the controller.

[0042] Further, based on the above embodiment, after the program to be written is written into the memory space based on the write start address and the running space occupation information, the write start address is updated according to the running space occupation information of the program to be written.

[0043] In the embodiment of the present application, after the to-be-flashed program is written into the memory space according to the flashing start address, the sum of the flashing start address and the memory space size corresponding to the running space occupation information of the to-be-flashed program can be recorded as the flashing end address, and the original flashing start address can be updated using the flashing end address. For example, for big-end memory, the flashing end address minus 1 can be used as the new flashing start address, and for little-end memory, the flashing end address plus 1 can be used as the new flashing start address.

[0044] Embodiment Two

[0045] Figure 2 is a flowchart of a program flashing method of a controller provided by the second embodiment of the present application, which is optimized on the basis of the above-mentioned embodiments. As shown in Figure 2 The program flashing method of a controller provided by the second embodiment of the present application specifically includes the following steps:

[0046] S210, calling a data structure class to receive and store the code segment, data segment, calibration segment and interrupt data of the to-be-flashed program.

[0047] The data structure class can be a program processing logic for receiving and storing data according to different data structures, for example, get() and set() methods written by a programming language, which can be used to access the attributes and / or methods of the to-be-flashed program. Of course, the method name of the specific data structure class can be defined by oneself.

[0048] In the embodiment of the present application, the code segment can be different logical codes corresponding to the flashing program data structure. The data segment can be a data region required for the program running, which is composed of global variables in different codes of the flashing program. The calibration segment can be a calibration segment composed of calibration quantities in different codes of the flashing program. The interrupt can refer to that when some unexpected situation occurs during the computer running process and the host needs to be intervened, the machine can automatically stop the running program and transfer to the program for processing the new situation, and after the processing is completed, the program continues to run. For example, each code has a different execution order, and when the current code is executed, another code is executed, at this time, the situation is an interrupt for the current code, but the current code needs to be saved for the other code to return to continue executing the current code after the execution is completed. Therefore, the space size required by the interrupted code can be the interrupt data.

[0049] Specifically, the corresponding data structure classes can be pre-written in different data structures, and when the to-be-written program is written, different data structure classes can be called in sequence to process the to-be-written code to obtain and store the code segment, data segment, calibration segment and interrupt data of the to-be-written code respectively. It can be understood that the data structure classes can be pre-written in the controller and called and executed when the to-be-written program is written.

[0050] S220, reading code content of the to-be-written program, wherein the code content includes code text, global variable, calibration and interrupt.

[0051] The code text can refer to the source code in the program, and has a processing logic with an execution function. The code text can be a human-readable text written in a programming language. The global variable is an external variable defined outside the function. The global variable can be created by an object function or anywhere in the program. The global variable can be referenced by all objects or functions of the to-be-written program. The scalar can be understood as a constant. The constant can refer to a quantity that is not modified by the program during the running of the computer program. The interrupt can refer to the case that the code of the to-be-written program has different execution orders during the running of the to-be-written program. When the current code is executed, another code is executed. At this time, the situation is interrupted for the current code.

[0052] In the embodiment of the application, the code content of the to-be-written program can be extracted, and the code text, global variable, calibration and interrupt in the code content can be extracted respectively. It can be understood that the code content can be pre-read into the register of the controller, and the reading of the code content can be realized by the operation of the register.

[0053] S230, respectively determining the memory occupation of the code text, global variable, calibration and interrupt, and taking each memory occupation as the running space occupation information.

[0054] The memory occupation can be the memory overhead required to support the storage and running of the to-be-written program. The memory occupation of each corresponding memory can be estimated for the code text, global variable, calibration and interrupt respectively. The determined memory occupation can be taken as the running space occupation information of the to-be-written program.

[0055] For example, the code written in the programming language can read the number of lines of all meaningful codes in the to-be-written program, and then calculate the memory space size required after conversion into a binary file, and take the memory space size as the code text memory occupation. For example, the number of lines of all meaningful codes in the to-be-written program can be 100 lines, and the maximum memory space size of each line can be 1 KB, so the memory space size required after conversion of all codes in the to-be-written program into a binary file can be 100 KB. The code written in the programming language can also read all global variables in the to-be-written program. For example, if there are 2 global variables in the to-be-written program, and the maximum memory space size required in all global variables is 1 KB, then the memory space required for all global variables in the to-be-written program can be 2 KB. The code written in the programming language can also read all calibration quantities in the to-be-written program. For example, if there are 2 calibration quantities in the to-be-written program, and the maximum memory space size required in all calibration quantities is 1 KB, then the memory space required for all calibration quantities in the to-be-written program can be 2 KB. The code written in the programming language can also read the priority of the interrupt vector table set in the to-be-written program, the parameters involved in the functions in the code, and the memory size required for temporary variables triggered by the interrupt. The interrupt vector table stores all interrupts in the to-be-written program. If the highest priority in the interrupt vector table is 8, it can be considered that the deepest interrupt level in the interrupt vector table is 8, and the memory size required for the deepest interrupt level is taken as the reference value of the interrupt memory size required by the to-be-written program. Since the memory size required by the interrupt, the parameters involved, and the temporary variables can be 2 KB, the memory occupation required by the interrupt in the to-be-written program is 16 KB. In addition, the memory space sizes required by the code text, the global variables, the calibration quantities, and the interrupt can be expressed as the memory occupation required by the code text, the global variables, the calibration quantities, and the interrupt, and the sum of the memory occupation required by the code text, the global variables, the calibration quantities, and the interrupt can be taken as the running space occupation information.

[0056] S240, determining whether the remaining space of the memory space satisfies the running space occupation information.

[0057] The remaining space of the memory space can be a space in the memory space that has not been occupied.

[0058] Specifically, the remaining space can be compared with the memory space corresponding to the running space occupation information, the size relationship between the remaining space and the memory space corresponding to the running space occupation information can be determined, and the writing process of the to-be-written program can be controlled according to different size relationships to realize accurate writing of the to-be-written code.

[0059] S250, if yes, reading a flashing start address of the to-be-flashed program in a preset region of the memory space, and writing the to-be-flashed program into the memory space according to the flashing start address.

[0060] The preset region can be a memory region in the memory space that is previously agreed to store the flashing start address, and the preset region can be located at the beginning or the end of the memory space, or can be a memory region corresponding to a fixed address in the memory space, and the flashing start address in the preset region can be used to identify the location of the remaining space in the memory space.

[0061] In the embodiment of the application, when the remaining space is greater than the memory space size corresponding to the running space occupation information of the to-be-flashed program, it can be determined that the remaining space satisfies the running space occupation information, the flashing start address can be read in the preset region, and the data of the to-be-flashed code can be sequentially flashed into the memory space with the flashing start address as the starting point.

[0062] It should be noted that when writing the to-be-flashed code, different regions of the memory space can be flashed according to different contents in the to-be-flashed code, for example, the starting address, size and termination address of the bootloader in the program flash (Pflash) of the current chip can be used to set the starting address of the to-be-flashed program, and the starting address and size of the data flash (dflash) of the current chip can be used to set the position and required space of global variables, calibration quantities and interruption writing, and ensure the continuity of the address to reduce the fragmentation of the space. The sum of the flashing start address of the to-be-flashed program and the memory space size corresponding to the running space occupation information of the to-be-flashed program is recorded as the flashing end address, and the address between the flashing start address and the flashing end address is continuous.

[0063] S260, if not, generating a flashing failure information and feeding back.

[0064] In the embodiment of the application, when the remaining space is less than the memory space size corresponding to the running space occupation information of the to-be-flashed program, it can be determined that the remaining space does not satisfy the running space occupation information, and then a flashing failure information is generated and fed back, for example, the flashing failure information can be "current chip performance is insufficient" and the like, and the failure information is returned to the user.

[0065] The technical scheme of the embodiment of the present application receives and stores the code segment, data segment, calibration segment and interrupt data of the to-be-flashed program by calling the data structure class, reads the code text, global variable, calibration quantity and interrupt in the code content of the to-be-flashed program, and takes the memory occupation of the code text, global variable, calibration quantity and interrupt as the running space occupation information to calculate the required running memory space size of the to-be-flashed program; and compares the required running memory space size of the to-be-flashed program with the residual space of the memory space, if the residual space of the memory space meets the required running memory space size of the to-be-flashed program, the to-be-flashed program is written into the memory space to ensure the correct flashing of the to-be-flashed program, if it is judged that the residual space of the memory space does not meet the required running memory space size of the to-be-flashed program, the flashing failure information is given to enable the user to re-adjust the work according to the flashing failure information.

[0066] Further, Figure 3 is a flowchart for determining the memory occupation of the code content provided by the second embodiment of the present application, referring to Figure 3 In the embodiment of the present application, the memory occupation of the code text, global variable, calibration quantity and interrupt is determined respectively, including:

[0067] S2301, the effective code line number of the code text is determined, and the product of the effective code line number and the code line space occupation coefficient is taken as the memory occupation of the code text.

[0068] The effective code line number can refer to the line number of the logical code with actual meaning in the to-be-flashed program, which can be obtained by subtracting the number of empty lines and the number of comment lines from the total number of all codes. It can be understood that the effective code line number in the code text can not include the number of empty lines and the number of comment lines. The code line space occupation coefficient can refer to the maximum length of the memory space occupied by each line of code, which can be set according to the experience of the developer, or can be determined by the average memory occupation length of the binary line code of the to-be-flashed program, which can more reasonably determine the memory occupation of the code text.

[0069] In the embodiment of the present application, the effective code line number in the code text can be counted, and the code line space occupation coefficient can be extracted, the product of the effective code line number and the code line space occupation coefficient can be determined, and the product can be taken as the memory occupation of the code text.

[0070] For example, the total number of lines of the code text is 500, including 20 lines of comments and empty lines, so the effective code line number of the code text is 480, and the average memory occupation length of the binary line code of the to-be-flashed program can be 2KB, so the memory occupation of the code text is the product of the effective code line number and the code line space occupation coefficient. That is, the memory occupation of the code text is 960KB.

[0071] S2302, respectively determine the data structure corresponding to each global variable and each calibration quantity, sum the data structure of each global variable as the memory occupation of the global variable, and sum the data structure of the calibration quantity as the memory occupation of the calibration quantity.

[0072] The data structure can be information reflecting the data type of the global variable and the calibration quantity, and the length of the memory space occupied by different data structures can be different. For example, there are two global variables in the to-be-flashed program, and the data structures of the two global variables are integer and character type, respectively. The length of the memory space required for integer storage can be 4 bytes, and the length of the memory space required for character storage can be 2 bytes. Therefore, the memory occupation of the global variable can be the sum of 4 bytes and 2 bytes, i.e., 6 bytes. For another example, the calibration quantity includes three integers, and the length of the memory space required for each integer storage is 2 bytes. Therefore, the memory occupation of the calibration quantity can be 3*2=6 bytes.

[0073] Specifically, the data structures corresponding to all global variables and calibration quantities can be counted, and the memory occupation required for each data structure storage can be obtained. The sum of the memory occupation required for each data structure in the global variable can be taken as the memory occupation of the global variable, and the sum of the data structures of the calibration quantity can be taken as the memory occupation of the calibration quantity.

[0074] S2303, in the preset interrupt vector table, find the deepest priority of the interrupt, and take the product of the memory size corresponding to the deepest priority interrupt and the number of interrupts as the memory occupation of the interrupt.

[0075] The interrupt can refer to that, during the normal execution of a program, due to the triggering of internal or external events or the pre-arrangement of the program, the processor temporarily interrupts the program currently running, and goes to execute the service subprogram for the internal or external event or the pre-arranged event of the program. After the execution of the interrupt service subprogram is completed, the processor returns to the program (breakpoint) that is temporarily interrupted to continue executing the original program. This process is called interrupt. The interrupt vector table can be considered to store all interrupt type codes and their corresponding interrupt vectors in a storage area according to a certain rule. This storage area is called interrupt vector table. The interrupt type code in the interrupt vector table can be an 8-bit binary number, which can be considered as the entry address of the interrupt service program. The deepest priority can be the priority corresponding to the highest priority interrupt type code of the to-be-flashed code. The number of interrupts can be the number of different interrupt type codes in the to-be-flashed code.

[0076] Specifically, the controller is responsive to higher level interrupt requests when processing interrupts, and masks interrupt requests of the same or lower level, thus the memory occupation of interrupts is related to the number of interrupts and the priority of interrupts, and the memory occupation of interrupts can be determined by the product of the number of interrupts and the priority of interrupts. For example, if the priority of interrupts has 8 levels, the deepest priority of interrupts can be the highest priority, the program of the priority needs to occupy 10KB of memory, and the product of the memory size corresponding to the deepest priority of interrupts and the number of interrupts is taken as the memory occupation of interrupts, that is, the memory occupation of interrupts is 80KB.

[0077] In the embodiment of the present application, the product of the effective code lines and the code line space occupation coefficient is taken as the memory occupation of code text, the sum of the data structures of global variables is taken as the memory occupation of global variables, and the sum of the data structures of the calibration quantity is taken as the memory occupation of the calibration quantity, and the product of the memory size corresponding to the deepest priority of interrupts and the number of interrupts is taken as the memory occupation of interrupts, so that the memory occupation of code text, the memory occupation of global variables, the memory occupation of calibration quantity and the memory occupation of interrupts can be effectively calculated, and thus the memory occupation of the program to be written can be effectively calculated.

[0078] In the embodiment of the present application, the product of the effective code lines and the code line space occupation coefficient is taken as the memory occupation of code text, the sum of the data structures of global variables is taken as the memory occupation of global variables, and the sum of the data structures of the calibration quantity is taken as the memory occupation of the calibration quantity, and the product of the memory size corresponding to the deepest priority of interrupts and the number of interrupts is taken as the memory occupation of interrupts, so that the memory occupation of code text, the memory occupation of global variables, the memory occupation of calibration quantity and the memory occupation of interrupts can be effectively calculated, and thus the memory occupation of the program to be written can be effectively calculated. Figure 4 is an implementation effect diagram of a program writing method of a controller provided by the embodiment of the present application, as shown in Figure 4 The overall class for implementing the program writing method of the present application includes MCUStruct_Class class, ReadMCU class, Disposition_Chip class and Generation_LinkFile class.

[0079] MCUStruct_Class is a data structure class, which can be used to receive and store the data of code section, data section, calibration section and interrupt memory size in the program to be written. The value of code section in the program to be written is obtained by using the get_CodeSize() function in the class, and the value of code section in the program to be written is set by using the set_CodeSize() function in the class; the value of data section in the program to be written is obtained by using the get_DataSize() function in the class, and the value of data section in the program to be written is set by using the set_DataSize() function in the class; the value of calibration section in the program to be written is obtained by using the get_Calib_DataSize() function in the class, and the value of calibration section in the program to be written is set by using the set_Calib_DataSize() function in the class; the value of interrupt data in the program to be written is obtained by using the get_Interrupt_MemenorySize() function in the class, and the value of interrupt data in the program to be written is set by using the set_Interrupt_MemenorySize() function in the class.

[0080] ReadMCU class, which can be used to read all the codes in the program to be written, and then calculate the memory size required by all the codes, and also can read the memory space size required by all global variables, the memory space size required by all calibration quantities and the memory space size required by the current code in the interrupt condition. Specifically, the Cal_CodeSize() function in the class reads the number of meaningful lines of all the codes in the current program, and then calculates the memory space size required after conversion into binary file; the Cal_DataSize() function in the class calculates the memory space size required by global variables by reading the global variables in the program to be written, the Cal_Calib_DataSize() function calculates the memory space size required by calibration quantities by reading the calibration quantities in the program to be written, and the Cal_Interrupt_Memory_Size() function reads the priority of the interrupt vector table set in the program to be written, and calculates the memory space size required by the priority of the interrupt vector table set in the program to be written, the parameters involved in the function and the temporary variables involved in the function when the interrupt is triggered.

[0081] Disposition_Chip class, the current chip specific pflash and dflash related start and end address information are stored in this class. The set_ChipSetting() function in this class is used to set the value of the current chip specific pflash and dflash related start and end address, and the get_ChipSetting() function in this class is used to obtain the value of the current chip specific pflash and dflash related start and end address.

[0082] Generation_LinkFile class, after the memory size data required for the program to be written is calculated by the ReadMCU class and the chip data is obtained according to the Disposition_Chip class, a LinkFile file is generated. The Generation_File() function in this class writes the program to be written into the pflash according to the start address, size in the pflash and the end address of the bootloader, writes the global variables, calibration quantities and interrupts in the program to be written into the dflash according to the start address and size of the dflash, and ensures the continuity of the address to reduce the fragmentation of the space.

[0083] Specifically, Figure 5 is an example diagram of another program writing method of a controller provided by the embodiment of the present application, referring to Figure 5 , the program writing in the controller can include the following steps:

[0084] First, the size and start address of the current chip pflash and dflash memory are configured, then all the source codes of the program to be written are read, it is judged whether the source codes of the program to be written are empty, if yes, it is printed that the code of the program to be written is empty and the whole process is ended, if not, the occupied space size required by the program to be written, the occupied space size required by the global variables in the program to be written, the occupied space size required by the calibration quantities in the program to be written and the estimated occupied space size required by the interrupts in the program to be written are calculated, then the total of the memory space size required by the program to be written is calculated and compared with the size of the current chip pflash and dflash, and it is judged whether the total of the memory space size required by the program to be written exceeds the size of the chip, if yes, it is printed that the current chip performance is insufficient and the whole process is ended, if not, the corresponding LinkFile file is generated and the whole process is ended.

[0085] Embodiment three

[0086] Figure 6is a structural block diagram of a program flashing device of a controller provided by embodiment three of the present application, the device can execute the program flashing method of the controller provided by any embodiment of the present application, has the function module and beneficial effect corresponding to the execution method. The device is configured in the controller to realize the program flashing method of the controller in the embodiment of the present application. As shown in Figure 6 The device includes a program receiving module 610, a space information module 620 and a program flashing module 630.

[0087] The program receiving module 610 is configured to obtain a to-be-flashed program according to a preset storage structure.

[0088] The space information module 620 is configured to determine running space occupation information of code content of the to-be-flashed program.

[0089] The program flashing module 630 is configured to write the to-be-flashed program into a memory space based on a flashing start address and the running space occupation information.

[0090] The technical solution of the embodiment of the present application, the program receiving module obtains the to-be-flashed program according to the preset storage structure, the space information module determines the running space occupation information of the code content of the to-be-flashed program, and the program flashing module writes the to-be-flashed program into the memory space based on the flashing start address and the running space occupation information. The above technical solution writes the to-be-flashed program into the memory space based on the estimated running memory size and start address of the to-be-flashed program, effectively saves the memory space, can improve the success rate of program flashing, thereby improving the stability of the controller running, can reduce the test time of determining the running parameters of the to-be-flashed program, and can improve the development efficiency of the controller.

[0091] Further, in the above device, the program receiving module 610 is specifically configured to:

[0092] Call a data structure class to receive and store code segments, data segments, calibration segments and interrupt data of the to-be-flashed program.

[0093] Further, in the above device, the space information module 620 includes a code reading unit and a memory determination unit:

[0094] The code reading unit is configured to read code content of the to-be-flashed program, wherein the code content includes code text, global variables, calibration quantities and interrupts.

[0095] The memory determination unit is configured to determine memory occupation amounts of the code text, global variables, calibration quantities and interrupts respectively, and take each of the memory occupation amounts as running space occupation information.

[0096] Further, the memory determining unit comprises a line number determining subunit, a structure determining subunit and a searching subunit.

[0097] The line number determining subunit is configured to determine the effective code line number of the code text, and the product of the effective code line number and the code line space occupation coefficient is taken as the memory occupation of the code text.

[0098] The structure determining subunit is configured to determine the data structure corresponding to each of the global variables and each of the constants respectively, take the sum of the data structures of the global variables as the memory occupation of the global variables, and take the sum of the data structures of the constants as the memory occupation of the constants.

[0099] The searching subunit is configured to search the deepest priority of the interrupt in a preset interrupt vector table, and take the product of the memory size corresponding to the deepest priority interrupt and the number of the interrupts as the memory occupation of the interrupts.

[0100] Further, the code line space occupation coefficient comprises the average memory occupation length of the binary line code of the to-be-flashed program.

[0101] Further, the program flashing module 630 is specifically configured to:

[0102] determine whether the remaining space of the memory space satisfies the running space occupation information, if yes, read the flashing start address of the to-be-flashed program in a preset area of the memory space, and write the to-be-flashed program into the memory space according to the flashing start address, and if not, generate a flashing failure information and feedback.

[0103] Further, the program flashing module 630 is further connected with an updating module.

[0104] The updating module is configured to update the flashing start address according to the running space occupation information of the to-be-flashed program.

[0105] The product can execute the program flashing method of the controller provided by the embodiments of the present application, and has the corresponding function modules and beneficial effects of the execution method.

[0106] Embodiment four

[0107] The embodiment four of the present application provides a controller. Figure 7 is a structural schematic diagram of the controller provided by the embodiment four of the present application. Figure 7As shown, the embodiment provides a controller, which can include a central processing unit and a memory. The memory stores at least one instruction, and the instruction is executed by the central processing unit, so that the controller executes the program flashing method of the controller as described in the above method embodiment.

[0108] Referring to Figure 7 The controller can specifically include a central processing unit 720, a memory 710, an input device 730, and an output device 740; the number of central processing units 720 in the controller can be one or more, Figure 7 The number of central processing units 720 in the controller can be one or more, Figure 7 The number of central processing units 720 in the controller can be one or more, Figure 7 The central processing unit 720, the memory 710, the input device 730, and the output device 740 in the controller can be connected through a bus or other means,

[0109] Specifically, in the embodiment, when the central processing unit 720 executes one or more programs stored in the memory 710, the following operations can be implemented: obtaining a to-be-flashed program according to a preset storage structure;

[0110] determining running space occupation information of code content of the to-be-flashed program;

[0111] writing the to-be-flashed program into a memory space based on a flashing start address and the running space occupation information.

[0112] The program flashing method, the device, the controller, and the storage medium provided in the above embodiment can execute the program flashing method of the controller provided in any embodiment of the present application, have the corresponding function modules and beneficial effects of executing the method. Technical details not described in detail in the above embodiment can be referred to the program flashing method of the controller provided in any embodiment of the present application.

[0113] Embodiment five

[0114] The embodiment five of the present application provides a computer readable storage medium, which stores a program, and the program is executed by a central processing unit to implement the program flashing method of the controller provided in all embodiments of the present application, and the method includes: obtaining a to-be-flashed program according to a preset storage structure; determining running space occupation information of code content of the to-be-flashed program; and writing the to-be-flashed program into a memory space based on a flashing start address and the running space occupation information.

[0115] The computer storage medium of the embodiments of the present application can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any combination thereof. More specific examples (non-exhaustive list) of the computer-readable storage medium include an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus or device.

[0116] The computer-readable signal medium can include a data signal propagated in baseband or propagated as a carrier wave in a propagated data signal, in which the computer-readable program code is contained. Such propagated data signal can take a variety of forms, including but not limited to electro-magnetic, optical or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium that is not a storage medium and that can be used to carry or propagate program code for use by or in connection with an instruction execution system, apparatus or device.

[0117] The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wire line, optical fiber cable, RF, etc., or any suitable combination of the above.

[0118] The computer program code for carrying out operations of the present application can be written in one or more programming languages or combinations of languages including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages such as "C" or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).

[0119] Note that the above merely describes preferred embodiments of the present application and the principles of the technology applied. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, modifications and substitutions can be made without departing from the scope of the present application. Therefore, although the present application has been described in detail through the above embodiments, the present application is not limited to the above embodiments, and can include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the claims.

Claims

1. A method for flashing a controller's program, characterized in that, The method includes: The program to be flashed is obtained according to the preset storage structure; Determine the runtime space usage information of the code content of the program to be flashed; The program to be flashed is written into the memory space based on the flashing start address and the running space occupancy information. The step of determining the runtime space occupancy information of the code content of the program to be flashed includes: Read the code content of the program to be flashed, wherein the code content includes: code text, global variables, scalar values, and interrupts; The memory usage of code text, global variables, calibrators, and interrupts is determined separately, and each of these memory usages is used as runtime space usage information; wherein, the runtime space usage information is the sum of the memory usage required by code text, global variables, calibrators, and interrupts; The determination of memory usage for code text, global variables, scalar values, and interrupts includes: The effective number of lines of code in the code text is determined, and the product of the effective number of lines of code and the code line space occupancy coefficient is taken as the memory usage of the code text; wherein, the effective number of lines of code refers to the number of lines of logical code with actual meaning in the program to be written, which is obtained by subtracting the number of blank lines and the number of comment lines from the total number of lines of all code; the code line space occupancy coefficient refers to the maximum length of memory space occupied by each line of code; The data structures corresponding to each global variable and each calibrated value are determined respectively. The sum of the data structures of the global variable is used as the memory usage of the global variable, and the sum of the data structures of the calibrated value is used as the memory usage of the calibrated value. The data structures reflect the data types of the global variable and the calibrated value, and different data structures occupy different lengths of memory space. The deepest priority of the interrupt is found in the preset interrupt vector table, and the memory size corresponding to the deepest priority interrupt is multiplied by the number of interrupts as the memory usage of the interrupt; wherein, when the controller processes interrupts, it responds to higher-level interrupt requests and blocks interrupt requests of the same or lower level. The step of writing the program to be flashed into memory space based on the flashing start address and the running space occupancy information includes: Determine whether the remaining space in the memory space satisfies the runtime space occupancy information; If the conditions are met, the flashing start address of the program to be flashed is read from the preset area of ​​the memory space, and the program to be flashed is written into the memory space according to the flashing start address; wherein, the addresses between the flashing start address and the flashing end address are consecutive. If the conditions are not met, a flashing failure message will be generated and reported.

2. The method according to claim 1, characterized in that, The step of obtaining the program to be flashed according to the preset storage structure includes: The data structure class is called to receive and store the code segment, data segment, calibration segment, and interrupt data of the program to be flashed.

3. The method according to claim 1, characterized in that, The code line space occupancy coefficient includes: the average memory occupancy length of the binary line code of the program to be written.

4. The method according to any one of claims 1-3, characterized in that, After writing the program to be flashed into the memory space based on the flashing start address and the runtime space occupancy information, the process further includes: The flashing start address is updated based on the runtime space usage information of the program to be flashed.

5. A program flashing device for a controller, characterized in that, The device includes: The program receiving module is used to obtain the program to be flashed according to the preset storage structure; The spatial information module is used to determine the space occupancy information of the code content of the program to be written; The program flashing module is used to write the program to be flashed into the memory space based on the flashing start address and the running space occupancy information; The spatial information module includes: The code reading unit is used to read the code content of the program to be flashed, wherein the code content includes: code text, global variables, calibrated values, and interrupts; A memory determination unit is used to determine the memory usage of code text, global variables, calibrators, and interrupts respectively, and to use each of the memory usages as runtime space usage information; wherein, the runtime space usage information is the sum of the memory usage required by code text, global variables, calibrators, and interrupts; The memory determination unit includes: The line count determination subunit is used to determine the effective number of lines of code in the code text, and to use the product of the effective number of lines of code and the line space occupancy coefficient as the memory usage of the code text; wherein, the effective number of lines of code refers to the number of lines of logical code with actual meaning in the program to be written, which is obtained by subtracting the number of blank lines and the number of comment lines from the total number of lines of all code; the line space occupancy coefficient refers to the maximum length of memory space occupied by each line of code; The structure determination subunit is used to determine the data structure corresponding to each global variable and each calibrator, and to use the sum of the data structures of the global variable as the memory usage of the global variable, and the sum of the data structures of the calibrator as the memory usage of the calibrator; wherein, the data structure reflects the data type information of the global variable and the calibrator, and different data structures occupy different lengths of memory space; The lookup subunit is used to find the deepest priority of the interrupt in the preset interrupt vector table, and the memory size corresponding to the deepest priority interrupt is multiplied by the number of interrupts as the memory usage of the interrupt; wherein, when the controller processes interrupts, it responds to higher-level interrupt requests and masks interrupt requests of the same or lower level. Specifically, the program flashing module is used for: Determine whether the remaining space in the memory space satisfies the running space occupancy information; if it does, read the flashing start address of the program to be flashed from the preset area of ​​the memory space, and write the program to be flashed into the memory space according to the flashing start address; wherein the addresses between the flashing start address and the flashing end address are continuous; if it does not satisfy the condition, generate flashing failure information and provide feedback.

6. A controller, characterized in that, The controller includes: One or more central processing units; Memory, used to store one or more programs. When the one or more programs are executed by the one or more central processing units, the one or more central processing units implement the program flashing method of the controller as described in any one of claims 1-4.

7. A computer-readable storage medium having a program stored thereon, characterized in that, When the program is executed by the central processing unit, it implements the program flashing method of the controller as described in any one of claims 1-4.

Citation Information

Patent Citations

  • ECU data flashing method and related device

    CN111722864A