Method and device for generating initialization code of mcu, medium, program product and equipment
By automatically generating MCU initialization code through mapping relationship files, the problem of high complexity in MCU application development is solved. It achieves efficient and standardized initialization code generation, supports the development of multiple MCU models, and protects the user's upper-level code.
Patent Information
- Application Number
- CN202411999961.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2044-12-31
AI Technical Summary
MCU application development is highly complex, and the initialization code is cumbersome and non-standard, which increases the difficulty of development, especially due to the large number of MCU models, resulting in a large workload.
By obtaining the user-set initialization information, the initialization code of the MCU is generated using the mapping relationship file. The mapping relationship file records the mapping relationship between the interface between the module to be initialized and the configuration function of the MCU driver library, the configurable items and the configuration function parameters, and the optional items and the parameter enumeration values, and automatically generates the initialization code.
It improves the development efficiency of MCU applications and the accuracy and standardization of code, supports the initialization of various MCU models, has good versatility and portability, and protects the upper-level code edited by users from being overwritten.
Smart Images

Figure CN119917158B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computers, and particularly relates to a generation method and device of initialization code of MCU, a medium, a program product and equipment. BACKGROUND
[0002] A microcontroller unit (MCU) is a single-chip microcomputer in which main parts of a microcomputer are integrated on a chip. The MCU is a powerful and small control chip, and is favored by engineers in various industries. With the continuous development of MCU technology, the MCU can integrate more and more functions. For developers of MCU applications, the more complex the functions of the MCU are, the more complex the corresponding initialization code is, which increases the difficulty and complexity of the development of the MCU application. SUMMARY
[0003] Therefore, one of the technical purposes of the embodiments of the present application is to provide a generation method of initialization code of MCU, which can reduce the development difficulty of the MCU application, improve the development efficiency of the MCU application, and improve the standardization and accuracy of the initialization code of the MCU.
[0004] In addition, one of the technical purposes of the embodiments of the present application is to provide a generation method of initialization code of MCU suitable for different models, which can have universality and portability, so as to solve the problem of large development workload caused by the large number of MCU models, and improve the development efficiency of the code generation device in the present application.
[0005] In a first aspect, an embodiment of the present application provides a method for generating initialization code of an MCU, the method comprising: obtaining initialization information set by a user, the initialization information comprising configuration information of a plurality of to-be-initialized modules, wherein each of the to-be-initialized modules has at least one configurable item, each of the configurable items has a plurality of selectable items, and the configuration information comprises a target item of each of the configurable items, the target item being selected from the plurality of selectable items; reading a mapping relationship file, the mapping relationship file recording a mapping relationship set, the mapping relationship set comprising a first-level mapping relationship, a second-level mapping relationship, and a third-level mapping relationship, wherein the first-level mapping relationship refers to a mapping relationship between the to-be-initialized module and an interface of a configuration function in a driver library of the MCU, the second-level mapping relationship refers to a mapping relationship between the configurable item and a parameter of the configuration function, and the third-level mapping relationship refers to a mapping relationship between the selectable item and an enumeration value of the parameter; determining code calling information of each of the to-be-initialized modules based on the mapping relationship file, the code calling information of each of the to-be-initialized modules comprising: an interface of a configuration function corresponding to the to-be-initialized module, a parameter corresponding to each of the configurable items of the to-be-initialized module, and an enumeration value corresponding to the target item of each of the configurable items; and calling code of the configuration function corresponding to each of the to-be-initialized modules based on the code calling information of the to-be-initialized module, to generate the initialization code.
[0006] Optionally, the initialization information further comprises a model of the MCU, and the mapping relationship file records mapping relationship sets of MCUs of a plurality of models; and determining the code calling information of each of the to-be-initialized modules of the MCU based on the mapping relationship file comprises: determining a target mapping relationship set in the mapping relationship file according to the model of the MCU; and determining the code calling information of each of the to-be-initialized modules of the MCU based on the target mapping relationship set.
[0007] Optionally, before receiving the initialization information set by the user, the method further comprises: reading a header file corresponding to each of the to-be-initialized modules from a driver library of the MCU, the header file providing an interface of the configuration function, a parameter of the configuration function, and an enumeration value list of the parameter; extracting the first-level mapping relationship according to the interface of the configuration function and an annotation of the interface; extracting the second-level mapping relationship according to each of the parameters of the configuration function and an annotation of each of the parameters; and extracting the third-level mapping relationship according to the enumeration value list of the parameter and an annotation of the enumeration value list.
[0008] Optionally, the obtaining the initialization information set by the user comprises: determining graphical controls selected by the user on a configuration interface of each of the to-be-initialized modules, wherein the configuration interface of each of the to-be-initialized modules displays graphical controls of multiple selectable items of each of the configurable items; and determining the initialization information based on the selected graphical controls.
[0009] Optionally, the mapping relationship file is an XML file.
[0010] Optionally, the method further comprises: calling an engineering template; and generating an IDE project based on the initialization code and the engineering template.
[0011] Optionally, the method further comprises: receiving an upper-layer code input by the user to obtain a code of the MCU, wherein the code of the MCU comprises the initialization code and the upper-layer code; and if the code protection function is enabled when the user updates the initialization information, shielding the upper-layer code and regenerating the initialization code.
[0012] In a second aspect, an embodiment of the present application provides a device for generating an initialization code of an MCU, the device comprising: an initialization information receiving module configured to obtain initialization information set by a user, wherein the initialization information comprises configuration information of multiple to-be-initialized modules, each of the to-be-initialized modules has at least one configurable item, each of the configurable items has multiple selectable items, and the configuration information comprises target items of the configurable items, the target items being selected from the multiple selectable items; a file reading module configured to read a mapping relationship file, wherein the mapping relationship file records a mapping relationship set, the mapping relationship set comprises a first-level mapping relationship, a second-level mapping relationship and a third-level mapping relationship, the first-level mapping relationship refers to a mapping relationship between the to-be-initialized modules and interfaces of configuration functions in a driver library of the MCU, the second-level mapping relationship refers to a mapping relationship between the configurable items and parameters of the configuration functions, and the third-level mapping relationship refers to a mapping relationship between the selectable items and enumeration values of the parameters; a mapping module configured to determine code calling information of each of the to-be-initialized modules based on the mapping relationship file, wherein the code calling information of each of the to-be-initialized modules comprises an interface of a configuration function corresponding to the to-be-initialized module, parameters corresponding to the configurable items of the to-be-initialized module, and enumeration values corresponding to the target items of the configurable items; and a calling module configured to, for each of the to-be-initialized modules, call the configuration function corresponding to the to-be-initialized module based on the code calling information of the to-be-initialized module to generate the initialization code.
[0013] In a third aspect, an embodiment of the present application provides a computer readable storage medium, having stored thereon a computer program, which, when run on a processor, causes the MCU initialization code generation method to be performed.
[0014] In a fourth aspect, an embodiment of the present application provides a computer program product, comprising a computer program which, when executed on a processor, implements the steps of the MCU initialization code generation method.
[0015] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, the memory having stored thereon a computer program which is run on the processor, and the processor, when running the computer program, implements the steps of the MCU initialization code generation method.
[0016] Compared with the prior art, the technical scheme of the embodiment of the present application has the following beneficial effects:
[0017] In the scheme of the embodiment of the present application, each to-be-initialized module of the MCU has at least one configurable item, each configurable item has a plurality of optional items, and a user selects a target item of the configurable item from the plurality of optional items to obtain initialization information. The mapping relationship file records a mapping relationship set, and the mapping relationship set includes a first-level mapping relationship, a second-level mapping relationship and a third-level mapping relationship, wherein the first-level mapping relationship refers to a mapping relationship between the to-be-initialized module and an interface of a configuration function in a driver library of the MCU, the second-level mapping relationship refers to a mapping relationship between the configurable item and a parameter of the configuration function, and the third-level mapping relationship refers to a mapping relationship between the optional item and an enumeration value of the parameter. Based on the mapping relationship file and the initialization information set by the user, the interface of the configuration function corresponding to each to-be-initialized module, the parameter corresponding to each configurable item, and the enumeration value corresponding to each target item are determined. Thus, for each to-be-initialized module, based on the interface of the configuration function corresponding to the to-be-initialized module, the parameters corresponding to each configurable item of the to-be-initialized module, and the enumeration value corresponding to each target item, the code of the configuration function corresponding to the to-be-initialized module is called, so that the initialization code of the MCU can be generated.
[0018] In the above scheme, the user only needs to set the configuration information of each to-be-initialized module, and the configuration function in the driver library of the MCU is called by using the pre-set mapping relationship set, so that the initialization code of the MCU is automatically generated. By adopting such a scheme, not only can the initialization code be efficiently generated, but also the accuracy and standardization of the initialization code can be ensured, thereby improving the overall development efficiency of the MCU application.
[0019] Further, in the scheme of the embodiment of the application, the first-level mapping relationship is extracted according to the interface of the configuration function and the annotation of the interface; the second-level mapping relationship is extracted according to each parameter of the configuration function and the annotation of each parameter; and the third-level mapping relationship is extracted according to the enumeration value list of the parameter and the annotation of the enumeration value list, so that the mapping relationship set can be obtained. The scheme of automatically extracting the mapping relationship can improve the efficiency of extracting the mapping relationship and has high universality and portability.
[0020] Further, in the scheme of the embodiment of the application, the mapping relationship file records the mapping relationship sets of multiple models of MCUs, and the initialization information includes the model of the MCU. After the mapping relationship file is read, the target mapping relationship set is determined from the mapping relationship file based on the model of the MCU in the initialization information, and then the initialization code is generated based on the target mapping relationship set. The above scheme can efficiently support the initialization of multiple models of MCUs, has good universality and portability, can solve the problem of large development workload caused by the large number of MCU models, and is beneficial to improving the development efficiency of the code generation device in the application.
[0021] Further, in the scheme of the embodiment of the application, if the user code protection function is enabled, the upper-layer code input by the user is shielded in the process of regenerating the initialization code. That is, if the user code protection function is enabled, in the process of regenerating the initialization code, the newly generated initialization code only covers the initialization code in the MCU code, and the upper-layer code in the MCU code is retained. By using the scheme, the user-edited upper-layer code can be protected on the basis of supporting the update of the initialization code, the user-edited upper-layer code is avoided from being covered or deleted, and the development efficiency of the MCU is improved. BRIEF DESCRIPTION OF DRAWINGS
[0022] Figure 1 is a flow diagram of a method for generating initialization code of an MCU in the embodiment of the application;
[0023] Figure 2 is a schematic diagram of a configuration interface in the embodiment of the application;
[0024] Figure 3 is a schematic diagram of a mapping relationship in the embodiment of the application;
[0025] Figure 4 is a structural schematic diagram of a device for generating initialization code of an MCU in the embodiment of the application;
[0026] Figure 5 is a flow diagram of another method for generating initialization code of an MCU in the embodiment of the application;
[0027] Figure 6is a flowchart of a method for generating a mapping relationship file in an embodiment of the present application. DETAILED DESCRIPTION
[0028] As described in the background, with the development of technology, the MCU is becoming more and more powerful, which leads to the development of MCU application more and more difficult and complicated. Especially in the development process of MCU initialization, the kernel, clock, peripherals and other modules to be initialized need to be configured, therefore, the initialization code is complex, and if one of the configurations deviates, the MCU cannot run according to the development requirements.
[0029] Therefore, the embodiment of the present application provides a method for generating initialization code of MCU. In the scheme of the embodiment of the present application, each initialization module of MCU has at least one configurable item, each configurable item has a plurality of optional items, and the user selects the target option of the configurable item from the plurality of optional items to obtain the initialization information. The mapping relationship file records a mapping relationship set, and the mapping relationship set includes a first-level mapping relationship, a second-level mapping relationship and a third-level mapping relationship, wherein the first-level mapping relationship refers to the mapping relationship between the initialization module and the interface of the configuration function in the driver library of MCU, the second-level mapping relationship refers to the mapping relationship between the configurable item and the parameter of the configuration function, and the third-level mapping relationship refers to the mapping relationship between the optional item and the enumeration value of the parameter. Based on the above mapping relationship file and the initialization information set by the user, the interface of the configuration function corresponding to each initialization module, the parameter corresponding to each configurable item, and the enumeration value corresponding to each target option are determined. Therefore, for each initialization module, based on the interface of the configuration function corresponding to the initialization module, the parameters corresponding to each configurable item of the initialization module, and the enumeration value corresponding to each target option, the code of the configuration function corresponding to the initialization module is called, so that the initialization code of MCU can be generated.
[0030] In the above scheme, the user only needs to set the configuration information of each initialization module, and the configuration function in the driver library of MCU is called by using the pre-set mapping relationship set, so that the initialization code of MCU is automatically generated. By using such a scheme, not only the initialization code can be efficiently generated, but also the accuracy and standardization of the initialization code can be ensured, so that the overall development efficiency of MCU application is improved.
[0031] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application will be described in detail below with reference to the drawings.
[0032] Reference Figure 1 , Figure 1 is a flowchart of a method for generating initialization code of MCU in an embodiment of the present application. Figure 1The illustrated scheme can be applied to an electronic device, which can be a computer or the like used by an MCU developer. Figure 1 The illustrated method can include S11-S14.
[0033] S11, obtaining initialization information set by a user, the initialization information including configuration information of a plurality of modules to be initialized;
[0034] S12, reading a mapping relationship file, the mapping relationship file recording a mapping relationship between the modules to be initialized and interfaces of configuration functions, a mapping relationship between configurable items and parameters of the configuration functions, and a mapping relationship between enumeration values of the configurable items and the parameters;
[0035] S13, determining code calling information of each of the modules to be initialized based on the mapping relationship file;
[0036] S14, for each of the modules to be initialized, calling code of a configuration function corresponding to the module to be initialized based on the code calling information of the module to be initialized, to generate the initialization code.
[0037] In S11, the initialization information set by the user includes configuration information of a plurality of modules to be initialized.
[0038] Specifically, in an initialization process of an MCU, a plurality of modules to be initialized need to be initialized. Exemplarily, the plurality of modules to be initialized can include a kernel, a clock, a pin, and an external device, and the like.
[0039] More specifically, each of the modules to be initialized has at least one configurable item, wherein each of the configurable items has a plurality of optional items. In the initialization process of the MCU, for each of the configurable items of each of the modules to be initialized, one of the plurality of optional items of the configurable item needs to be selected as a target item of the configurable item. Thus, the configuration information of each of the modules to be initialized includes target items of the configurable items of the module to be initialized.
[0040] Referring to Table 1, Table 1 shows configurable items of a plurality of modules to be initialized.
[0041] Table 1
[0042]
[0043]
[0044] It should be noted that the above only exemplarily describes the modules to be initialized, the configurable items, and the optional items of the MCU. The number and specific content of the modules to be initialized, the configurable items, and the optional items are not limited by the embodiments of the present application.
[0045] In S11, the user can select a target option of each configurable item of each initialization module.
[0046] In a possible implementation of S11, the user can set the target option through a graphical user interface. That is, the user can set the initialization information through the graphical interface.
[0047] Specifically, in S11, a configuration interface is displayed to the user, and the user selects a graphical control of the target option of the configurable item through the configuration interface. Based on the graphical control selected by the user, the initialization information can be determined. For example, in the configuration interface, each configurable item can have a drop-down menu, and a plurality of selectable options can be displayed in the drop-down menu. The user can select the target option in the drop-down menu.
[0048] Referring to Figure 2 , Figure 2 is a schematic diagram of a configuration interface in an embodiment of the present application. As Figure 2 indicated, one configuration interface corresponds to one initialization module. Figure 2 indicated, one configuration interface corresponds to one initialization module. Figure 2 indicated, one configuration interface corresponds to one initialization module.
[0049] Continuing to refer to Figure 1 In S12, a mapping relationship file is read, and the mapping relationship file records a mapping relationship set. In the scheme of the present application, the mapping relationship set can include a first-level mapping relationship, a second-level mapping relationship, and a third-level mapping relationship.
[0050] Referring to Figure 3 , Figure 3 is a schematic diagram of a mapping relationship set in an embodiment of the present application. As shown in Figure 3 , the first-level mapping relationship refers to the mapping relationship between the to-be-initialized module and the configuration function in the driving library of the MCU.
[0051] Specifically, the configuration operation of each to-be-initialized module is embodied in the form of a configuration function in the source code of the MCU driving library. The to-be-initialized module and the configuration function can be one-to-one corresponding, in other words, the interfaces of the to-be-initialized module and the configuration function are one-to-one corresponding. That is, each to-be-initialized module corresponds to a configuration function in the MCU driving library. The parameter type of the configuration function can be a structure type, and the structure can include at least one parameter.
[0052] Further, the parameter and the configurable item of the to-be-initialized module corresponding to the configuration function are one-to-one corresponding. The second-level mapping relationship refers to the mapping relationship between the configurable item and the parameter of the configuration function. As shown in Figure 3 , the parameter of the configuration function is a structure parameter, the structure includes parameter 1, parameter 2 and parameter 3, and the to-be-initialized module corresponding to the configuration function has configurable item 1, configurable item 2 and configurable item 3. The second-level mapping relationship can include the mapping relationship between parameter 1 and configurable item 1, the mapping relationship between parameter 2 and configurable item 2, and the mapping relationship between parameter 3 and configurable item 3.
[0053] Further, for each parameter, the parameter can have a corresponding enumeration list, and the enumeration list can include a plurality of enumeration values, each enumeration value corresponding to an optional item of the configurable item corresponding to the parameter. The third-level mapping relationship refers to the mapping relationship between the optional item and the enumeration value of the parameter.
[0054] Continuing to refer to Figure 1 , in S13, based on the initialization information input by the user and the mapping relationship set described above, the code calling information of each to-be-initialized module can be determined. The code calling information of each to-be-initialized module includes the interface of the configuration function corresponding to the to-be-initialized module, the parameters corresponding to each configurable item of the to-be-initialized module, and the enumeration value corresponding to the target option of each configurable item.
[0055] Further, in S14, for each to-be-initialized module, based on the interface of the configuration function corresponding to the to-be-initialized module, the parameters corresponding to each configurable item of the to-be-initialized module, and the enumeration value corresponding to the target option of each configurable item, the code of the configuration function corresponding to the to-be-initialized module is called, thereby obtaining the initialization code.
[0056] Referring to Figure 5 , Figure 5 is a flowchart of another method for generating initialization code of an MCU in the embodiments of the present application. As shown in Figure 5 , the method for generating initialization code of an MCU can include the following steps:
[0057] S51, obtaining initialization information set by a user.
[0058] S52, reading a mapping relationship file.
[0059] S53, determining code calling information of each module to be initialized based on the mapping relationship file.
[0060] S54, calling code of a configuration function corresponding to the module to be initialized based on the code calling information, to generate initialization code.
[0061] For specific contents of S51 to S54, refer to the related description of S11 to S14 above, which will not be repeated here.
[0062] After S54, S55 can be executed.
[0063] S55, judging whether the configurations in the initialization code are consistent with the initialization information set by the user.
[0064] Specifically, the parameters of the configuration function corresponding to each module to be initialized and their values can be extracted from the initialization code, and then based on the mapping relationship set, it is judged whether the optional items corresponding to each value are consistent with the target items in the initialization information set by the user. If the judgment result is no, S56 can be executed, and if the judgment result is yes, S57 can be executed.
[0065] S56, outputting configurations in the initialization code that are inconsistent with the initialization information set by the user.
[0066] Specifically, the values corresponding to the optional items that are inconsistent with the target items set by the user in S56, as well as the parameters to which the values belong, the configuration functions to which the parameters belong, and other information can be outputted.
[0067] S57, judging whether the initialization code has syntax errors.
[0068] Specifically, the initialization code can be compiled by a compiler to determine whether there are syntax errors in the initialization code.
[0069] If the judgment result is yes, S58 is executed. If the judgment result is no, the process ends.
[0070] S58, outputting syntax error information.
[0071] Specifically, the user can be outputted the code with syntax error in the initialization code, and the type of the syntax error and the like.
[0072] After S56 and S58, the user can reset the target option of the optional item of each initialization module, and return to S51 to regenerate the initialization code.
[0073] From the above, Figure 5 In the scheme shown, after generating the initialization code, by comparing the configuration in the initialization code with the initialization information set by the user, and judging the syntax error, the accuracy of the initialization code is improved.
[0074] Exemplarily, the mapping relationship file in the embodiment of the application can be an Extensible Markup Language (XML) file, but is not limited thereto.
[0075] In a specific implementation, the mapping relationship file is generated based on the MCU driver library in advance. The generation method of the mapping relationship file is described below.
[0076] Specifically, the driver library of the MCU can include a plurality of header files corresponding to the initialization modules. The style of the driver library of the MCU is unified. Specifically, one header file corresponds to one initialization module, and the header file corresponding to each initialization module can provide the interface of the configuration function corresponding to the initialization module, the parameters of the configuration function, and the enumeration value list of the parameters.
[0077] In a possible implementation, the mapping relationship file can be manually extracted. Specifically, the mapping relationship set described above can be manually extracted from the header file in the driver library of the MCU.
[0078] In another possible implementation, the mapping relationship file can be automatically extracted and generated. Exemplarily, since the style of the driver library of the MCU is unified, the Python script can be used to extract and generate from the driver library of the MCU.
[0079] Referring to Figure 6 , Figure 6 is a flowchart of a generation method of a mapping relationship file in the embodiment of the application. Specifically, Figure 6 The method shown can include the following steps:
[0080] S61, forming a first-level mapping relationship in the header file.
[0081] Specifically, the interface of each configuration function and the corresponding comment are configured in the source code of the header file of the MCU to form the first-level mapping relationship.
[0082] S62, forming a second-level mapping relationship in the header file.
[0083] Specifically, the parameters of each configuration function and the corresponding comments are configured in the source code of the header file of the MCU to form the second-level mapping relationship.
[0084] S63, forming a third-level mapping relationship in the header file.
[0085] Specifically, the enumeration value list of each parameter and the corresponding comments are configured in the source code of the header file of the MCU to form the third-level mapping relationship.
[0086] S64, judging whether the header file meets the requirements of the regular expression.
[0087] S65, outputting information of the mapping relationship that does not meet the requirements of the regular expression.
[0088] Specifically, the code that does not meet the requirements of the regular expression and the comments of the code can be outputted. The code that does not meet the requirements of the regular expression can include at least one of the following: code of the configuration function interface, code of the parameters of the configuration function, and code of the enumeration value list of the parameters.
[0089] Further, after S65, it can return to S61 to regenerate the mapping relationship file.
[0090] S66, extracting the mapping relationship set by using the regular expression script to generate the mapping relationship file. Specifically, the source code of the header file of the MCU has comments, and the first-level mapping relationship can be extracted according to the interface of the configuration function and the comments of the interface in the header file.
[0091] Further, for one configuration function, the second-level mapping relationship can be extracted based on each parameter of the configuration function and the comment of each parameter.
[0092] Further, for one parameter, the third-level mapping relationship can be extracted based on the enumeration values contained in the enumeration value list of the parameter and the comment of each enumeration value.
[0093] The following takes the initialization module A as an example for description.
[0094] First, the first-level mapping relationship is extracted.
[0095] Specifically, the interface of the configuration function corresponding to the initialization module xxx in the driver library is:
[0096] module_xxx_init(module_xxx_init_t*init); / / module xxx configuration
[0097] Based on the interface and the annotation of the interface, a mapping relationship between the to-be-initialized module xxx and the configuration function module_xxx_init_t can be extracted:
[0098] <Function Name="module_xxx_init">
[0099] <Parameter Name="module A configuration" Type="module_xxx_init_t" / >
[0100]
[0101] Secondly, a second-level mapping relationship is extracted.
[0102] Specifically, the parameters of the configuration function module_xxx_init_t defined in the driver library include aaa and bbb:
[0103]
[0104] Based on the defined parameters and the annotation of the parameters, a mapping relationship between the configurable items of the to-be-initialized module xxx and the parameters of the configuration function module_xxx_init_t can be extracted:
[0105]
[0106] Finally, a third-level mapping relationship is extracted.
[0107] Specifically, the enumeration list of the parameter aaa and the enumeration list of the parameter bbb defined in the driver library are as follows:
[0108]
[0109] Based on the enumeration values of each parameter and the annotation of each enumeration value, a mapping relationship between the optional items of the configurable items and the enumeration values of the parameters of the configuration function module_xxx_init can be extracted:
[0110]
[0111]
[0112] Further, in the method shown in the figure, the method can further include: S67, outputting history information of generating the mapping relationship file. Figure 6
[0113] Compared with the scheme of manually extracting the mapping relationship file, the scheme of automatically extracting the mapping relationship file can improve the efficiency of extracting the mapping relationship. In addition, the method of automatically extracting the mapping relationship file has high universality and portability. Specifically, the portability means that the method of automatically extracting the mapping relationship can be reused to extract the mapping relationship set of multiple models of MCU.
[0114] In an embodiment of the present application, the user can also select the model of the MCU.
[0115] Specifically, the mapping relationship file can record the mapping relationship set of multiple models of MCU. More specifically, one model can correspond to one mapping relationship set.
[0116] In S11, the user can set the model of the MCU, that is, the user can set the model of the MCU to be initialized. In other words, the initialization information can include the model of the MCU. In S12, the target mapping relationship set can be determined from the mapping relationship file based on the model of the MCU, and then in S13 and S14, the enumeration value corresponding to the target option of each configurable item in each of the to-be-initialized modules of the MCU can be determined based on the target mapping relationship set, and then the initialization code is generated. The target mapping relationship set refers to the mapping relationship set of the model of the MCU selected by the user.
[0117] For example, the mapping relationship file can record the mapping relationship set of model 1, the mapping relationship set of model 2, and the mapping relationship set of model 3. The user selects the model of the MCU to be initialized as model 1, and the target mapping relationship set is the mapping relationship set of model 1.
[0118] From the above, the scheme of the embodiment of the present application can efficiently support the initialization of multiple models of MCU, has good universality and portability, and can solve the problem of large development workload caused by the large number of MCU models, which is beneficial to improve the development efficiency of the initialization code generation device of the MCU in the embodiment of the present application.
[0119] Further, the scheme provided by the embodiment of the present application can also realize the user code protection function.
[0120] Specifically, by executing S11 to S14, the initialization code can be automatically generated. Further, the user can edit the upper layer code based on the initialization code. The upper layer code can include: the code of the intermediate layer and / or the code of the application layer. After receiving the upper layer code input by the user, the code of the MCU can be obtained.
[0121] In a specific implementation, after the user edits the upper-layer code, if the initialization code needs to be updated, the user can reconfigure the initialization information and execute S11 to S14 again to update the initialization code. If the user code protection function is enabled, the user-edited upper-layer code is shielded during the process of regenerating the initialization code. That is, if the user code protection function is enabled, during the process of regenerating the initialization code, the newly generated initialization code only covers the initialization code in the MCU code, and the upper-layer code in the MCU code is retained. With such a scheme, the user-edited upper-layer code can be protected on the basis of supporting the update of the initialization code, the user-edited upper-layer code is prevented from being covered or deleted, and the development efficiency of the MCU application is improved.
[0122] Further, the method provided in the embodiments of the present application can further include: calling an engineering template, and generating an integrated development environment (IDE) project according to the generated initialization code and the engineering template. The engineering template can be preconfigured. For example, the preconfigured engineering template can be called by using an SCons script to generate a corresponding IDE project.
[0123] It can be understood that, in a specific implementation, the above method can be implemented in the form of a software program running in a processor integrated in a chip or a chip module, or the method can be implemented in the form of hardware or a combination of software and hardware, for example, by using a dedicated chip or a chip module, or by using a dedicated chip or a chip module in combination with a software program.
[0124] Reference Figure 4 , Figure 4 is a structural schematic diagram of an initialization code generation apparatus of an MCU in the embodiments of the present application. As shown in Figure 4 , the initialization code generation apparatus of the MCU can include:
[0125] The initialization information receiving module 41 is configured to obtain initialization information set by a user, and the initialization information includes configuration information of a plurality of to-be-initialized modules. Each to-be-initialized module has at least one configurable item, each configurable item has a plurality of optional items, and the configuration information includes a target item of each configurable item, and the target item is selected from the plurality of optional items.
[0126] The file reading module 42 is configured to read a mapping relationship file, wherein the mapping relationship file records a mapping relationship set, and the mapping relationship set includes a first-level mapping relationship, a second-level mapping relationship and a third-level mapping relationship. The first-level mapping relationship refers to a mapping relationship between an interface of a configuration function in a driving library of the MCU and the to-be-initialized module. The second-level mapping relationship refers to a mapping relationship between a configurable item and a parameter of the configuration function. The third-level mapping relationship refers to a mapping relationship between a selectable item and an enumeration value of the parameter.
[0127] The mapping module 43 is configured to determine code calling information of each to-be-initialized module based on the mapping relationship file. The code calling information of each to-be-initialized module includes an interface of a configuration function corresponding to the to-be-initialized module, parameters corresponding to each configurable item of the to-be-initialized module, and enumeration values corresponding to target selectable items of each configurable item.
[0128] The calling module 44 is configured to call, for each to-be-initialized module, code of a configuration function corresponding to the to-be-initialized module based on the code calling information of the to-be-initialized module, to generate the initialization code.
[0129] In an implementation manner, the MCU initialization code generation apparatus described above can be MCU code generation software, which can automatically generate initialization code based on initialization information set by a user.
[0130] For more information about the working principle, working method and beneficial effects of the MCU initialization code generation apparatus in the embodiments of the present application, refer to the related description of the MCU initialization code generation method above, and details are not repeated here.
[0131] The embodiments of the present application further provide a computer readable storage medium, which stores a computer program. When the computer program is run by a processor, the steps of the MCU initialization code generation method described above are executed. The storage medium can include ROM, RAM, magnetic disk or optical disk, etc. The storage medium can also include non-volatile memory or non-transitory memory, etc.
[0132] The embodiments of the present application further provide a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the MCU initialization code generation method described above are implemented.
[0133] The embodiment of the present application further provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program capable of running on the processor, and the processor runs the computer program to perform the steps of the initialization code generation method of the MCU. The electronic device includes but is not limited to a server, a computer, a tablet computer and the like.
[0134] It should be understood that, in the embodiment of the present application, the processor can be a central processing unit (CPU), and the processor can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0135] It should also be understood that the memory in the embodiments of the present application can be a volatile memory or a nonvolatile memory, or can include both volatile and nonvolatile memory. Among them, the nonvolatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM) or flash memory. The volatile memory can be random access memory (RAM) used as an external cache. By way of example, but not by way of limitation, many forms of random access memory (RAM) are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchlink dynamic random access memory (SLDRAM) and direct rambus random access memory (DR RAM).
[0136] The above embodiments can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer program can be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, the computer program can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired or wireless means.
[0137] In several embodiments provided in the present application, it should be understood that the disclosed methods, devices and systems can be implemented in other manners. For example, the described device embodiments are merely illustrative; the division of the units is merely logical function division; and there can be another division manner in actual implementation; for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. The units described as separated components can or can not be physical separated, and the components displayed as units can or can not be physical units; that is, they can be located in one place, or distributed to a plurality of network units. In actual implementation, a part or all of the units can be selected according to the actual needs to achieve the purposes of the embodiments.
[0138] In addition, each functional unit in the various embodiments of the present application can be integrated into one processing unit, or each unit can be a separate physical unit, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of hardware plus software function units. For example, for each device or product applied to or integrated into a chip, each module / unit contained therein can be implemented in the form of a circuit or other hardware, or at least part of the modules / units can be implemented in the form of a software program running on a processor integrated in the chip, and the remaining (if any) part of the modules / units can be implemented in the form of a circuit or other hardware; for each device or product applied to or integrated into a chip module, each module / unit contained therein can be implemented in the form of a circuit or other hardware, and different modules / units can be located in the same component (for example, a chip, a circuit module, etc.) or different components of the chip module, or at least part of the modules / units can be implemented in the form of a software program running on a processor integrated in the chip module, and the remaining (if any) part of the modules / units can be implemented in the form of a circuit or other hardware; for each device or product applied to or integrated into a terminal, each module / unit contained therein can be implemented in the form of a circuit or other hardware, and different modules / units can be located in the same component (for example, a chip, a circuit module, etc.) or different components of the terminal, or at least part of the modules / units can be implemented in the form of a software program running on a processor integrated in the terminal, and the remaining (if any) part of the modules / units can be implemented in the form of a circuit or other hardware.
[0139] It should be understood that the term "and / or" herein merely describes an associated relationship with the associated objects, and can represent three relationships, for example, A and / or B, which can represent three cases of A alone, A and B together, and B alone. In addition, the character " / " herein represents an "or" relationship between the front and rear associated objects.
[0140] The "multiple" appearing in the embodiments of the present application refers to two or more than two. The first, second, and the like appearing in the embodiments of the present application are only for illustrative and distinguishing purposes, and do not have order, nor represent a special limitation on the number of devices in the embodiments of the present application, and cannot constitute any limitation on the embodiments of the present application. Although the present application is disclosed as above, the present application is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present application, and therefore the protection scope of the present application should be subject to the range defined by the claims.
[0141] Although the present application is disclosed as above, the present application is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present application, and therefore the protection scope of the present application should be subject to the range defined by the claims.
Claims
1. A method of generating initialization code for an MCU, characterized by, The method comprises: obtaining initialization information set by a user, the initialization information comprising configuration information of a plurality of modules to be initialized, wherein each of the modules to be initialized has at least one configurable item, each of the configurable items has a plurality of optional items, and the configuration information comprises target items of the configurable items, the target items being selected from the plurality of optional items; reading a mapping relationship file, the mapping relationship file recording a mapping relationship set, the mapping relationship set comprising a first-level mapping relationship, a second-level mapping relationship and a third-level mapping relationship, wherein the first-level mapping relationship refers to a mapping relationship between the modules to be initialized and interfaces of configuration functions in a driver library of the MCU, the second-level mapping relationship refers to a mapping relationship between the configurable items and parameters of the configuration functions, and the third-level mapping relationship refers to a mapping relationship between the optional items and enumeration values of the parameters; determining, based on the mapping relationship file, code calling information of each of the modules to be initialized, the code calling information of each of the modules to be initialized comprising: an interface of a configuration function corresponding to the module to be initialized, parameters corresponding to the configurable items of the module to be initialized, and enumeration values corresponding to the target items of the configurable items; for each of the modules to be initialized, calling code of the configuration function corresponding to the module to be initialized based on the code calling information of the module to be initialized, to generate the initialization code.
2. The method of claim 1, wherein, The initialization information further comprises a model of the MCU, and the mapping relationship file records mapping relationship sets of a plurality of models of the MCU. Determining, based on the mapping relationship file, code calling information of each of the modules to be initialized comprises: determining, according to the model of the MCU, a target mapping relationship set in the mapping relationship file; and determining, based on the target mapping relationship set, the code calling information of each of the modules to be initialized of the MCU.
3. The method of claim 1, wherein, Before receiving the initialization information set by the user, the method further comprises: reading, from a driver library of the MCU, a header file corresponding to each of the modules to be initialized, the header file providing interfaces of the configuration functions, parameters of the configuration functions and an enumeration value list of the parameters; extracting the first-level mapping relationship according to the interfaces of the configuration functions and annotations of the interfaces; extracting the second-level mapping relationship according to the parameters of the configuration functions and annotations of each of the parameters; extracting the third-level mapping relationship according to the enumeration value list of the parameters and annotations of the enumeration value list.
4. The method of claim 1, wherein, Obtaining the initialization information set by the user comprises: determining graphical controls selected by the user in a configuration interface of each of the modules to be initialized, wherein the configuration interface of each of the modules to be initialized displays graphical controls of a plurality of optional items of each of the configurable items; determining the initialization information based on the selected graphical controls.
5. The method of claim 1, wherein, The mapping relationship file is an XML file.
6. The method of claim 1, wherein, The method further comprises: calling an engineering template; generating an IDE project according to the initialization code and the engineering template.
7. The method of claim 1, wherein, The method further comprises: receive a user input upper layer code to obtain the MCU code, the MCU code including the initialization code and the upper layer code; if the code protection function is enabled when the user updates the initialization information, shield the upper layer code and regenerate the initialization code.
8. An apparatus for generating initialization code of an MCU, characterized by The apparatus comprises: an initialization information receiving module configured to obtain initialization information set by a user, the initialization information including configuration information of a plurality of to-be-initialized modules, wherein each of the to-be-initialized modules has at least one configurable item, each of the configurable items has a plurality of selectable items, and the configuration information includes a target item of each of the configurable items, the target item being selected from the plurality of selectable items; a file reading module configured to read a mapping relationship file, the mapping relationship file recording a mapping relationship set, the mapping relationship set including a first-level mapping relationship, a second-level mapping relationship, and a third-level mapping relationship, wherein the first-level mapping relationship refers to a mapping relationship between the to-be-initialized modules and interfaces of configuration functions in a driver library of the MCU, the second-level mapping relationship refers to a mapping relationship between the configurable items and parameters of the configuration functions, and the third-level mapping relationship refers to a mapping relationship between the selectable items and enumeration values of the parameters; a mapping module configured to determine, based on the mapping relationship file, code calling information of each of the to-be-initialized modules, the code calling information of each of the to-be-initialized modules including an interface of a configuration function corresponding to the to-be-initialized module, parameters corresponding to the configurable items of the to-be-initialized module, and enumeration values corresponding to the target items of the configurable items; a calling module configured to, for each of the to-be-initialized modules, call code of a configuration function corresponding to the to-be-initialized module based on the code calling information of the to-be-initialized module to generate the initialization code.
9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is run by the processor, so that the MCU initialization code generation method of any one of claims 1 to 7 is executed.
10. A computer program product comprising a computer program, characterized in that, The computer program is run by the processor, so that the MCU initialization code generation method of any one of claims 1 to 7 is executed.
11. An electronic device comprising a memory and a processor, said memory having stored thereon a computer program operable to run on said processor, characterized in that, The computer program is run by the processor, so that the MCU initialization code generation method of any one of claims 1 to 7 is executed.
Citation Information
Patent Citations
SDK initialization method and system, electronic device and storage medium
CN110531985A
AUROSAR application layer architecture generation method and apparatus, and electronic device
CN117608529A