RAM capacity expansion method, terminal and computer readable storage medium
By using external SPI Flash in embedded systems to expand RAM, the problem of insufficient RAM space is solved, cost is reduced, and effective storage of CAN bus data is achieved.
Patent Information
- Application Number
- CN202411526875.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-14
AI Technical Summary
In embedded systems, the commonly used chip RAM space is small, which is difficult to meet the scenario needs of saving a large amount of real-time data, and the cost of expanding larger RAM is higher.
The capacity expansion of RAM is achieved by using external SPI Flash, and by storing CAN bus data in time-sharing in FLASH, and establishing sector-corruption tables when necessary to skip the bad sectors.
It reduces the cost of RAM expansion, meets some data storage needs, and avoids performance bottlenecks caused by slow Flash writing speed.
Smart Images

Figure CN119441075A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a RAM expansion method and terminal, and a computer-readable storage medium. Background Art
[0002] In the field of embedded systems, for commonly used microcontrollers, MCUs, DSPs and other chips, whether they are 8-bit, 16-bit or 32-bit, the available RAM is relatively small. For actual scenarios, special consideration needs to be given to how to maximize the use of RAM space. For scenarios that need to save a large amount of real-time data, only a dozen KB of RAM may not meet the needs of specific projects no matter how the data structure is optimized. At this time, it is necessary to consider how to solve this problem.
[0003] Regarding the problem of insufficient RAM space, projects with long delivery periods and ample money may consider replacing the chip directly. However, for most projects, expanding with a larger RAM may be a better option. Both solutions have disadvantages, the most important of which is that they will significantly increase costs. Summary of the invention
[0004] The object of the present invention is to provide a RAM capacity expansion method and terminal, and a computer-readable storage medium to reduce the cost of capacity expansion.
[0005] To achieve this object, the present invention adopts the following technical solutions: A RAM expansion method, the expansion method comprising: Provide FLASH for expanding the current RAM capacity; Determine the starting address of the normal sector in the FLASH, and store the CAN bus data to be transferred into the FLASH in a time-sharing manner starting from the starting address.
[0006] Optionally, the capacity expansion method further includes: establishing a sector damage table in the FLASH, the sector damage table being used to store information related to bad sectors in the FLASH; and determining a starting address of a normal sector in the FLASH according to the sector damage table.
[0007] Optionally, the capacity expansion method further includes: in the process of storing the CAN bus data in the FLASH in a time-sharing manner, if a new bad sector is identified, updating the sector damage table in real time accordingly.
[0008] Optionally, the sector damage table is stored in the starting sector of the FLASH.
[0009] Optionally, the storing the CAN bus data in the FLASH in a time-sharing manner starting from the start address includes: For each CAN bus data to be written, the writing operation is divided into five steps in sequence: writing FLASH successfully, reading sectors, data replacement, erasing sectors and writing sectors.
[0010] Optionally, in the five steps of writing FLASH successfully, reading sectors, replacing data, erasing sectors and writing sectors, the operation duration of each step is within 0.5s.
[0011] A terminal comprises a memory and a processor; The memory is used to store instructions; The processor is used to execute the instructions in the memory to implement any of the RAM expansion methods described above.
[0012] A computer-readable storage medium includes instructions, which, when executed on a computer, enables the computer to execute any one of the above-mentioned RAM expansion methods.
[0013] Compared with the prior art, the present invention has the following beneficial effects: The embodiment of the present invention uses an external SPI Flash to expand the RAM. For the SPI Flash, only four IO port resources need to be used. At the same time, the SPI bus speed can also be about 40Mhz to fully meet the needs of sharing the RAM to undertake the CAN bus data. Although the writing speed of the Flash is relatively slow and takes about 50ms, the demand can also be met through the step-by-step writing operation. Therefore, for some temporary storage of large amounts of data and the data generation speed is not particularly fast, this solution can be used to undertake part of the work of the RAM and reduce the cost increase. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0015] Figure 1 A design flow chart for transferring RAM data to Flash provided in an embodiment of the present invention.
[0016] Figure 2 A design flow chart of Flash time-sharing writing provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0018] Although RAM is faster than Flash, it is generally smaller and more expensive. At the same time, RAM requires a lot of IO resources. Although Flash is low-cost, it has problems such as slow bus speed and time-consuming writing. However, in the automotive industry, all devices are mounted on the CAN bus, and the data exchange speed between devices depends on the speed of the CAN bus. At this time, the shortcomings of Flash can be ignored. At the same time, Flash uses fewer IO resources. In this way, external Flash may be a better choice for external RAM.
[0019] Based on this, this solution uses external Flash to solve the problem of insufficient RAM space. Although the external Flash solution is generally only used to store programs, for some scenarios where the data interaction speed is not particularly fast, external Flash has more cost advantages than external RAM, and can also improve the price advantage of corresponding products and enhance competitiveness. External Flash is a relatively good method. At the same time, for external RAM, since it uses more IO resources, there are fewer project scenarios that can be applied. Therefore, this solution uses external Flash to expand RAM is a relatively advantageous solution.
[0020] Combination Figure 1 and Figure 2 As shown, the core idea of the embodiment of the present invention is: when expansion is needed, a FLASH is provided for expanding the capacity of the current RAM; the starting address of the normal sector in the FLASH is determined, and the CAN bus data to be transferred is stored in the FLASH in a time-sharing manner starting from the starting address. Further, it can also include: establishing a sector damage table in the FLASH, the sector damage table is used to store the bad sector related information in the FLASH; and determining the starting address of the normal sector in the FLASH according to the sector damage table.
[0021] As the most common storage device in the embedded field, Flash has the advantages of simple use, large storage capacity, and low price. It is widely used in storing programs. It may be the first time to use external SPI Flash to expand RAM. The reason for considering this solution is mainly to save costs and reduce workload. For external RAM, RAM needs to use more IO port resources and is more complicated to use and more expensive. For some projects, it is not necessary to expand RAM. The same effect can be achieved by using external Flash. For SPI Flash, only 4 IO port resources are needed. At the same time, the SPI bus speed can be about 40Mhz to fully meet the needs of sharing RAM to undertake CAN bus data. Although the write speed of Flash is slow and takes about 50ms, the step-by-step write operation can also meet the needs. Therefore, for some cases where a large amount of data is temporarily stored and the data generation speed is not particularly fast, this solution can be used to undertake part of the RAM work, and it can reduce the cost increase, which has a better actual effect for the project.
[0022] The main difficulty of this design is to consider the maximum available RAM space and the data flow speed and Flash write time to ensure that data overwriting does not occur. The second difficulty is how to skip Flash bad blocks.
[0023] There are two reasons why Flash generates bad blocks. One is that the Flash chip will generate certain bad blocks due to production process problems when it leaves the factory. The other is that Flash generally only has 100,000 erase and write times, and bad blocks will be generated after use. How to skip this bad block? The processing method of this solution is as follows: Explain that for 8M Flash, the size of one erase and write is a sector of 4K, and 16 sectors are one block. For this project, the amount of data transferred from RAM to Flash at one time is less than 64K, so it is too wasteful to skip a bad block. Therefore, this time a table is established in the starting sector of Flash to save the starting position and size of the sector that cannot be written in Flash, and also save the starting address of the normal sector. When programming / erasing this sector, some bits cannot be pulled high, which will cause Page Program and BlockErase operation errors. When a sector is damaged, the sector damage table is maintained in time to ensure that the program can skip the damaged sector the next time it is powered on.
[0024] Since the writing speed of Flash is really slow, it takes about 50ms to write a sector of 4k data. In this way, it is necessary to consider the size of the receiving bus data stream and the available RAM size. For this project, the speed of the bus data stream is the CAN bus load rate. For the CAN bus with a baud rate of 500k and a bus load rate of 90%, the maximum bus data stream is 3 frames / ms. At the same time, the storage space occupied by one frame of CAN data is optimized to 16Byte. For the CAN bus, there are only 150 frames of data in 50ms, which fully meets the writing speed of Flash. Therefore, it is completely possible to use external Flash to expand RAM.
[0025] Secondly, it takes 50ms to write a sector to Flash. For projects with time constraints, it is not feasible to waste resources waiting for Flash writing to succeed. Therefore, the Flash writing operation needs to be processed step by step, and a writing operation is divided into 5 steps to ensure that each step can be completed within 0.5ms, thus avoiding wasting CPU resources. Figure 2 As shown, a complete write operation can be divided into five steps: write FLASH successfully, read sector, data replacement, erase sector and write sector.
[0026] This solution has been verified in this project. It is a feasible solution that reduces costs while ensuring project needs. It has strong reference and practicality for other projects.
[0027] In addition, an embodiment of the present invention further provides a terminal, which includes a memory and a processor. The memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the RAM expansion method provided in the embodiment of the present invention.
[0028] Based on the same concept, an embodiment of the present invention provides a computer-readable storage medium, in which at least one instruction is stored. The instruction is loaded and executed by a processor to implement the cleaning control method provided by the embodiment of the present invention.
[0029] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0030] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for expanding RAM, characterized in that: The capacity expansion method comprises: Provide FLASH for expanding the current RAM capacity; Determine the starting address of the normal sector in the FLASH, and store the CAN bus data to be transferred into the FLASH in a time-sharing manner starting from the starting address.
2. The RAM expansion method according to claim 1, characterized in that: The capacity expansion method further includes: establishing a sector damage table in the FLASH, the sector damage table being used to store bad sector related information in the FLASH; and determining a starting address of a normal sector in the FLASH according to the sector damage table.
3. The RAM expansion method according to claim 2, characterized in that: The capacity expansion method further comprises: in the process of storing the CAN bus data in the FLASH in a time-sharing manner, if a new bad sector is identified, updating the sector damage table in real time accordingly.
4. The RAM expansion method according to claim 2, characterized in that: The sector damage table is stored in the starting sector of the FLASH.
5. The RAM expansion method according to claim 1, characterized in that: The step of storing the CAN bus data in the FLASH in a time-sharing manner starting from the start address includes: For each CAN bus data to be written, the writing operation is divided into five steps in sequence: writing FLASH successfully, reading sectors, data replacement, erasing sectors and writing sectors.
6. The RAM expansion method according to claim 5, characterized in that: In the five steps of writing FLASH successfully, reading sectors, replacing data, erasing sectors and writing sectors, the operation time of each step is within 0.5s.
7. A terminal, characterized in that: including memory and processor; The memory is used to store instructions; The processor is used to execute the instructions in the memory to implement the RAM expansion method described in any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that: The method comprises instructions which, when executed on a computer, enable the computer to execute the RAM expansion method as described in any one of claims 1 to 6.