A dual MRAM MCU and a method for caching data

By adopting a dual MRAM structure in the MCU and information backup and priority allocation in different operating modes, the problem of data loss caused by the volatility of SRAM is solved, and system stability and exception handling efficiency are improved.

CN113986131BActive Publication Date: 2024-09-27青岛海存微电子有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111255005.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-27
Publication Date
2024-09-27
Estimated Expiration
2041-10-27

AI Technical Summary

Technical Problem

The SRAM used by conventional MCUs is volatile memory, which results in data loss when problems such as null pointer reading and writing, memory leaks, and stack overflows occur, affecting troubleshooting and system stability.

Method used

An MCU with a dual MRAM structure connects two non-volatile memories to the system bus, which are used to store processor information and operating logs respectively, and perform information backup and priority allocation in different operating modes to avoid unbalanced writes. Input and storage overflow to achieve mutual data backup.

Benefits of technology

It improves the stability and exception handling efficiency of the MCU system and ensures the accurate positioning and security of data in abnormal situations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113986131B
    Figure CN113986131B
Patent Text Reader

Abstract

The present application discloses an MCU with dual MRAM type memory and a method for caching data, and relates to the field of dual MRAM type memory MCU. In the first aspect of the present application, a dual MRAM type cache MCU is proposed, the MCU includes: a processor, an AHB, a memory, an APB, and an AHB to APB bridge, the processor is connected to the memory through the AHB, the AHB is connected to the peripheral bus through the AHB to APB bridge, and the memory includes 2 MRAMs, of which 1 MRAM is used as a backup. In the second aspect of the present application, a caching method is proposed, including: formulating different storage rules for different working modes of the MCU, and establishing priority decision rules in an environment where partial data storage is required. By connecting dual MRAM as a memory MCU structure in the system bus, and combining the caching method, effective management of the cache space is achieved, and the stability of the MCU system is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiment of the present invention relates to the field of magnetic storage, and relates to a dual MRAM MCU and a method for caching data. Background Art

[0002] A microcontroller unit (MCU), also known as a single-chip microcomputer, is a chip-level computer formed by appropriately reducing the frequency and specifications of a central processing unit (CPU), and integrating peripheral interfaces such as memory, counter, universal serial bus (USB), A / D conversion, asynchronous receiver / transmitter (UART), programmable logic controller (PLC), and direct memory access (DMA), and even the components and interfaces involved in the operation of the liquid crystal display (LCD) drive circuit on a single chip. Due to its relatively small size, MCU is currently widely used in fields such as AI, cloud computing, 5G, and smart cars.

[0003] With the rapid development of AI, cloud computing, 5G, and smart cars, more and more types of data need to be processed in various fields. Based on this, the MCU memory will have problems such as null pointer reading and writing, memory leaks, stack overflows, and parameter errors. Since the memory used in conventional MCUs is SRAM (Static Random-Access Memory), which is a volatile memory, when these problems cause the MCU to crash, the data in the SRAM will be lost, which is not conducive to the relevant technicians to troubleshoot and solve. Summary of the invention

[0004] The embodiment of the present invention provides a dual MRAM MCU and a method for caching data to solve the problem that a conventional MCU memory is a volatile memory.

[0005] In order to solve the above problem, a first aspect of the present invention proposes a method for caching data, which is applied to a dual-MRAM MCU, wherein the MCU comprises: the MCU comprises a first memory 3A and a second memory 3B, and the method comprises:

[0006] Storing information generated during the operation of the MCU in the first memory 3A;

[0007] Detecting an operating mode of the MCU, where the operating mode of the MCU includes a non-user mode and a user mode;

[0008] When the operation mode of the MCU is the non-user mode, all information in the first memory 3A is stored in the second memory 3B;

[0009] When the MCU is in the user mode, the information matching the user mode in the first memory 3A is stored in the second memory 3B.

[0010] In some embodiments, the information matching the user matching pattern includes:

[0011] The operation log corresponding to the MCU operation failure.

[0012] In some embodiments, the method for caching data further includes:

[0013] Determining the priority of each type of information in the first memory, wherein each type of information corresponds to a type of service;

[0014] The information matching the user pattern is determined according to the priorities of the various types of information.

[0015] In some embodiments, each type of information in the various types of information includes a running event corresponding to a corresponding service, and determining the priority of each type of information in the first memory includes:

[0016] The MCU obtains the access time and the access number of at least one storage area of ​​the first memory, and establishes a corresponding relationship between each storage area and the corresponding access number at each access time to obtain at least one operation event;

[0017] The MCU determines the running time of each running event in the at least one running event;

[0018] Determine the weight of each operation event at each time, wherein the weight represents the demand degree of the corresponding operation event;

[0019] The priority of each running event is determined according to the weight.

[0020] In some embodiments, the weight is obtained based on at least one of the following factors: used storage capacity of the storage area, a preset system priority, and a number of accesses.

[0021] In some embodiments, the MCU periodically updates the number of accesses and the access time corresponding to the storage area in the first memory.

[0022] In some embodiments, the application scenarios corresponding to the MCU non-user mode include: scenarios of products with the MCU in factory production and aging testing, and the scenarios corresponding to the user mode include: scenarios of users using products with the MCU.

[0023] In some embodiments, a decision matrix is ​​constructed based on the running event and the running time to establish a connection between the two, which specifically includes:

[0024]

[0025] in, i represents the reading time of the MRAM reading the operation event, j represents different storage areas in the MRAM, E={E1, E2…E n}、D={D1,D2…D n} and O={O1,O2…O n} indicates the running time of each business event.

[0026] In some embodiments, the system kernel calculates the task priority Pi of each functional service through a formula, and the formula includes:

[0027]

[0028] In some embodiments, the processor allocates storage areas to each service module according to the calculation result, including:

[0029]

[0030] B i represents the bandwidth of the storage area, S total Indicates the total storage capacity of the MRAM, S alloc represents the storage capacity allocated to business function i,

[0031] The storage area bandwidth B i The solution formula is:

[0032]

[0033] Where N is the number of bytes accessed by the business behavior, and T+(N-1)*val represents the time when each business behavior accesses the storage area.

[0034] In some embodiments, the method further includes optimizing data in the internal storage space of the MRAM, wherein the optimization includes deleting data and locating specific data.

[0035] In some embodiments, it is assumed that the system kernel obtains the latest instruction data at time T1 and obtains the latest system behavior log at time T2.

[0036] When time T1 is earlier than time T2, that is, the current system is operating normally, the current pointer data has been read by the system, and the MRAM internal storage log performs a deletion operation;

[0037] When T1 is not earlier than T2, that is, the system has a failure or other special requirements during the (T1 to T2) time period or at T1, the backup MRAM internally stores data as the data stored when the system fails.

[0038] In some embodiments, the MCU performs system initialization before working.

[0039] In some embodiments, after the MCU is initialized, the 1#MRAM reads the internal configuration information and confirms whether it is the first startup through the system internal marking.

[0040] If it is the first time to start up, it will be marked as status "0";

[0041] If it is not the first time to start up, it is marked as state "1", and at this time, the 1#MRAM reads the system configuration information of state "1".

[0042] In some embodiments, the MCU further includes a data encryption process, the encryption step including:

[0043] The MRAM receives and reads the plaintext data;

[0044] The MRAM internal key converts the plaintext data into ciphertext data through an encryption algorithm;

[0045] The MRAM outputs the ciphertext data to a subsequent unit module or stores it itself.

[0046] In some embodiments, the MCU further includes a data decryption process, the decryption steps including:

[0047] The MRAM receives and reads the ciphertext data;

[0048] The MRAM internal key converts the ciphertext data into plaintext data through a decryption algorithm;

[0049] The MRAM outputs plaintext data to subsequent unit modules or stores it itself.

[0050] In another aspect of the present application, a dual-MRAM MCU includes:

[0051] A processor 1, a system bus 2, a first memory 3A and a second memory 3B, wherein the processor 1 is connected to the first memory and the second memory via the system bus 2, and the first memory 3A and the second memory 3B are non-volatile memories;

[0052] The first memory 3A is used to store information related to the processor 1 and a system operation log, and the second memory 3B is used to store all or part of the information in the first memory 3A.

[0053] In some embodiments, the MCU also includes a peripheral bus 4 and a transfer bridge 5, the transfer bridge 5 is used for the system bus 2 to transfer the peripheral bus 4, the processor 1 is connected to the first memory 3A and the second memory 3B through the system bus 2, and the system bus 2 is connected to the peripheral bus 4 through the transfer bridge 5.

[0054] In some embodiments, the MCU uses a queued serial peripheral interface QSPI, and a QSPI controller drives the first memory 3A and the second memory 3B.

[0055] In some embodiments, the MCU implements information transmission between the first memory 3A and the second memory 3B through the QSPI communication protocol.

[0056] In some embodiments, the modules used by the MCU also include I2C (synchronous serial bus), I2S (inter-integrated circuit audio bus), SPI (serial peripheral interface),

[0057] The module is mounted on the external bus 4 .

[0058] In some embodiments, the system bus 2 includes: a master module, a slave module and a basic structure.

[0059] In some embodiments, the MCU further includes an arbitrator, which is used to determine whether the system bus 2 and the connected modules have completed data interaction.

[0060] The embodiment of the present invention provides a dual-MRAM cache MCU and a method for caching data, by connecting a dual-MRAM as a memory to the system bus of the MCU structure, and the two MRAMs can back up each other. And for the dual-MRAM cache MCU, three data storage schemes under working modes are proposed, which avoids the problems of single-block wear inside the MRAM, storage overflow and thread interlock caused by unbalanced writing, improves the stability of the MCU system, and because the two MRAMs can back up each other, it also ensures the accurate positioning of data when an exception occurs, and improves the efficiency of exception handling. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the embodiments of the present application 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 application.

[0062] Figure 1 A schematic diagram of the internal architecture of a dual-MRAM MCU according to the present invention;

[0063] Figure 2 is a schematic diagram of a system bus architecture according to an embodiment of the present invention;

[0064] Figure 3 A schematic diagram of a dual-MRAM MCU working mode according to an embodiment of the present invention;

[0065] Figure 4a A schematic diagram of a system MRAM encryption process according to an embodiment of the present invention;

[0066] Figure 4b A schematic diagram of a system MRAM decryption process according to an embodiment of the present invention;

[0067] Figure 5 A schematic diagram of row shifting in a system MRAM encryption and decryption process according to an embodiment of the present invention;

[0068] Figure 6 A schematic diagram of column confusion merging and replacement in a system MRAM according to an embodiment of the present invention;

[0069] Figure 7 The figure is a flow chart of adding a key for encryption / decryption according to an embodiment of the present invention. DETAILED DESCRIPTION

[0070] In order to make the purpose, features, and advantages of the invention of this application more obvious and easy to understand, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described implementation methods are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0071] Those skilled in the art will understand that the terms "first" and "second" in this application are only used to distinguish different devices, modules or parameters, etc., and do not represent any specific technical meanings, nor do they indicate the necessary logical order between them.

[0072] A microcontroller unit (MCU), also known as a single-chip microcomputer, appropriately reduces the frequency and specifications of a central processing unit (CPU), and integrates peripheral interfaces such as memory, counter, universal serial bus (USB), A / D conversion, asynchronous receiver / transmitter (UART), programmable logic controller (PLC), direct memory access (DMA), and even liquid crystal display (LCD) drive circuits on a single chip to form a chip-level computer. It can perform different combination controls for different application scenarios and is widely used in AI, cloud computing, 5G, smart cars and other fields.

[0073] At present, with the rapid development of consumer electronics, industrial control and new energy, the demand for storage devices has exploded. With the existence of various types of structured or unstructured data in system equipment in various fields, null pointer reading and writing, memory leaks, stack overflows, parameter errors and other problems may occur in the system. These problems will cause the MCU to crash. In order to quickly restore the system and locate the problem point, the system needs to restore the running state before the crash as soon as possible, so that relevant technicians can locate the actual problem point of the product and improve the efficiency of solving the problem.

[0074] In one embodiment of the present application, Figure 1 As shown, the first aspect of the present invention provides a dual-MRAM MCU, comprising:

[0075] A processor 1, a system bus 2, a first memory 3A and a second memory 3B, wherein the processor 1 is connected to the first memory and the second memory via the system bus 2, and the first memory 3A and the second memory 3B are non-volatile memories;

[0076] The first memory 3A is used to store information related to the processor 1 and a system operation log, and the second memory 3B is used to store all or part of the information in the first memory 3A.

[0077] Optionally, the MCU also includes a peripheral bus 4 and a transfer bridge 5, the transfer bridge 5 is used for the system bus 2 to transfer the peripheral bus 4, the processor 1 is connected to the first memory 3A and the second memory 3B through the system bus 2, and the system bus 2 is connected to the peripheral bus 4 through the transfer bridge 5.

[0078] Usually, the cache inside the MCU mainly works with SRAM, which is static random access memory. The so-called "static" means that as long as the memory remains powered, the data stored in it can be kept constant. However, when the power supply stops, the data stored in the SRAM will disappear, which is the defect of volatility.

[0079] Usually, the system bus (AHB, Advanced High Performance Bus), also known as the high-performance bus, is a bus interface like USB. AHB is mainly used for the connection between high-performance modules (such as CPU, DMA and DPS, etc.).

[0080] MRAM memory cell arrays are addressed by selecting gates and bit lines, and information is read and written by bit line currents. They have the following characteristics: non-volatility, simple structure, low manufacturing process cost, high read and write times, and low power consumption. They are widely used in the storage field.

[0081] Optionally, the MCU further includes an MRAM controller, and the MRAM controller connects the 1# MRAM to the AHB system bus 2.

[0082] Optionally, the system bus 2 structure is as follows: Figure 2 As shown, it includes: a master module (AHB Master), a slave module (AHBSlave) and an infrastructure.

[0083] Typically, the basic modules of the system bus 2 include an arbitrator and a decoder, such as Figure 2 shown.

[0084] Optionally, the MCU further includes an arbitrator, and the arbitrator is used to determine whether the system bus 2 and the connected modules have completed data interaction.

[0085] Optionally, the modules used by the MCU also include I2C (synchronous serial bus), I2S (integrated circuit internal audio bus), and SPI (serial peripheral interface), and the modules are mounted on the APB external bus 4.

[0086] Generally, the Advanced Peripheral Bus (APB) is a standard on-chip bus structure. APB is mainly used for connecting low-bandwidth peripherals. Its bus architecture does not support multiple master modules like AHB. The only master module in APB is the APB bridge. Its features include: two clock cycle transmission; no waiting cycle and response signal; simple control logic, only four control signals. The transmission on APB can be explained by the state diagram shown in the overview figure.

[0087] Typically, data transmission on the system bus 2 is instructed by a master module and responded to by a slave module.

[0088] In another aspect of the present application, a method for caching data is proposed.

[0089] Applied to a dual-MRAM MCU, the MCU includes: the MCU includes a first memory 3A and a second memory 3B, the method includes:

[0090] Storing information generated during the operation of the MCU in the first memory 3A;

[0091] Detecting an operating mode of the MCU, where the operating mode of the MCU includes a non-user mode and a user mode;

[0092] When the operation mode of the MCU is the non-user mode, all information in the first memory 3A is stored in the second memory 3B;

[0093] When the MCU is in the user mode, the information matching the user mode in the first memory 3A is stored in the second memory 3B.

[0094] Optionally, the information matching the user matching pattern includes:

[0095] The operation log corresponding to the MCU operation failure.

[0096] Optionally, the information matching the user matching pattern includes:

[0097] The operation log corresponding to the MCU operation failure.

[0098] Optionally, the method for caching data further includes:

[0099] Determining the priority of each type of information in the first memory, wherein each type of information corresponds to a type of service;

[0100] The information matching the user pattern is determined according to the priorities of the various types of information.

[0101] Optionally, each type of information in the various types of information includes a running event corresponding to a corresponding service, and determining the priority of each type of information in the first memory includes:

[0102] The MCU obtains the access time and the access number of at least one storage area of ​​the first memory, and establishes a corresponding relationship between each storage area and the corresponding access number at each access time to obtain at least one operation event;

[0103] The MCU determines the running time of each running event in the at least one running event;

[0104] Determine the weight of each operation event at each time, wherein the weight represents the demand degree of the corresponding operation event;

[0105] The priority of each running event is determined according to the weight.

[0106] Optionally, the weight is obtained based on at least one of the following factors: used storage capacity of the storage area, a preset system priority, and a number of accesses.

[0107] Optionally, the MCU periodically updates the number of accesses and the access time corresponding to the storage area in the first memory.

[0108] Optionally, the MCU non-user mode corresponds to application scenarios including: scenarios of products with the MCU in the factory production process and aging test, and the user mode corresponds to scenarios including: scenarios of users using products with the MCU, data storage status of the MCU in different working modes, such as Figure 3 shown.

[0109] When the MCU is in factory mode, the second memory 3B backs up all information in the first memory 3A;

[0110] When the MCU is in the aging test mode, the second memory 3B backs up all the information in the first memory 3A;

[0111] When the MCU is in user mode, the second memory 3B is only used to store the information matching the user mode of the MCU system.

[0112] The information of the user pattern matching is provided by the first memory 3A.

[0113] Optionally, the MCU performs system initialization before working.

[0114] Optionally, after the MCU is initialized, the first memory 3A reads the internal configuration information and confirms whether it is the first startup through the internal marking of the system.

[0115] If it is the first time to start up, it will be marked as status "0";

[0116] If it is not the first time to start up, it is marked as state "1", and at this time, the first memory 3A reads the system configuration information of state "1".

[0117] Optionally, when the MCU is in the user mode, since the second memory 3B only backs up the information matching the user mode in the first memory 3A, the system needs to prioritize the data through a data processing method to identify and prioritize the specific behavior logs of the system. The data processing method includes:

[0118] The processor establishes a connection between the number of accesses and the access time in the MRAM storage area;

[0119] The processor constructs a decision matrix based on the access time and the specific behavior log to establish a connection between the two;

[0120] The MCU system periodically queries the number of accesses to each storage area, updates and records the access time of each service instruction to the storage area in real time, and performs task recording for each specific event to generate a specific behavior log;

[0121] The processor constructs a decision matrix based on the access time and the specific behavior log to establish a connection between the two;

[0122] The processor calculates the priority of each functional service to determine the basis for allocating the storage area;

[0123] The processor allocates storage areas to each service module according to the calculation results.

[0124] Optionally, the connection between the number of accesses and the access time is established in the MRAM storage area, which is specifically expressed as: Nc(C, T), indicating that the number of times a specific storage area is accessed at a specific time T is C.

[0125] Optionally, the MCU system periodically queries the number of accesses to each storage area, and updates and records the access time of each service instruction accessing the storage area in real time.

[0126] Specifically expressed as: Flow = (T, Event), indicating that a specific event Event occurs at time T.

[0127] Optionally, a decision matrix is ​​constructed based on the running event and the running time to establish a connection between the two, which specifically includes:

[0128]

[0129] Wherein, i represents the reading time of the MRAM reading the operation event, j represents different storage areas in the MRAM, and E={E1, E2…E n}、D={D1,D2…D n} and O={O1,O2…O n} indicates the running time of each business event.

[0130] Optionally, the specific events include: failure of the MCU system and special operation of the MCU system.

[0131] Optionally, the MCU acquires relevant factors to construct a business decision matrix, including: used storage capacity, system priority, and number of accesses. The business decision matrix is ​​used to arrange the priorities of different functional businesses in system processes and threads.

[0132] The business data flow constructs a weight coefficient vector W, which is specifically expressed as: W = [W b , W d , W c ] T ,

[0133] Among them, W b Indicates the used storage capacity of the corresponding storage area, W d Indicates the internal priority of the system, W c The corresponding storage area access count.

[0134] Optionally, the MCU calculates the task priority Pi of each functional service through a formula, and the formula includes:

[0135]

[0136] Optionally, the MCU allocates storage areas to each service module according to the calculation result, including:

[0137]

[0138] B i represents the bandwidth of the storage area, S total Indicates the total storage capacity of the MRAM, S alloc represents the storage capacity allocated to business function i,

[0139] The storage area bandwidth B i The solution formula is:

[0140]

[0141] Where N is the number of bytes accessed by the business behavior, and T+(N-1)*val represents the time it takes for each business behavior to access the storage area.

[0142] Optionally, the method further includes optimizing data in the internal storage space of the MRAM, wherein the optimization includes deleting data and locating specific data.

[0143] Optionally, assuming that the system kernel obtains the latest instruction data at time T1, and obtains the latest system behavior log at time T2,

[0144] When time T1 is earlier than time T2, that is, the current system is operating normally, the current pointer data has been read by the system, and the MRAM internal storage log performs a deletion operation;

[0145] When T1 is not earlier than T2, that is, the system has a failure or other special requirements during the (T1 to T2) time period or at T1, the backup MRAM internally stores data as the data stored when the system fails.

[0146] Generally, since MRAM is a non-volatile memory, the characteristic of non-volatile storage that does not lose data also provides more access opportunities for system attackers and data thieves. When the MCU is in the factory mode and the aging test mode, it is mainly used to test the MCU system and period stability, and the data security requirements are relatively low. However, when the MCU is running in the user mode, it is necessary to encrypt and protect the user's behavior events and the internal data stored in the MRAM to ensure the privacy and security of the user during use.

[0147] Optionally, the MCU also includes a data encryption process, the encryption process is as follows Figure 4a As shown, the encryption steps include:

[0148] The MRAM receives and reads the plaintext data;

[0149] The MRAM internal key converts the plaintext data into ciphertext data through an encryption algorithm;

[0150] The MRAM outputs the ciphertext data to a subsequent unit module or stores it itself.

[0151] Optionally, the MCU also includes a data decryption process, the decryption process is as follows Figure 4b As shown, the decryption steps include:

[0152] The MRAM receives and reads the ciphertext data;

[0153] The MRAM internal key converts the ciphertext data into plaintext data through a decryption algorithm;

[0154] The MRAM outputs plaintext data to subsequent unit modules or stores it itself.

[0155] Optionally, the MCU data encryption / decryption process includes:

[0156] The processor performs row shift processing on the storage data in the storage area, and the processing process is as follows: Figure 5 As shown,

[0157] Specifically, the first row of data stored in the storage area remains unchanged, the second row is cyclically shifted left by one byte, the third row is cyclically shifted left by two bytes, and the Nth row is cyclically shifted left by (n-1) bytes. The storage data matrix is ​​set to State, which is expressed as follows:

[0158] State[i][j]=State[i][(j+i)%n];i,j∈[0,n-1];

[0159] The processor performs byte replacement and data column confusion merging on the stored data, the process is as follows Figure 6 As shown,

[0160] Generally, the S-box (Substitution-box) is the basic structure of a symmetric key algorithm to perform substitution calculations, and its function is a simple "substitution" operation.

[0161] Specifically, the MCU system uses the S-box to complete the byte conversion of the byte event mapping, and directly processes the data through column conversion to improve the data time. The specific calculation is expressed as:

[0162] text64[0]^=keyExtended64[2*round];

[0163] text64[1]^=keyExtended64[2*round+1];

[0164] …

[0165] text64[n-1]^=keyExtended64[2*round+(n-1)];

[0166] The processor uses different keys to perform encryption / decryption on the MRAM, the MCU system further includes a six-axis sensor, and the key is derived from the six-axis sensor.

[0167] Specifically, when the MCU system reads data from the data storage box, the key is formed according to the six-side values ​​of the six-axis sensor in the current state.

[0168] If the key B is obtained when storing data, and the key A is obtained when reading data, the two parties exchange keys during the storage and reading process after obtaining the key, that is, when storing data, key A is used for encryption, and when reading data, key B is used for decryption. Figure 7 shown.

[0169] The embodiment of the present invention provides a dual-MRAM cache MCU and a method for caching data, by connecting a dual-MRAM as a memory to the system bus of the MCU structure, and the two MRAMs can back up each other. And for the dual-MRAM cache MCU, three data storage schemes under working modes are proposed, which avoids the problems of single-block wear inside the MRAM, storage overflow and thread interlock caused by unbalanced writing, improves the stability of the MCU system, and because the two MRAMs can back up each other, it also ensures the accurate positioning of data when an exception occurs, and improves the efficiency of exception handling.

Claims

1. A method for caching data, It is characterized in that An MCU applied to a dual magnetic random access memory MRAM, the MCU comprising a first memory (3A) and a second memory (3B), the first memory (3A) and the second memory (3B) backing up each other, the method comprising: storing information generated during the operation of the MCU in the first memory (3A); Detecting an operating mode of the MCU, where the operating mode of the MCU includes a non-user mode and a user mode; When the operation mode of the MCU is the non-user mode, storing all the information in the first memory (3A) into the second memory (3B); When the MCU is in user mode, storing information matching the user mode in the first memory (3A) into the second memory (3B); Determining priorities of various types of information in the first memory, wherein each type of information corresponds to a type of service; Each type of information in the various types of information includes an operation event corresponding to a corresponding business, and determining the priority of each type of information in the first memory to identify and preferentially record a specific behavior log of the system includes: The MCU obtains the access time and the access number of at least one storage area of ​​the first memory, and establishes a corresponding relationship between each storage area and the corresponding access number at each access time to obtain at least one operation event; The MCU determines the running time of each running event in the at least one running event; Determine the weight of each operation event at each time, wherein the weight represents the demand degree of the corresponding operation event; Determine the priority of each running event according to the weight; The information matching the user pattern is determined according to the priorities of the various types of information.

2. The method according to claim 1, It is characterized in that The information matching the user pattern includes: The operation log corresponding to the MCU operation failure.

3. The method according to claim 1, It is characterized in that The weight is obtained according to at least one of the following factors: the used storage capacity of the storage area, the preset system priority and the number of accesses.

4. The method according to claim 1, It is characterized in that Also includes: The MCU periodically updates the number of accesses and the access time corresponding to the storage area in the first memory.

5. A dual-MRAM MCU, It is characterized in that The MCU includes: A processor (1), a system bus (2), a first memory (3A), a second memory (3B), and a computer program running on the processor, wherein the processor executes the computer program to implement the method for caching data according to any one of claims 1 to 4. The processor (1) is connected to the first memory and the second memory via the system bus (2), and the first memory (3A) and the second memory (3B) are non-volatile memories; The first memory (3A) is used to store information related to the processor (1) and a system operation log, and the second memory (3B) is used to store all or part of the information in the first memory (3A).

6. The MCU according to claim 5, It is characterized in that The MCU further comprises a peripheral bus (4) and a transfer bridge (5), wherein the transfer bridge (5) is used for transferring the system bus (2) to the peripheral bus (4), the processor (1) is connected to the first memory (3A) and the second memory (3B) via the system bus (2), and the system bus (2) is connected to the peripheral bus (4) via the transfer bridge (5).

7. The MCU according to claim 5, It is characterized in that The MCU adopts a queue serial peripheral interface QSPI, and a QSPI controller drives the first memory (3A) and the second memory (3B).

8. The MCU according to claim 5, It is characterized in that The MCU implements information transmission between the first memory (3A) and the second memory (3B) through a QSPI communication protocol.