Method, device and medium for dynamic loading of mcu application

CN117215671BActive Publication Date: 2026-10-27TIANDI CHANGZHOU AUTOMATION +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202311206569.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-18
Publication Date
2026-10-27
Estimated Expiration
2043-09-18

AI Technical Summary

Technical Problem

[0005]本发明要解决的技术问题是:为了解决现有技术中MCU的应用程序动态加载方法存在存储资源浪费、实现效率低以及适用性低的技术问题,本发明提供一种基于MCU应用程序动态加载方法,所需存储资源少,且减少了APP代码尺寸,提高了MCU存储的空间利用率,避免了对于存在存储资源紧张的MCU,无法实现应用程序动态加载的问题,适用性高

Benefits of technology

[0040]本发明的有益效果是,本发明的一种基于MCU应用程序动态加载方法,构建App程序动态加载特性生成App二进制文件,减少了APP代码尺寸,便于APP程序的开发和维护,通过所述App程序调用所述内核主机服务函数,进一步提高了MCU存储的空间利用率,避免了对于存在存储资源紧张的MCU,无法实现应用程序动态加载的问题,适用性高。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117215671B_ABST
    Figure CN117215671B_ABST
Patent Text Reader

Abstract

The application relates to the field of embedded technology, in particular to a dynamic loading method, equipment and medium based on an MCU application program. The method comprises the following steps: constructing an App program dynamic loading characteristic, and generating an App binary file; dynamically loading the App binary file through a kernel host program, and executing the APP program; and calling a kernel host service function by the App program, and completing dynamic loading of the App program. The application provides a dynamic loading method based on an MCU application program, the required storage resource is small, the APP code size is reduced, the space utilization rate of MCU storage is improved, the problem that an MCU with a storage resource shortage cannot realize dynamic loading of an application program is avoided, and the applicability is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded technology, and in particular to a method, device and medium for dynamically loading MCU applications. Background Technology

[0002] With the development of artificial intelligence technology, microcontrollers (MCUs) are becoming increasingly important. A microcontroller is a gate circuit integrated circuit commonly used to control and manage electronic devices, and can be used to implement the complex functions of artificial intelligence (AI) systems.

[0003] Currently, the common method for loading applications in MCU development is to use a bootloader program to load the App. The bootloader reads the binary file of the new version of the App from the storage system, writes the binary file to a designated internal Flash space, and then jumps to the App's entry point to execute the App. In this method, after the bootloader jumps to the App, the MCU no longer executes the code in the flash space where the bootloader resides, resulting in wasted flash space. Furthermore, the App code contains both the operating system and the application, making it large in size. Even when only the application functionality is updated, both the operating system and the application still need to be loaded, leading to low efficiency.

[0004] With the development of embedded technology, a method for dynamically loading applications based on parsing ELF files will be implemented on MCUs with abundant storage resources. In this method, the kernel host program parses the ELF format App file in the storage system, moves the App code to RAM, redirects it, and then executes the App program. Since the App code executes in RAM, this method is only suitable for MPUs (Microprocessor Units) or MCUs with abundant storage resources. For MCUs with limited storage resources, dynamic application loading cannot be implemented, resulting in low applicability. Summary of the Invention

[0005] The technical problem to be solved by this invention is: in order to solve the technical problems of waste of storage resources, low implementation efficiency and low applicability of the existing MCU application dynamic loading method, this invention provides an MCU application dynamic loading method that requires less storage resources, reduces the size of APP code, improves the space utilization of MCU storage, avoids the problem that the application dynamic loading cannot be implemented for MCUs with tight storage resources, and has high applicability.

[0006] The technical solution adopted by this invention to solve its technical problem is: a method for dynamically loading MCU applications, the method comprising:

[0007] Build the dynamic loading feature of the App program and generate the App binary file;

[0008] The App binary file is dynamically loaded and the App program is executed via the kernel host program.

[0009] The App program calls the kernel host service function to complete the dynamic loading of the App program.

[0010] Furthermore, specifically, building the dynamic loading feature of an app includes the following steps:

[0011] S11 enables the read-only data location-independent and read-write data location-independent features of the App code compiler;

[0012] S12 enables the read-only section location independence and read-write section location independence features of the App code linker;

[0013] S13, Remove the OS kernel component code, protocol stack component code, and C library component code from the App program;

[0014] S14, redefine the C library initialization function. The redefined C library initialization function only executes the instruction to jump to the main function.

[0015] S15, Define the entry function of the App program. The entry function is used to first execute the data loading operation of the App program, and then execute the C library initialization function defined in step S14.

[0016] S16, Set the App entry function defined in step S15 as the App code entry point;

[0017] S17, add the leading information of the App binary file. The leading information includes the App code length, the App read / write data area length, and the App code entry function.

[0018] S18, Place the leading information of the App binary file from step S17 at the beginning of the execution region;

[0019] S19 enables the compiler's ARM / Thumb code interconnect support feature, generating new App binaries.

[0020] Furthermore, specifically, in step S11, the App code compiler includes a C language compiler and an assembly language compiler.

[0021] Furthermore, specifically, dynamically loading the App binary file through the kernel host program includes the following steps:

[0022] S21, Start the MCU and run the kernel host program, which retrieves the App binary file from the external storage system;

[0023] S22, parse the App binary file to obtain the leading information of the App binary file;

[0024] S23, based on the leading information of the App binary file, write the content of the App binary file into the corresponding flash space inside the MCU;

[0025] S24, allocate dynamic memory space based on the leading information of the App binary file, wherein the dynamic memory space is the read and write data area of ​​the App program;

[0026] S25, assign the starting address of the requested dynamic memory space to the R9 register of the MCU;

[0027] S26, Execute the App program based on the App entry function information;

[0028] During the execution of the App program, instruction information is read from the internal Flash space of the MCU in step S23. The read and write data used during the execution of the App program are stored in the memory space allocated in step S24, and the data is accessed through the R9 register value set in step S25.

[0029] Furthermore, specifically, in step S24, dynamic memory space is requested by calling the malloc function.

[0030] Furthermore, specifically, the process of the App program calling the kernel host service function includes the following steps:

[0031] S31, The App program defines an SVC exception call function, which includes at least one input parameter, the input parameter being the service function request number, and the return value type being an integer.

[0032] S32, the kernel host program defines a service function table, which is represented as an array. The array index is set with the request number of the service function, and each array index corresponds one-to-one with the request number of the service function.

[0033] S33, An SVC interrupt service function is added to the kernel host program, and the SVC interrupt service function returns the address of the corresponding service function according to the service function request number;

[0034] S34, the App program calls the kernel host service function through the service function address returned by the SVC exception call function.

[0035] A computer device, including

[0036] processor;

[0037] Memory, used to store executable instructions;

[0038] The processor is used to read the executable instructions from the memory and execute the executable instructions to implement the MCU application dynamic loading method described above.

[0039] A computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement the MCU application dynamic loading method described above.

[0040] The beneficial effects of this invention are that the method for dynamically loading MCU applications generates App binary files by constructing the dynamic loading feature of App programs, which reduces the size of App code, facilitates the development and maintenance of App programs, and further improves the space utilization of MCU storage by having the App program call the kernel host service function. This avoids the problem that dynamic loading of applications cannot be achieved for MCUs with limited storage resources, and has high applicability. Attached Figure Description

[0041] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0042] Figure 1 This is a schematic diagram of the method flow of Embodiment 1 of the present invention.

[0043] Figure 2 This is a schematic diagram of the computer device structure according to Embodiment 2 of the present invention.

[0044] In the diagram, 10 is a computer device; 1002 is a processor; 1004 is a memory; and 1006 is a transmission device. Detailed Implementation

[0045] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0046] Example 1

[0047] This application provides a method for dynamically loading MCU applications, such as... Figure 1 As shown, the method includes:

[0048] S1, build the dynamic loading feature of the App program and generate the App binary file;

[0049] S2 dynamically loads the App binary file through the kernel host program and executes the App program.

[0050] S3, the App program calls the kernel host service function to complete the dynamic loading of the App program.

[0051] In this embodiment, building the dynamic loading feature of the App program includes the following steps:

[0052] S11 enables the read-only data location independence and read-write data location independence features of the App code compiler; the App code compiler includes a C language compiler and an assembly language compiler.

[0053] S12 enables the read-only section location independence and read-write section location independence features of the App code linker; through steps S11 and S12, the code address and read / write data address required during the operation of the App program can be dynamically specified by the kernel host program, so as to realize the dynamic loading of the App by the kernel host program.

[0054] S13 removes OS kernel component code, protocol stack component code, and C library component code from the App program, reducing the size of the subsequently generated App binary file and improving the development and maintenance efficiency of the App program.

[0055] S14, redefine the C library initialization function. The redefined C library initialization function only executes the instruction to jump to the main function.

[0056] S15, define the entry function of the App program. The entry function is used to first execute the App program's data loading operation, and then execute the C library initialization function defined in step S14.

[0057] S16, Set the App entry function defined in step S15 as the App code entry point;

[0058] S17, Add the leading information of the App binary file. The leading information includes the App code length, the App read / write data area length, and the App code entry function.

[0059] S18, Place the leading information of the App binary file from step S17 at the beginning of the execution area;

[0060] S19 enables the compiler's ARM / Thumb code interconnect support feature, generating new App binaries.

[0061] In this embodiment, dynamically loading the App binary file through the kernel host program includes the following steps:

[0062] S21, start the MCU and run the kernel host program, which obtains the App binary file from the external storage system; the external storage system is an external flash or SD card, but is not limited to this.

[0063] S22, parse the App binary file and obtain the leading information of the App binary file;

[0064] S23, based on the leading information of the App binary file, write the contents of the App binary file into the corresponding flash space inside the MCU;

[0065] S24. Based on the leading information of the App binary file, allocate dynamic memory space. The dynamic memory space is the read and write data area of ​​the App program. Further, allocate dynamic memory space by calling the malloc function.

[0066] S25, assign the starting address of the dynamically allocated memory space to the MCU's R9 register;

[0067] S26, Execute the App program based on the App entry function information;

[0068] In this embodiment, during the execution of the App program, instruction information is read from the internal Flash space of the MCU in step S23. The read and write data used by the App program during execution are stored in the memory space allocated in step S24, and the data is accessed through the R9 register value set in step S25. That is, the running address of the App program can be specified by the kernel host program as any address in the internal Flash space of the MCU. Compared to the prior art where the App program only runs at a fixed address, in this embodiment, the execution of the App program is address-independent, which is beneficial for the independent maintenance of the kernel host program and the App program, and improves compatibility.

[0069] In this embodiment, the App program calling the kernel host service function includes the following steps:

[0070] S31, the App program defines an SVC exception call function. The SVC exception call function must contain at least one input parameter, which is the service function request number. The return value type is integer. The service function request number is 0, 1, 2, ..., 255.

[0071] S32, the kernel host program defines a service function table, which is represented as an array. The array index is set with the request number of the service function, and each array index corresponds one-to-one with the request number of the service function.

[0072] S33, add an SVC interrupt service function to the kernel host program. The SVC interrupt service function returns the address of the corresponding service function according to the service function request number.

[0073] S34, the App program calls the kernel host service function through the service function address returned by the SVC exception call function.

[0074] It should be noted that in existing technologies, the App program contains kernel service function addresses, which the App program can directly access to call the kernel service functions. This application, in order to improve the space utilization of MCU memory, removes the OS kernel component code from the App program; that is, the App program does not contain kernel service function addresses. The kernel service function addresses (function pointers) are obtained through the steps described above, ensuring that the App program calls the kernel host service functions, completing the dynamic loading of the App program. Furthermore, by calling the kernel host service functions through the SVC exception call function, the code of the kernel host program is effectively utilized, thus improving the MCU memory utilization.

[0075] In summary, the present invention provides a method for dynamically loading MCU applications, which generates App binary files by constructing the dynamic loading feature of App programs, reduces the size of App code, facilitates the development and maintenance of App programs, and further improves the space utilization of MCU storage by having the App program call the kernel host service function. This avoids the problem of not being able to achieve dynamic loading of applications for MCUs with limited storage resources, and has high applicability.

[0076] Example 2

[0077] This application provides a computer device including a processor and a memory. The memory stores at least one instruction or at least one program, which is loaded and executed by the processor to implement a dynamic loading method for MCU applications as provided in the above method embodiments.

[0078] Figure 2 This diagram illustrates a hardware structure of a device for implementing a dynamic loading method for MCU applications provided in the embodiments of this application. The device can participate in or include the apparatus or system provided in the embodiments of this application. Figure 2 As shown, the computer device 10 may include one or more processors 1002 (the processor may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 1004 for storing data, and a transmission device 1006 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 2The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer device 10 may also include... Figure 2 The more or fewer components shown, or having the same Figure 2 The different configurations shown.

[0079] It should be noted that the aforementioned one or more processors and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuit may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer device 10 (or mobile device). As involved in the embodiments of this application, the data processing circuit serves as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).

[0080] The memory 1004 can be used to store software programs and modules for application software, such as the program instruction / data storage device corresponding to the MCU application dynamic loading method in this embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 1004, thereby implementing the aforementioned method. The memory 1004 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1004 may further include memory remotely located relative to the processor, and these remote memories can be connected to the computer device 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0081] The transmission device 1006 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer device 10. In one example, the transmission device 1006 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 1006 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.

[0082] The display may be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer device 10 (or mobile device).

[0083] Example 3

[0084] This application embodiment also provides a computer-readable storage medium, which can be disposed in a server to store at least one instruction or at least one program related to implementing a dynamic loading method for MCU applications in the method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the dynamic loading method for MCU applications provided in the above method embodiment.

[0085] Optionally, in this embodiment, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0086] Example 4

[0087] This invention also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform a dynamic loading method for MCU applications provided in the various optional embodiments described above.

[0088] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, the above description focuses on specific embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired results. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired results. In some implementations, multitasking and parallel processing are also possible or may be advantageous.

[0089] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device, equipment, and storage medium embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0090] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0091] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.

Claims

1. A method for dynamically loading MCU applications, characterized in that, The method includes: To build the dynamic loading feature of an app, generate the app binary file. Building the dynamic loading feature of an app includes the following steps: S11 enables the read-only data location-independent and read-write data location-independent features of the App code compiler; S12 enables the read-only section location independence and read-write section location independence features of the App code linker; S13, Remove the OS kernel component code, protocol stack component code, and C library component code from the App program; S14, redefine the C library initialization function. The redefined C library initialization function only executes the instruction to jump to the main function. S15, Define the entry function of the App program. The entry function is used to first execute the data loading operation of the App program, and then execute the C library initialization function defined in step S14. S16, Set the App entry function defined in step S15 as the App code entry point; S17, add the leading information of the App binary file. The leading information includes the App code length, the App read / write data area length, and the App code entry function. S18, Place the leading information of the App binary file from step S17 at the beginning of the execution region; S19 enables the compiler's ARM / Thumb code interconnection support feature, generating new App binaries; The App binary file is dynamically loaded and the App program is executed via the kernel host program. The App program calls the kernel host service function to complete the dynamic loading of the App program; the App program calling the kernel host service function includes the following steps: S31, The App program defines an SVC exception call function, which includes at least one input parameter, the input parameter being the service function request number, and the return value type being an integer. S32, the kernel host program defines a service function table, which is represented as an array. The array index is set with the request number of the service function, and each array index corresponds one-to-one with the request number of the service function. S33, An SVC interrupt service function is added to the kernel host program, and the SVC interrupt service function returns the address of the corresponding service function according to the service function request number; S34, the App program calls the kernel host service function through the service function address returned by the SVC exception call function.

2. The method for dynamically loading MCU applications as described in claim 1, characterized in that, In step S11, the App code compiler includes a C language compiler and an assembly language compiler.

3. The method for dynamically loading MCU applications as described in claim 1, characterized in that, Dynamically loading the App binary file via the kernel host program includes the following steps: S21, Start the MCU and run the kernel host program, which retrieves the App binary file from the external storage system; S22, parse the App binary file to obtain the leading information of the App binary file; S23, based on the leading information of the App binary file, write the content of the App binary file into the corresponding flash space inside the MCU; S24, allocate dynamic memory space based on the leading information of the App binary file, wherein the dynamic memory space is the read and write data area of ​​the App program; S25, assign the starting address of the requested dynamic memory space to the R9 register of the MCU; S26, Execute the App program based on the App entry function information; During the execution of the App program, instruction information is read from the internal Flash space of the MCU in step S23. The read and write data used during the execution of the App program are stored in the memory space allocated in step S24, and the data is accessed through the R9 register value set in step S25.

4. The method for dynamically loading MCU applications as described in claim 3, characterized in that, In step S24, dynamic memory space is allocated by calling the malloc function.

5. A computer device, characterized in that, include processor; Memory, used to store executable instructions; The processor is configured to read the executable instructions from the memory and execute the executable instructions to implement the MCU application dynamic loading method as described in any one of claims 1 to 4.

6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to implement the MCU application dynamic loading method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Method for dynamic loading in embedded system of mobile phone

    CN101668283A

  • Wearable device system function call method and wearable device

    CN105138360A

  • Program dynamic loading method, program dynamic loading device and storage medium

    CN111124550A