Micro-control unit virtual heap space allocation method based on external storage space

By allocating virtual heap blocks and initializing and requesting them in the external storage space of the microcontroller unit, the problem of insufficient memory in the MCU chip is solved, memory expansion and read/write speed are improved, and the service life of the external memory is extended.

CN121326784APending Publication Date: 2026-01-13QUECLINK WIRELESS SOLUTIONS(SHENZHEN) CO LTD
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411996763.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2026-01-13

AI Technical Summary

Technical Problem

In the existing technology, the on-chip SDRAM space of the microcontroller (MCU) chip is insufficient, which leads to increased memory requirements in the later stages of project development or product iteration and upgrade. Existing methods, such as replacing the MCU chip with a high-performance chip or adding an external SDRAM chip, are costly and waste I/O pin resources.

Method used

By attaching external storage space to the microcontroller unit, allocating several virtual heap blocks, and initializing and requesting the virtual heap space, the external storage space is used to expand memory. The data page mapping method is used to improve read and write speed and extend the life of external memory.

Benefits of technology

Without increasing costs or changing the storage structure, the memory space of the microcontroller unit was expanded, the data read and write speed was improved, and the number of erases of the external memory was reduced, thus extending its service life.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121326784A_ABST
    Figure CN121326784A_ABST
Patent Text Reader

Abstract

The invention discloses a micro-control unit virtual heap space allocation method based on an external storage space, the virtual heap space comprises a plurality of virtual heap blocks in the external storage space, and the size and the number of the virtual heap blocks are determined according to the size of the virtual heap space; the micro-control unit virtual heap space allocation method comprises the following steps: initializing a virtual heap space: initializing allocation information of a plurality of virtual heap blocks in an external storage space, so that the allocation information of the current virtual heap block points to an address of a next or previous available or used virtual heap block; and virtual heap space application: updating distribution information of the virtual heap blocks according to the number of the applied virtual heap blocks. According to the method, the external storage space of the micro-control unit is utilized, and the memory space of the micro-control unit is expanded on the basis of not increasing any cost and not changing the application and release mode of the space.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of chip memory control technology, and in particular to a method for allocating virtual heap space for microcontrollers based on external storage space. Background Technology

[0002] When developing projects using microcontrollers (MCUs), the on-chip SDRAM (synchronous dynamic random-access memory) and on-chip ROM (read-only memory) of the MCU chip are generally small. As the project progresses or the product is iterated and upgraded, the memory requirements increase significantly, causing the current SDRAM space to become insufficient for program needs. To meet these requirements, the most direct method in current technology is to replace the MCU chip with one that has more on-chip SDRAM. For example, the commonly used STM32 chip can support up to 1.4MB of RAM (random access memory), but this is only available on high-performance models, which are relatively expensive and may still not meet the requirements. Some low- to mid-range models typically only have tens to hundreds of kilobytes of RAM. Another common method in current technology is to use an external SDRAM chip. This method can effectively solve the memory shortage problem. However, SDRAM chips are still relatively expensive, and external SDRAM chips require more MCU pins, wasting valuable IO (input / output) pin resources. Therefore, in the actual development of projects, external SDRAM chips are not used unless absolutely necessary. Summary of the Invention

[0003] The technical problem to be solved by the present invention is to overcome the above-mentioned defects in the prior art and provide a method for allocating virtual heap space of microcontroller units based on external storage space.

[0004] The present invention solves the above-mentioned technical problems through the following technical solution:

[0005] This invention provides a method for allocating virtual heap space for a microcontroller unit based on external storage space. The virtual heap space includes several virtual heap blocks in the external storage space, and the size and number of the virtual heap blocks are determined according to the size of the virtual heap space. The method for allocating virtual heap space for the microcontroller unit includes:

[0006] Virtual heap space initialization: Initialize the allocation information of several virtual heap blocks in the external storage space so that the allocation information of the current virtual heap block points to the address of the next or previous available or used virtual heap block;

[0007] Virtual heap space allocation: Update the allocation information of the virtual heap blocks according to the number of virtual heap blocks requested.

[0008] Preferably, the external storage space includes a FLASH (flash memory) external to the microcontroller unit;

[0009] Prior to the virtual heap space initialization step, the microcontroller virtual heap space allocation method further includes:

[0010] Write address page mapping: Map the write address pages of the virtual heap space in the FLASH memory to selected pages in the internal memory of the microcontroller unit.

[0011] Preferably, the step of writing the address page mapping specifically includes:

[0012] Determine whether there is written data on a selected page of the microcontroller's internal memory;

[0013] If so, the data to be written is stored in the FLASH memory, and then the write address page of the virtual heap space in the FLASH memory is mapped to the selected page of the internal memory of the microcontroller unit.

[0014] Preferably, the virtual heap space initialization step further includes:

[0015] The addresses of the virtual heap blocks are determined based on the write address of the virtual heap space in the FLASH memory, the size and number of the virtual heap blocks.

[0016] Preferably, the allocation information includes the next used, the previous used, the next available, and the previous available; the virtual heap space initialization step specifically includes:

[0017] The "next used" allocation information of the first virtual heap block points to the address of the second virtual heap block;

[0018] The "previous used" allocation information of the first virtual heap block points to the address of the first virtual heap block;

[0019] The "next available" allocation information for the first virtual heap block points to the address of the second virtual heap block;

[0020] The "previous available" allocation information of the first virtual heap block points to the address of the second virtual heap block;

[0021] The "next used" allocation information for the second virtual heap block points to the address of the last virtual heap block;

[0022] The "previous used" allocation information of the last virtual heap block points to the address of the second virtual heap block.

[0023] Preferably, the virtual heap space allocation step includes:

[0024] The "next used" allocation information for the last virtual heap block requested points to the address of the last virtual heap block;

[0025] The "previous used" allocation information of the last virtual heap block requested points to the address of the second virtual heap block;

[0026] The "previous used" allocation information of the last virtual heap block points to the address of the last virtual heap block requested;

[0027] The "next used" allocation information for the second virtual heap block points to the address of the last virtual heap block requested.

[0028] The "next available" allocation information for the first virtual heap block points to the address of the last virtual heap block requested;

[0029] The "previous available" allocation information for the last virtual heap block requested points to the address of the first virtual heap block;

[0030] The "previous available" allocation information for the first virtual heap block points to the address of the last virtual heap block requested.

[0031] The "next available" allocation information for the last virtual heap block requested points to the address of the first virtual heap block.

[0032] The present invention also provides a virtual heap space allocation system for a microcontroller unit based on external storage space, wherein the virtual heap space includes a plurality of virtual heap blocks in the external storage space, and the size and number of the virtual heap blocks are determined according to the size of the virtual heap space; the microcontroller unit virtual heap space allocation system includes:

[0033] The virtual heap space initialization module is used to initialize the allocation information of several virtual heap blocks in the external storage space, so that the allocation information of the current virtual heap block points to the address of the next or previous available or used virtual heap block.

[0034] The virtual heap space allocation module is used to update the allocation information of the virtual heap blocks according to the number of virtual heap blocks requested.

[0035] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the virtual heap space allocation method for a microcontroller unit based on external storage space as described above.

[0036] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the virtual heap space allocation method for a microcontroller unit based on external storage space as described above.

[0037] The present invention also provides a computer-readable medium having computer instructions stored thereon, which, when executed by a processor, implement the virtual heap space allocation method for a microcontroller unit based on external storage space as described above.

[0038] The positive and progressive effects of this invention are as follows:

[0039] The present invention provides a method for allocating virtual heap space for microcontrollers based on external storage space. By allocating several virtual heap blocks in the external storage space attached to the microcontroller and performing virtual heap space initialization and virtual heap space allocation operations, the memory space of the microcontroller is expanded by utilizing the external storage space attached to the microcontroller without increasing any cost or changing the way space is allocated and released. Attached Figure Description

[0040] To more clearly illustrate the technical solutions of the embodiments in this specification, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are merely some examples or embodiments of this specification. For those skilled in the art, these drawings can be applied to other similar scenarios without creative effort. Unless obvious from the context or otherwise specified, the same reference numerals in the drawings represent the same structures or operations.

[0041] Figure 1 This is a schematic diagram of the storage method of a microcontroller in the prior art.

[0042] Figure 2 This is a schematic diagram of the memory configuration of the microcontroller in Embodiment 1 of the present invention.

[0043] Figure 3 This is a schematic diagram illustrating the division of the size and number of virtual heap blocks in Embodiment 1 of the present invention.

[0044] Figure 4 This is a flowchart illustrating the virtual heap space allocation method for microcontrollers based on external storage space in Embodiment 1 of the present invention.

[0045] Figure 5This is a schematic diagram showing the mapping of the write address page of the virtual heap space to the internal SDRAM in Embodiment 1 of the present invention.

[0046] Figures 6a-6c This is a schematic diagram illustrating the classification of virtual stack blocks in Embodiment 1 of the present invention.

[0047] Figure 7 This is a schematic diagram of the initialization of the virtual heap space in Embodiment 1 of the present invention.

[0048] Figure 8 This is a schematic diagram of applying for virtual heap space in Embodiment 1 of the present invention.

[0049] Figure 9 This is a schematic diagram of the structure of the virtual heap space allocation system for microcontrollers based on external storage space in Embodiment 2 of the present invention.

[0050] Figure 10 This is a schematic diagram of the electronic device in Embodiment 3 of the present invention. Detailed Implementation

[0051] The present invention will be further illustrated by way of embodiments below, but the present invention is not limited to the scope of the embodiments described herein.

[0052] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the document does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0053] It should be understood that the terms “device,” “system,” “unit,” and / or “module” used herein are one way to distinguish different components, elements, parts, sections, or assemblies at different levels. However, if other terms can achieve the same purpose, they may be replaced by other expressions.

[0054] As illustrated herein, unless the context clearly indicates otherwise, the words “a,” “an,” “an,” and / or “the” do not specifically refer to the singular and may also include the plural. Generally speaking, the terms “comprising” and “including” only indicate the inclusion of explicitly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements.

[0055] The definitions used herein, such as the terms “having,” “may have,” “comprising,” or “may include,” indicate the presence of the corresponding function, operation, element, etc., and do not limit the presence of one or more other functions, operations, elements, etc. Furthermore, it should be understood that the terms “comprising” or “having” as used herein indicate the presence of the features, figures, steps, operations, elements, components, or combinations thereof described in the specification, without excluding the presence or addition of one or more other features, figures, steps, operations, elements, components, or combinations thereof.

[0056] Flowcharts are used in this document to illustrate the operations performed by the system according to the embodiments herein. It should be understood that the preceding or following operations are not necessarily performed in exact order. Instead, the steps can be processed in reverse order or simultaneously. Furthermore, other operations can be added to these processes, or one or more steps can be removed from them.

[0057] Example 1

[0058] Please refer to Figure 1 This is a schematic diagram of the storage method of a microcontroller in the prior art, such as... Figure 1 As shown, the on-chip SDRAM and on-chip ROM of a microcontroller (MCU) chip are generally small in size. Considering cost and current needs, a common solution is to use on-chip SDRAM supplemented by a large-capacity external FLASH memory. This means that file storage requirements are met by using a large-capacity external FLASH memory. Please refer to [reference needed]. Figure 2 This is a schematic diagram of the microcontroller's memory configuration in this embodiment, as shown below. Figure 2 As shown, this embodiment overcomes many shortcomings of the prior art by using part of the external FLASH storage space as SDRAM, without increasing costs or changing the storage structure and usage, and expands the memory size of the MCU chip.

[0059] like Figure 3 As shown, the virtual heap space includes several virtual heap blocks in the external storage space. The size and number of the virtual heap blocks are determined according to the size of the virtual heap space. Specifically, a certain virtual memory size, such as vmem_size, can be used for the external FLASH storage space to create the virtual heap space. The block size of the virtual memory block is defined, for example, blck_size bytes. The virtual block size blck_size can be chosen as a reasonable value according to actual needs, such as 16 bytes. Then, the total number of virtual heap blocks vmem_blck is blck_nums = vmem_size / blck_size.

[0060] Please refer to Figure 4 This is a flowchart illustrating the microcontroller virtual heap space allocation method based on external storage space in this embodiment. The microcontroller virtual heap space allocation method includes:

[0061] S1. Virtual heap space initialization: Initialize the allocation information of several virtual heap blocks in the external storage space so that the allocation information of the current virtual heap block points to the address of the next or previous available or used virtual heap block.

[0062] S2, Virtual Heap Space Allocation: Updates the allocation information of virtual heap blocks based on the number of virtual heap blocks requested.

[0063] In one alternative implementation, the external storage space includes the FLASH memory attached to the microcontroller unit; FLASH memory is the most commonly attached memory to the microcontroller unit, but this method is not limited to FLASH memory, and other external memories attached to the microcontroller unit can also be adapted to achieve the purpose of this application based on this embodiment.

[0064] Prior to step S1, the microcontroller virtual heap space allocation method further includes:

[0065] S0. Write Address Page Mapping: Mapping the write address page of the virtual heap space in the FLASH memory to a selected page in the internal memory of the microcontroller unit. Specifically, after allocating a certain size of virtual heap space, it is usually necessary to frequently read and write data to this storage space. Reading data from the FLASH memory allows reading data of any size from any location without limit on the number of reads. However, writing data to the FLASH memory is relatively complex, requiring the entire page containing the write address to be erased before writing the data. Furthermore, the number of erases in the FLASH memory is limited; that is, writing data to the FLASH memory too frequently will affect its lifespan. On the other hand, reading and writing FLASH data is slower than reading and writing SDRAM data. Therefore, this embodiment introduces a data page mapping method to prevent repeated erasing and writing of the FLASH memory from adversely affecting its lifespan, and to improve the data read and write speed. Specifically, the entire virtual heap space can be mapped, in units of pages, to one or more pages of SDRAM, such as... Figure 5 As shown, when reading or writing data from the virtual heap space, if the page where the address is located has been mapped to page 1, 2, 3 or 4 of the internal SDRAM, then data can be read or written directly in the corresponding SDRAM page.

[0066] Specifically, step S0 includes:

[0067] S01. Determine whether there is written data on the selected page of the microcontroller's internal memory;

[0068] S02. If so, the write data is stored in the FLASH memory, and then the write address page of the virtual heap space in the FLASH memory is mapped to the selected page of the microcontroller's internal memory.

[0069] S03. If not, directly map the write address page of the virtual heap space in the FLASH memory to the selected page of the microcontroller's internal memory.

[0070] When the write address page of the virtual heap space has not yet been mapped to pages 1, 2, 3, or 4 of the internal SDRAM, mapping must be performed according to the page mapping order. For example, if a page such as page 3 is selected, it is first determined whether page 3 has been written to. If data has been written to it, the page is a "dirty" page, and the entire page of data on page 3 needs to be written back to the virtual heap space. Then, the page containing the read / write data address is mapped to page 3 of the internal SDRAM. Finally, data is read from page 3 of the internal SDRAM or written to page 3 of the internal SDRAM. Typically, the page size of the external FLASH is 4KB. In this embodiment, four pages are mapped to the internal SDRAM. If the virtual heap space is 8MB, then only 16KB of internal SDRAM can operate on the 8MB virtual heap space. Due to the use of the data page mapping method, on the one hand, reading and writing data is accelerated; on the other hand, only one FLASH page data needs to be erased during page swapping, which can effectively reduce the number of FLASH erases and extend the life of the FLASH.

[0071] In another alternative implementation, step S1 further includes:

[0072] S11. Determine the addresses of several virtual heap blocks based on the write address of the virtual heap space in the FLASH memory, the size and number of virtual heap blocks.

[0073] In this embodiment, the allocation information includes the next used, the previous used, the next available, and the previous available; specifically, the virtual heap blocks include three data types, such as... Figure 6a As shown, the first type is a data-type virtual heap block, such as... Figure 6b As shown, the second type is the managed virtual heap block, such as... Figure 6c As shown, the third type is the hybrid virtual heap block. Data-type virtual heap blocks contain entirely virtual heap data, similar to real heap data. Hybrid virtual heap blocks store both virtual heap allocation information and virtual heap data. Management-type virtual heap blocks store virtual heap allocation information, used for managing and reclaiming the virtual heap.

[0074] Step S1 specifically includes:

[0075] The "next used" allocation information of the first virtual heap block points to the address of the second virtual heap block;

[0076] The "previous used" allocation information of the first virtual heap block points to the address of the first virtual heap block;

[0077] The "next available" allocation information for the first virtual heap block points to the address of the second virtual heap block;

[0078] The "previous available" allocation information of the first virtual heap block points to the address of the second virtual heap block;

[0079] The "next used" allocation information for the second virtual heap block points to the address of the last virtual heap block;

[0080] The "previous used" allocation information of the last virtual heap block points to the address of the second virtual heap block.

[0081] The following example further illustrates how to initialize the virtual heap space. For example... Figure 7 As shown, the arrow direction indicates "the current virtual block points to the next or previous available or existing virtual block". The default pointer of all virtual blocks is vmem_blck_0. The initialization steps are as follows.

[0082] ① The "next used" pointer of vmem_blck_0 points to vmem_blck_1, that is... Figure 7 As shown by arrow 1;

[0083] ② The "previous used" pointer of vmem_blck_0 points to vmem_blck_0, that is... Figure 7 As shown by arrow 2;

[0084] ③ The "next available" pointer of vmem_blck_0 points to vmem_blck_1, that is... Figure 7 As shown by arrow 3;

[0085] ④ The "previous available" value of vmem_blck_0 points to vmem_blck_1, that is... Figure 7 As shown by arrow 4;

[0086] ⑤ The "next used" pointer of vmem_blck_1 points to vmem_blck_N-1, that is... Figure 7 As shown by arrow 5;

[0087] ⑥ The "previous used" value of vmem_blck_N-1 points to vmem_blck_1, that is... Figure 7 As shown by arrow 6.

[0088] Starting with vmem_blck_0, the "next available" for vmem_blck_0 is vmem_blck_1, that is... Figure 7 Arrow 3; the "next used" for vmem_blck_1 is vmem_blck_N-1, that is... Figure 7 Arrow 5.

[0089] Therefore, the total number of available virtual heap blocks can be calculated as (vmem_blck_N-1-1) = vmem_blck_N-2. That is, after the virtual heap space is initialized, the total available heap space is vmem_blck_N-2 virtual heap blocks.

[0090] Step S2 specifically includes:

[0091] The "next used" allocation information for the last virtual heap block requested points to the address of the last virtual heap block;

[0092] The "previous used" allocation information of the last virtual heap block requested points to the address of the second virtual heap block;

[0093] The "previous used" allocation information of the last virtual heap block points to the address of the last virtual heap block requested;

[0094] The "next used" allocation information for the second virtual heap block points to the address of the last virtual heap block requested.

[0095] The "next available" allocation information for the first virtual heap block points to the address of the last virtual heap block requested;

[0096] The "previous available" allocation information for the last virtual heap block requested points to the address of the first virtual heap block;

[0097] The "previous available" allocation information for the first virtual heap block points to the address of the last virtual heap block requested.

[0098] The "next available" allocation information for the last virtual heap block requested points to the address of the first virtual heap block.

[0099] The following example further illustrates how to allocate a certain size of virtual heap space. For example... Figure 8 As shown, for example, to allocate 33 virtual heap spaces, the main steps are as follows:

[0100] ① The "next used" pointer of vmem_blck_34 points to vmem_blck_N-1, that is... Figure 8 As shown by arrow 1;

[0101] ② The "previous used" field of vmem_blck_34 points to vmem_blck_1, that is... Figure 8 As shown by arrow 2;

[0102] ③ The "previous used" pointer of vmem_blck_N-1 points to mem_blck_34, that is... Figure 8 As shown by arrow 3;

[0103] ④ The "next used" pointer of mem_blck_1 points to mem_blck_34, that is... Figure 8 As shown by arrow 4;

[0104] ⑤mem_blck_0 “ Next available " Pointing to mem_blck_34, that is Figure 8 Arrow 5 Show;

[0105] ⑥ The "previous available" value of mem_blck_34 points to mem_blck_0, that is... Figure 8 As shown by arrow 6;

[0106] ⑦ The "previous available" value of mem_blck_0 points to mem_blck_34, that is... Figure 8 As shown by arrow 7;

[0107] ⑧ The "next available" pointer of vmem_blck_34 points to mem_blck_0, that is... Figure 8 As shown by arrow 8.

[0108] Finally, the virtual heap space address that was requested is the virtual heap address space pointed to by 9.

[0109] The present invention provides a method for allocating virtual heap space for microcontrollers based on external storage space. By allocating several virtual heap blocks in the external storage space attached to the microcontroller and performing virtual heap space initialization and allocation operations, the method expands the memory space of the microcontroller using the external storage space attached to the microcontroller without increasing any cost or changing the way space is allocated and released. The data reading and writing of the virtual heap space uses a data page mapping method, which speeds up the reading and writing of data on the one hand, and on the other hand, only one FLASH page data needs to be erased when page swapping, which can effectively reduce the number of FLASH erases and extend the life of FLASH.

[0110] Example 2

[0111] Please refer to Figure 9 This is a schematic diagram of a microcontroller virtual heap space allocation system based on external storage space in this embodiment. Specifically, as shown... Figure 9As shown, the virtual heap space includes several virtual heap blocks in the external storage space, and the size and number of the virtual heap blocks are determined according to the size of the virtual heap space; the microcontroller virtual heap space allocation system includes:

[0112] Virtual heap space initialization module 1 is used to initialize the allocation information of several virtual heap blocks in the external storage space, so that the allocation information of the current virtual heap block points to the address of the next or previous available or used virtual heap block.

[0113] Virtual heap space allocation module 2 is used to update the allocation information of the virtual heap blocks according to the number of virtual heap blocks requested.

[0114] For the system embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The system embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separate, and the modules shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this disclosure according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0115] Example 3

[0116] Figure 10 This is a schematic diagram of an electronic device according to Embodiment 3 of the present invention. The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the method of Embodiment 1. Figure 10 The electronic device 30 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.

[0117] like Figure 10 As shown, the electronic device 30 can be manifested as a general-purpose computing device, such as a server device. The components of the electronic device 30 may include, but are not limited to: at least one processor 31, at least one memory 32, and a bus 33 connecting different system components (including memory 32 and processor 31).

[0118] Bus 33 includes a data bus, an address bus, and a control bus.

[0119] The memory 32 may include volatile memory, such as random access memory (RAM) 321 and / or cache memory 322, and may further include read-only memory (ROM) 323.

[0120] The memory 32 may also include a program / utility 325 having a set (at least one) of program modules 324, including but not limited to: an operating system, one or more application programs, other program modules, and program data, each or some combination of these examples may include an implementation of a network environment.

[0121] The processor 31 executes various functional applications and data processing, such as the method of Embodiment 1 of the present invention, by running computer programs stored in the memory 32.

[0122] Electronic device 30 can also communicate with one or more external devices 34 (e.g., keyboard, pointing device, etc.). This communication can be performed via input / output (I / O) interface 35. Furthermore, the model-generated device 30 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public network, such as the Internet) via network adapter 36. As shown, network adapter 36 communicates with other modules of the model-generated device 30 via bus 33. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the model-generated device 30, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems.

[0123] It should be noted that although several units / modules or sub-units / modules of the electronic device have been mentioned in the detailed description above, this division is merely exemplary and not mandatory. In fact, according to embodiments of the present invention, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided and embodied by multiple units / modules.

[0124] Example 4

[0125] This embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method of Embodiment 1.

[0126] The readable storage medium may be more specifically adopted, including but not limited to: portable disk, hard disk, random access memory, read-only memory, erasable programmable read-only memory, optical storage device, magnetic storage device, or any suitable combination thereof.

[0127] In a possible implementation, the present invention can also be implemented as a program product comprising program code, which, when the program product is run on a terminal device, is used to cause the terminal device to execute the method of embodiment 1.

[0128] The program code for executing the present invention can be written in any combination of one or more programming languages. The program code can be executed entirely on the user device, partially on the user device, as a standalone software package, partially on the user device and partially on a remote device, or entirely on a remote device.

[0129] While specific embodiments of the present invention have been described above, those skilled in the art should understand that these are merely illustrative examples, and the scope of protection of the present invention is defined by the appended claims. Those skilled in the art can make various changes or modifications to these embodiments without departing from the principles and essence of the present invention, but all such changes and modifications fall within the scope of protection of the present invention.

Claims

1. A method for allocating virtual heap space for a microcontroller unit based on external storage space, characterized in that, The virtual heap space includes several virtual heap blocks in the external storage space, and the size and number of the virtual heap blocks are determined according to the size of the virtual heap space; the microcontroller virtual heap space allocation method includes: Virtual heap space initialization: Initialize the allocation information of several virtual heap blocks in the external storage space so that the allocation information of the current virtual heap block points to the address of the next or previous available or used virtual heap block; Virtual heap space allocation: Update the allocation information of the virtual heap blocks according to the number of virtual heap blocks requested.

2. The method for allocating virtual heap space for a microcontroller unit based on external storage space as described in claim 1, characterized in that, The external storage space includes the FLASH memory attached to the microcontroller unit; Prior to the virtual heap space initialization step, the microcontroller virtual heap space allocation method further includes: Write address page mapping: Map the write address pages of the virtual heap space in the FLASH memory to selected pages in the internal memory of the microcontroller unit.

3. The method for allocating virtual heap space for a microcontroller unit based on external storage space as described in claim 2, characterized in that, The steps of writing the address page mapping specifically include: Determine whether there is written data on a selected page of the microcontroller's internal memory; If so, the data to be written is stored in the FLASH memory, and then the write address page of the virtual heap space in the FLASH memory is mapped to the selected page of the internal memory of the microcontroller unit.

4. The method for allocating virtual heap space for a microcontroller unit based on external storage space as described in claim 2, characterized in that, The virtual heap space initialization step also includes: The addresses of the virtual heap blocks are determined based on the write address of the virtual heap space in the FLASH memory, the size and number of the virtual heap blocks.

5. The method for allocating virtual heap space for a microcontroller unit based on external storage space as described in claim 1, characterized in that, The allocation information includes the next used, the previous used, the next available, and the previous available; the virtual heap space initialization steps specifically include: The "next used" allocation information of the first virtual heap block points to the address of the second virtual heap block; The "previous used" allocation information of the first virtual heap block points to the address of the first virtual heap block; The "next available" allocation information for the first virtual heap block points to the address of the second virtual heap block; The "previous available" allocation information of the first virtual heap block points to the address of the second virtual heap block; The "next used" allocation information for the second virtual heap block points to the address of the last virtual heap block; The "previous used" allocation information of the last virtual heap block points to the address of the second virtual heap block.

6. The method for allocating virtual heap space for a microcontroller unit based on external storage space as described in claim 1, characterized in that, The steps for allocating virtual heap space include: The "next used" allocation information for the last virtual heap block requested points to the address of the last virtual heap block; The "previous used" allocation information of the last virtual heap block requested points to the address of the second virtual heap block; The "previous used" allocation information of the last virtual heap block points to the address of the last virtual heap block requested; The "next used" allocation information for the second virtual heap block points to the address of the last virtual heap block requested. The "next available" allocation information for the first virtual heap block points to the address of the last virtual heap block requested; The "previous available" allocation information for the last virtual heap block requested points to the address of the first virtual heap block; The "previous available" allocation information for the first virtual heap block points to the address of the last virtual heap block requested. The "next available" allocation information for the last virtual heap block requested points to the address of the first virtual heap block.

7. A virtual heap space allocation system for a microcontroller unit based on external storage space, characterized in that, The virtual heap space includes several virtual heap blocks in the external storage space, and the size and number of the virtual heap blocks are determined according to the size of the virtual heap space; the microcontroller virtual heap space allocation system includes: The virtual heap space initialization module is used to initialize the allocation information of several virtual heap blocks in the external storage space, so that the allocation information of the current virtual heap block points to the address of the next or previous available or used virtual heap block. The virtual heap space allocation module is used to update the allocation information of the virtual heap blocks according to the number of virtual heap blocks requested.

8. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the virtual heap space allocation method for a microcontroller unit based on external storage space as described in any one of claims 1 to 6.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes a computer program, it implements the virtual heap space allocation method for microcontrollers based on external storage space as described in any one of claims 1 to 6.

10. A computer-readable medium having computer instructions stored thereon, characterized in that, The computer instructions, when executed by the processor, implement the virtual heap space allocation method for microcontrollers based on external storage space as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Middleware memory management scheme

    CN102455976A

  • Highly-concurrent real-time memory resource management and scheduling method

    CN102567107A

  • Data caching in non-volatile memory

    CN102576333A

  • Data cache method used in NAND FLASH

    CN105930282A

  • Memory management method and system

    CN106681829A