Data receiving method and device of MCU (Microprogrammed Control Unit), electronic equipment and storage medium

By configuring a circular buffer for the MCU and using the DMA module to read data at once, the burden caused by frequent interruptions when the MCU receives large amounts of data is solved, and efficient data reception is achieved.

CN121996590APending Publication Date: 2026-05-08LISHUI PENGYANG MEDICAL TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
LISHUI PENGYANG MEDICAL TECHNOLOGY CO LTD
Filing Date
2026-02-05
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

The problem of MCUs being overburdened due to frequent interrupt handling when receiving large amounts of data.

Method used

Configure a circular buffer for the MCU and map it as the data receive buffer for the DMA module. Use the DMA module to read data at once and generate an interrupt to reduce the number of interrupts.

Benefits of technology

Reading a large amount of data in a single interrupt reduces the burden on the MCU and improves data reception efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121996590A_ABST
    Figure CN121996590A_ABST
Patent Text Reader

Abstract

The invention discloses a data receiving method and device of an MCU, electronic equipment and a storage medium, the method and device are applied to the electronic equipment, specifically, a circular buffer area is configured for the MCU, and the circular buffer area comprises a basic buffer area and at least one expansion buffer area; mapping the circular buffer area into a data receiving buffer area of a DMA (Direct Memory Access) module of the MCU; responding to a data uploading request of the peripheral, and receiving uploading data of the peripheral based on the data receiving buffer area; when the uploaded data is read into the data receiving buffer area, reading interruption is generated; and controlling the MCU to respond to the reading interruption, and reading the uploaded data from the data receiving buffer area. According to the scheme, the DMA module is used for reading multiple pieces of data into the data receiving buffer area at a time, then interruption is generated after reading is completed, an MCU reads a large amount of data through one-time interruption, and therefore the burden caused by the fact that the MCU needs to frequently process the interruption when receiving the large amount of data is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data communication technology, and more specifically, to a data receiving method, apparatus, electronic device, and storage medium for an MCU. Background Technology

[0002] An MCU (Microcontroller Unit) is a computing core that provides computation and control services for devices or equipment requiring intelligent control, such as vehicles, home appliances, and machinery. When implementing control, it needs to acquire external data (such as from temperature and humidity sensors or buttons), send commands (such as controlling motors or OLED screens), and collaborate with other devices (such as multi-MCU networking or connecting to computers / mobile phones). Generally, MCUs communicate externally via interrupts, requiring interrupt processing for each received byte. When receiving large amounts of data, this necessitates frequent interrupt processing, increasing the workload. Summary of the Invention

[0003] In view of this, this application provides a data receiving method, apparatus, electronic device and storage medium for controlling the MCU to receive data through a serial port, so as to reduce the burden caused by the MCU having to frequently process interrupts when receiving a large amount of data.

[0004] To achieve the above objectives, the following solution is proposed:

[0005] A data receiving method for an MCU, applied to an electronic device, the data receiving method comprising the following steps:

[0006] Configure a circular buffer for the MCU, the circular buffer comprising a basic buffer and at least one extended buffer;

[0007] Map the circular buffer to the data receive buffer of the DMA module of the MCU;

[0008] In response to a data upload request from a peripheral device, the device receives the uploaded data based on the data receiving buffer.

[0009] A read interrupt is generated when the uploaded data is read into the data receiving buffer;

[0010] The MCU is controlled to respond to the read interrupt and read the uploaded data from the data receive buffer.

[0011] Optionally, configuring a circular buffer for the MCU, the circular buffer comprising a basic buffer and at least one extended buffer, includes the following steps:

[0012] In response to a user's basic configuration request, configure a basic buffer.

[0013] In response to a user's extended configuration request, configure one or more extended buffers.

[0014] Based on the user's capacity configuration request, the basic buffer is concatenated with one or more of the extended buffers according to the capacity configuration parameters to obtain the circular buffer.

[0015] Optionally, the length of the basic buffer is a fixed length.

[0016] Optionally, the capacity configuration parameter is related to the amount of data sent by the peripheral device.

[0017] Optionally, generating a read interrupt when the uploaded data is read into the data receiving buffer includes the following steps:

[0018] After the uploaded data is read into the data receiving buffer, the length of the read data is compared with the buffer length of the data receiving buffer;

[0019] If the data length is equal to the buffer length, a DMA interrupt is generated;

[0020] If the data length is less than the buffer length, an idle interrupt is generated.

[0021] Optionally, controlling the MCU to respond to the read interrupt and read the uploaded data from the data receive buffer includes the following steps:

[0022] Data is read sequentially from the data receiving buffer;

[0023] For each piece of data read, the starting position of the data to be read is moved forward by one data unit.

[0024] Optionally, the data unit is the amount of data contained in a single read length.

[0025] A data receiving device for an MCU, used in an electronic device, the data receiving device comprising:

[0026] A buffer configuration module is configured to configure a circular buffer for the MCU, the circular buffer including a basic buffer and at least one extended buffer;

[0027] A buffer mapping module is configured to map the circular buffer to the data receive buffer of the DMA module of the MCU;

[0028] The data receiving module is configured to respond to data upload requests from peripheral devices and receive the uploaded data from the peripheral devices based on the data receiving buffer.

[0029] The interrupt generation module is configured to generate a read interrupt when the uploaded data is read into the data receiving buffer;

[0030] The read execution module is configured to control the MCU to respond to the read interrupt and read the uploaded data from the data receive buffer.

[0031] An electronic device includes at least one processor and a memory connected to the processor, wherein:

[0032] The memory is used to store computer programs or instructions;

[0033] The processor is used to execute the computer program or instructions to enable the electronic device to implement the data receiving method as described above.

[0034] A computer-readable storage medium is applied to an electronic device, the storage medium carrying one or more computer programs that can be executed by the electronic device to enable the electronic device to perform the data receiving method as described above.

[0035] As can be seen from the above technical solutions, this application discloses a data receiving method, apparatus, electronic device, and storage medium for an MCU. The method and apparatus are applied to an electronic device, specifically configuring a circular buffer for the MCU, the circular buffer including a basic buffer and at least one extended buffer; mapping the circular buffer to a data receiving buffer of the MCU's DMA module; responding to a data upload request from a peripheral device, receiving uploaded data from the peripheral device based on the data receiving buffer; generating a read interrupt when uploaded data is read into the data receiving buffer; controlling the MCU to respond to the read interrupt and read the uploaded data from the data receiving buffer. This solution utilizes the DMA module to read multiple data items into the data receiving buffer at once, and only generates an interrupt after the reading is complete. This allows the MCU to read a large amount of data through a single interrupt, thereby reducing the burden on the MCU caused by frequent interrupt handling when receiving large amounts of data.

[0036] In addition, this application uses DMA interrupts, idle interrupts, and circular buffers to achieve the reception of variable-length data, reducing the number of times the MCU enters an interrupt, improving data reception efficiency, and further reducing the burden on the MCU. Attached Figure Description

[0037] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0038] Figure 1 This is a flowchart illustrating a data receiving method for an MCU according to an embodiment of this application;

[0039] Figure 2 This is a schematic diagram of the data receiving buffer in an embodiment of this application;

[0040] Figure 3 This is a schematic diagram illustrating data storage in the data reception buffer when an idle interrupt occurs, according to an embodiment of this application.

[0041] Figure 4 This is a schematic diagram illustrating data storage in the data receive buffer when a DMA interrupt occurs, according to an embodiment of this application.

[0042] Figure 5 This is a schematic diagram illustrating data storage in the data reception buffer when an idle interrupt is generated again, according to an embodiment of this application.

[0043] Figure 6 This is a schematic diagram illustrating data storage when reading data from the data receiving buffer, according to an embodiment of this application.

[0044] Figure 7 This is a flowchart illustrating a data receiving method for an MCU according to an embodiment of this application;

[0045] Figure 8 This is a block diagram of an electronic device according to an embodiment of this application. Detailed Implementation

[0046] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0047] Figure 1 This is a flowchart illustrating a data receiving method for an MCU according to an embodiment of this application.

[0048] like Figure 1 As shown, the data receiving method in this embodiment is applied to electronic devices to reduce the burden on the MCU caused by frequent interrupt handling when receiving large amounts of data via serial port. The electronic device refers to a control device or electronic device module built on an MCU, or a control device or electronic device module including an MCU. The data receiving method includes the following steps:

[0049] S1. Configure a circular buffer for the MCU.

[0050] In other words, assuming the MCU has a storage module or storage device, such as internal cache or external storage, a circular buffer is configured based on this storage module or storage device. A circular buffer is one that can perform circular storage, providing a buffer space for subsequently received uploaded data. This circular buffer includes a basic buffer and at least one extended buffer. The configuration process is as follows:

[0051] On one hand, it responds to basic configuration requests input by the user, configuring the position, starting address, length, and ending address of the basic buffer. The length of the basic buffer is fixed, but it can also be adaptively adjusted according to the configuration request or the data to be received.

[0052] On the other hand, responding to the user's extended configuration request, one or more extended buffers are configured. The length of the extended buffers is preferably fixed, allowing for convenient configuration of the circular buffer length based on the number of extended buffers. When configuring one extended buffer, its starting address is concatenated with the ending address of the base buffer; furthermore, when configuring multiple extended buffers, subsequent extended buffers are sequentially concatenated with the addresses of the preceding extended buffers.

[0053] Furthermore, based on the user's capacity configuration request and the capacity configuration parameters received from that request, the basic buffer is concatenated with one or more extended buffers to obtain a circular buffer. These capacity configuration parameters are related to the amount of data sent by the peripheral device.

[0054] S2. Map the circular buffer to the data receive buffer of the MCU's DMA module.

[0055] After configuring the circular buffer, it is mapped to the MCU's DMA module, specifically as the DMA's data receive buffer. For example... Figure 2 As shown, assuming the starting address of the data receive buffer is 0x00000001, in the initial state (i.e., before data reception begins), both head and rear point to the starting address of the data receive buffer. Here, rear indicates the position of the last data to be received within the data receive buffer, and head indicates the position of the first data to be received within the data receive buffer.

[0056] S3. Respond to the data upload request from the peripheral device and receive the uploaded data from the peripheral device based on the data receive buffer.

[0057] Here, "peripheral" refers to an external device relative to the MCU, or other devices connected to the MCU. Upon receiving a data upload request from the peripheral, the system receives the uploaded data from the peripheral based on this circular buffer. During reception, the `rear` variable moves one position forward for each received data item, until all uploaded data has been received.

[0058] S4. When the uploaded data is read into the data receiving buffer, a read interrupt is generated.

[0059] The data receive buffer is a data cache. After receiving data, the MCU can be controlled via an interrupt to read the data from it for parsing and processing. The specific process is as follows:

[0060] After the uploaded data is read into the data receive buffer, the length of the read data is compared with the buffer length of the data receive buffer to determine whether the data length is equal to or less than the buffer length. If the data length is equal to the buffer length, a DMA interrupt is generated; if the data length is less than the buffer length, an idle interrupt is generated.

[0061] Specifically, when an idle interrupt occurs, the data storage status in the data receive buffer is as follows: Figure 3 As shown, since DMA is used for receiving, the MCU does not need to read data byte by byte, which saves frequent operations. At this time, the received data size number is equal to rear minus head.

[0062] When a DMA interrupt occurs, the data storage in the data receive buffer is as follows: Figure 4 As shown, at this point, number equals rear minus head. When the peripheral device continues to send data, another idle interrupt is generated. At this time, the data receive buffer is stored as follows. Figure 5 As shown, the buffer loops back to the starting position to begin receiving data. At this point, number equals rear plus size minus head.

[0063] S5. Control the MCU to respond to the read interrupt and read the uploaded data from the data receive buffer.

[0064] This means reading data sequentially from the data receive buffer. For each data byte read, the starting position of the data to be read is shifted forward by one data unit. This data unit represents the amount of data contained in a single read, such as one byte. For example, after retrieving one byte of data from the buffer, the `head` pointer is shifted forward one position; the portion between `rear` and `head` represents the remaining valid data. Figure 6 As shown.

[0065] As can be seen from the above technical solution, this embodiment provides a data receiving method for an MCU. This method is applied to electronic devices, specifically by configuring a circular buffer for the MCU, which includes a basic buffer and at least one extended buffer; mapping the circular buffer to a data receiving buffer of the MCU's DMA module; responding to a data upload request from a peripheral device, receiving uploaded data from the peripheral device based on the data receiving buffer; generating a read interrupt when uploaded data is read into the data receiving buffer; and controlling the MCU to respond to the read interrupt and read the uploaded data from the data receiving buffer. This solution utilizes the DMA module to read multiple data items into the data receiving buffer at once, and only generates an interrupt after the reading is complete. This allows the MCU to read a large amount of data in a single interrupt, thereby reducing the burden on the MCU caused by frequent interrupt handling when receiving large amounts of data.

[0066] In addition, this application uses DMA interrupts, idle interrupts, and circular buffers to achieve the reception of variable-length data, reducing the number of times the MCU enters an interrupt, improving data reception efficiency, and further reducing the burden on the MCU.

[0067] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0068] Although the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous.

[0069] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.

[0070] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including but not limited to object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer.

[0071] Figure 7 This is a block diagram of a data receiving device for an MCU according to an embodiment of this application.

[0072] like Figure 7 As shown, the data receiving device in this embodiment is applied to electronic devices to reduce the burden on the MCU caused by frequent interrupt handling when it needs to receive large amounts of data via serial port. This electronic device refers to a control device or electronic device module built on an MCU, or a control device or electronic device module including an MCU. The data receiving device includes a buffer configuration module 10, a buffer mapping module 20, a data receiving module 30, an interrupt generation module 40, and a read execution module 50.

[0073] The buffer configuration module is used to configure a circular buffer for the MCU.

[0074] In other words, assuming the MCU has a storage module or storage device, such as internal cache or external storage, a circular buffer is configured based on this storage module or storage device. A circular buffer is one that can perform circular storage, providing a buffer space for subsequently received uploaded data. This circular buffer includes a basic buffer and at least one extended buffer. The configuration process is as follows:

[0075] On one hand, it responds to basic configuration requests input by the user, configuring the position, starting address, length, and ending address of the basic buffer. The length of the basic buffer is fixed, but it can also be adaptively adjusted according to the configuration request or the data to be received.

[0076] On the other hand, responding to the user's extended configuration request, one or more extended buffers are configured. The length of the extended buffers is preferably fixed, allowing for convenient configuration of the circular buffer length based on the number of extended buffers. When configuring one extended buffer, its starting address is concatenated with the ending address of the base buffer; furthermore, when configuring multiple extended buffers, subsequent extended buffers are sequentially concatenated with the addresses of the preceding extended buffers.

[0077] Furthermore, based on the user's capacity configuration request and the capacity configuration parameters received from that request, the basic buffer is concatenated with one or more extended buffers to obtain a circular buffer. These capacity configuration parameters are related to the amount of data sent by the peripheral device.

[0078] The buffer mapping module is used to map a circular buffer to the data receive buffer of the MCU's DMA module.

[0079] After configuring the circular buffer, it is mapped to the MCU's DMA module, specifically as the DMA's data receive buffer. For example... Figure 2 As shown, assuming the starting address of the data receive buffer is 0x00000001, in the initial state (i.e., before data reception begins), both head and rear point to the starting address of the data receive buffer. Here, rear indicates the position of the last data to be received within the data receive buffer, and head indicates the position of the first data to be received within the data receive buffer.

[0080] The data receiving module is used to respond to data upload requests from peripheral devices and receives the uploaded data from the peripheral devices based on the data receiving buffer.

[0081] Here, "peripheral" refers to an external device relative to the MCU, or other devices connected to the MCU. Upon receiving a data upload request from the peripheral, the system receives the uploaded data from the peripheral based on this circular buffer. During reception, the `rear` variable moves one position forward for each received data item, until all uploaded data has been received.

[0082] The interrupt generation module is used to generate a read interrupt when uploaded data is read into the data receive buffer.

[0083] The data receive buffer is a data cache. After receiving data, the MCU can be controlled via an interrupt to read the data from it for parsing and processing. The specific process is as follows:

[0084] After the uploaded data is read into the data receive buffer, the length of the read data is compared with the buffer length of the data receive buffer to determine whether the data length is equal to or less than the buffer length. If the data length is equal to the buffer length, a DMA interrupt is generated; if the data length is less than the buffer length, an idle interrupt is generated.

[0085] Specifically, when an idle interrupt occurs, the data storage status in the data receive buffer is as follows: Figure 3 As shown, since DMA is used for receiving, the MCU does not need to read data byte by byte, which saves frequent operations. At this time, the received data size number is equal to rear minus head.

[0086] When a DMA interrupt occurs, the data storage in the data receive buffer is as follows: Figure 4 As shown, at this point, number equals rear minus head. When the peripheral device continues to send data, another idle interrupt is generated. At this time, the data receive buffer is stored as follows. Figure 5 As shown, the buffer loops back to the starting position to begin receiving data. At this point, number equals rear plus size minus head.

[0087] The read execution module is used to control the MCU to respond to read interrupts and read uploaded data from the data receive buffer.

[0088] This means reading data sequentially from the data receive buffer. For each data byte read, the starting position of the data to be read is shifted forward by one data unit. This data unit represents the amount of data contained in a single read, such as one byte. For example, after retrieving one byte of data from the buffer, the `head` pointer is shifted forward one position; the portion between `rear` and `head` represents the remaining valid data. Figure 6 As shown.

[0089] As can be seen from the above technical solution, this embodiment provides a data receiving device for an MCU. This device is applied to electronic devices, specifically configuring a circular buffer for the MCU, which includes a basic buffer and at least one extended buffer; mapping the circular buffer to a data receiving buffer of the MCU's DMA module; responding to data upload requests from peripherals, receiving uploaded data from the peripherals based on the data receiving buffer; generating a read interrupt when uploaded data is read into the data receiving buffer; controlling the MCU to respond to the read interrupt and read the uploaded data from the data receiving buffer. This solution utilizes the DMA module to read multiple data items into the data receiving buffer at once, and only generates an interrupt after the reading is complete. This allows the MCU to read a large amount of data in a single interrupt, thereby reducing the burden on the MCU caused by frequent interrupt handling when receiving large amounts of data.

[0090] The units described in the embodiments of this disclosure can be implemented in software or in hardware. The name of a unit does not necessarily limit the unit itself; for example, the first acquisition unit can also be described as "a unit that acquires at least two Internet Protocol addresses".

[0091] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), and so on.

[0092] Figure 8 A block diagram of an electronic device according to an embodiment of this application.

[0093] The following is for reference. Figure 8 This document illustrates a structural diagram suitable for implementing the electronic device in the embodiments of this disclosure. The terminal device in the embodiments of this disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. This electronic device is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this disclosure.

[0094] The electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from an input device 806 into a random access memory (RAM) 803. The RAM also stores various programs and data required for the operation of the electronic device. The processing unit, ROM, and RAM are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0095] Typically, the following devices can be connected to the I / O interface: input devices including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 807 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 808 including, for example, magnetic tapes, hard disks, etc.; and communication devices 809. Communication device 809 allows the electronic device to communicate wirelessly or wiredly with other devices to exchange data. Although electronic devices with various devices are shown in the figures, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0096] This application also provides an embodiment of a computer-readable storage medium.

[0097] The aforementioned computer-readable storage medium is used in an electronic device and carries one or more computer programs. When these programs are executed by the electronic device, the device configures a circular buffer for the MCU, which includes a basic buffer and at least one extended buffer. The circular buffer is mapped to a data receive buffer of the MCU's DMA module. In response to a data upload request from a peripheral device, the device receives the uploaded data based on the data receive buffer. When uploaded data is read into the data receive buffer, a read interrupt is generated. The MCU is controlled to respond to the read interrupt and read the uploaded data from the data receive buffer. This solution utilizes the DMA module to read multiple data items into the data receive buffer at once, and only generates an interrupt after the read is complete. This allows the MCU to read a large amount of data in a single interrupt, thereby reducing the burden on the MCU caused by frequent interrupt handling when receiving large amounts of data.

[0098] It should be noted that the computer-readable medium described above in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.

[0099] In this disclosure, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0100] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0101] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.

[0102] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0103] The technical solution provided by the present invention has been described in detail above. Specific examples have been used to illustrate the principle and implementation of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core idea of ​​the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation and application scope based on the idea of ​​the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A data receiving method for an MCU, applied to electronic devices, characterized in that, The data receiving method includes the following steps: Configure a circular buffer for the MCU, the circular buffer comprising a basic buffer and at least one extended buffer; Map the circular buffer to the data receive buffer of the DMA module of the MCU; In response to a data upload request from a peripheral device, the device receives the uploaded data based on the data receiving buffer. A read interrupt is generated when the uploaded data is read into the data receiving buffer; The MCU is controlled to respond to the read interrupt and read the uploaded data from the data receive buffer.

2. The data receiving method as described in claim 1, characterized in that, The step of configuring a circular buffer for the MCU, the circular buffer comprising a basic buffer and at least one extended buffer, includes the following steps: In response to a user's basic configuration request, configure a basic buffer. In response to a user's extended configuration request, configure one or more extended buffers. Based on the user's capacity configuration request, the basic buffer is concatenated with one or more of the extended buffers according to the capacity configuration parameters to obtain the circular buffer.

3. The data receiving method as described in claim 2, characterized in that, The length of the basic buffer is fixed.

4. The data receiving method as described in claim 2, characterized in that, The capacity configuration parameter is related to the amount of data sent by the peripheral device.

5. The data receiving method as described in claim 1, characterized in that, The step of generating a read interrupt when the uploaded data is read into the data receiving buffer includes the following steps: After the uploaded data is read into the data receiving buffer, the length of the read data is compared with the buffer length of the data receiving buffer; If the data length is equal to the buffer length, a DMA interrupt is generated; If the data length is less than the buffer length, an idle interrupt is generated.

6. The data receiving method as described in claim 1, characterized in that, The step of controlling the MCU to respond to the read interrupt and read the uploaded data from the data receive buffer includes the following steps: Data is read sequentially from the data receiving buffer; For each piece of data read, the starting position of the data to be read is moved forward by one data unit.

7. The data receiving method as described in claim 6, characterized in that, The data unit is the amount of data contained in a single read length.

8. A data receiving device for an MCU, used in electronic devices, characterized in that, The data receiving device includes: A buffer configuration module is configured to configure a circular buffer for the MCU, the circular buffer including a basic buffer and at least one extended buffer; A buffer mapping module is configured to map the circular buffer to the data receive buffer of the DMA module of the MCU; The data receiving module is configured to respond to data upload requests from peripheral devices and receive the uploaded data from the peripheral devices based on the data receiving buffer. The interrupt generation module is configured to generate a read interrupt when the uploaded data is read into the data receiving buffer; The read execution module is configured to control the MCU to respond to the read interrupt and read the uploaded data from the data receive buffer.

9. An electronic device, characterized in that, The electronic device includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs or instructions; The processor is used to execute the computer program or instructions to enable the electronic device to implement the data receiving method as described in any one of claims 1 to 7.

10. A computer-readable storage medium for use in electronic devices, characterized in that, The storage medium carries one or more computer programs that can be executed by the electronic device, thereby enabling the electronic device to implement the data receiving method as described in any one of claims 1 to 7.