Search

CN-121996590-A - MCU data receiving method and device, electronic equipment and storage medium

CN121996590ACN 121996590 ACN121996590 ACN 121996590ACN-121996590-A

Abstract

The application discloses a data receiving method, a device, an electronic device and a storage medium of an MCU (micro control Unit), which are applied to the electronic device, and particularly provide a circulating buffer zone for the MCU, wherein the circulating buffer zone comprises a basic buffer zone and at least one expansion buffer zone, the circulating buffer zone is mapped into a data receiving buffer zone of a DMA (direct memory access) module of the MCU, an uploading request of responding to the data of the peripheral is received based on the data receiving buffer zone, when the uploading data is read into the data receiving buffer zone, a reading interrupt is generated, and the MCU is controlled to respond to the reading interrupt and read the uploading data from the data receiving buffer zone. According to the scheme, the DMA module is utilized to read a plurality of data into the data receiving buffer area at one time, and then the interruption is generated after the reading is completed, so that the MCU reads a large amount of data through one interruption, and the burden caused by frequent interruption processing when the MCU receives a large amount of data is reduced.

Inventors

  • HAN CHANGLEI

Assignees

  • 丽水蓬阳医疗科技有限公司

Dates

Publication Date
20260508
Application Date
20260205

Claims (10)

  1. 1. The data receiving method of the MCU is applied to the electronic equipment and is characterized by comprising the following steps: Configuring a circular buffer zone for the MCU, wherein the circular buffer zone comprises a basic buffer zone and at least one expansion buffer zone; mapping the circulating buffer area into a data receiving buffer area of a DMA module of the MCU; responding to a data uploading request of a peripheral, and receiving uploading data of the peripheral based on the data receiving buffer area; Generating a read interrupt when the uploaded data is read into the data receiving buffer; And controlling the MCU to respond to the reading interrupt and read the uploaded data from the data receiving buffer.
  2. 2. The data receiving method of claim 1, wherein said configuring a circular buffer for said MCU, said circular buffer comprising a base buffer and at least one extended buffer, comprises the steps of: configuring a basic buffer area in response to a basic configuration request of a user; configuring one or more expansion buffers in response to a user's expansion configuration request And according to a capacity configuration request of a user, splicing the basic buffer area with one or more expansion buffer areas based on capacity configuration parameters to obtain the circulation buffer area.
  3. 3. The data receiving method of claim 2, wherein the length of the basic buffer is a fixed length.
  4. 4. The data receiving method according to claim 2, wherein the capacity allocation parameter is related to a data amount of data transmitted by the peripheral device.
  5. 5. The data receiving method of claim 1, wherein the generating a read interrupt when the uploaded data is read into the data receiving buffer comprises the steps of: After the uploading data is read into the data receiving buffer zone, comparing the data length of the read data with the buffer zone length of the data receiving buffer zone; Generating a DMA interrupt if the data length is equal to the buffer length; If the data length is less than the buffer length, an idle interrupt is generated.
  6. 6. The data receiving method of claim 1, wherein said controlling said MCU to read said uploaded data from said data receiving buffer in response to said read interrupt comprises the steps of: Sequentially reading data from the data receiving buffer area; And each time one data is read, the starting position of the data to be read is moved backwards by one data unit.
  7. 7. The data receiving method of claim 6, wherein the data unit is an amount of data contained in a single read length.
  8. 8. A data receiving device of an MCU, applied to an electronic device, comprising: A buffer configuration module configured to configure a circular buffer for the MCU, the circular buffer comprising a base buffer and at least one expansion buffer; A buffer mapping module configured to map the circular buffer to a data receiving buffer of a DMA module of the MCU; the data receiving module is configured to respond to a data uploading request of the peripheral equipment and receive uploading data of the peripheral equipment based on the data receiving buffer area; an interrupt generation module configured to generate a read interrupt when the upload data is read into the data reception buffer; And the read execution module is configured to control the MCU to read the uploaded data from the data receiving buffer area in response to the read interrupt.
  9. 9. An electronic device comprising at least one processor and a memory coupled to the processor, wherein: The memory is used for storing a computer program or instructions; The processor is configured to execute the computer program or instructions to cause the electronic device to implement the data receiving method according to any one of claims 1 to 7.
  10. 10. A computer-readable storage medium applied to an electronic device, wherein the storage medium carries one or more computer programs executable by the electronic device to cause the electronic device to implement the data receiving method according to any one of claims 1 to 7.

Description

MCU data receiving method and device, electronic equipment and storage medium Technical Field The present application relates to the field of data communications technologies, and in particular, to a data receiving method and apparatus for an MCU, an electronic device, and a storage medium. Background The MCU is a computation core capable of providing computation and control services for equipment or devices needing intelligent control such as vehicles, household appliances, mechanical equipment and the like, obtains external data (such as temperature and humidity sensors and keys) through communication when the equipment is controlled, sends out instructions (such as control motors and OLED screen display), cooperates with other equipment (such as multi-MCU networking and computer/mobile phone connection) and the like. In general, an MCU performs external communication through interrupts, and processes interrupts once every byte is received, and frequently processes interrupts when receiving a large amount of data, resulting in an increased burden. Disclosure of Invention In view of the above, the present application provides a data receiving method, apparatus, electronic device and storage medium for controlling an MCU to receive data through a serial port, so as to reduce the burden of the MCU caused by frequent processing of interrupts when receiving a large amount of data. In order to achieve the above object, the following solutions have been proposed: The data receiving method of the MCU is applied to the electronic equipment, and comprises the following steps: Configuring a circular buffer zone for the MCU, wherein the circular buffer zone comprises a basic buffer zone and at least one expansion buffer zone; mapping the circulating buffer area into a data receiving buffer area of a DMA module of the MCU; responding to a data uploading request of a peripheral, and receiving uploading data of the peripheral based on the data receiving buffer area; Generating a read interrupt when the uploaded data is read into the data receiving buffer; And controlling the MCU to respond to the reading interrupt and read the uploaded data from the data receiving buffer. Optionally, the configuring a circular buffer for the MCU, where the circular buffer includes a basic buffer and at least one extended buffer, includes the steps of: configuring a basic buffer area in response to a basic configuration request of a user; configuring one or more expansion buffers in response to a user's expansion configuration request And according to a capacity configuration request of a user, splicing the basic buffer area with one or more expansion buffer areas based on capacity configuration parameters to obtain the circulation buffer area. Optionally, the length of the basic buffer area is a fixed length. Optionally, the capacity configuration parameter is related to a data amount of data sent by the peripheral device. Optionally, the step of generating a read interrupt when the upload data is read into the data receiving buffer includes the steps of: After the uploading data is read into the data receiving buffer zone, comparing the data length of the read data with the buffer zone length of the data receiving buffer zone; Generating a DMA interrupt if the data length is equal to the buffer length; If the data length is less than the buffer length, an idle interrupt is generated. Optionally, the controlling the MCU to read the uploaded data from the data receiving buffer in response to the read interrupt includes the steps of: Sequentially reading data from the data receiving buffer area; And each time one data is read, the starting position of the data to be read is moved backwards by one data unit. Optionally, the data unit is the data amount contained in the single read length. A data receiving device of an MCU, applied to an electronic device, comprising: A buffer configuration module configured to configure a circular buffer for the MCU, the circular buffer comprising a base buffer and at least one expansion buffer; A buffer mapping module configured to map the circular buffer to a data receiving buffer of a DMA module of the MCU; the data receiving module is configured to respond to a data uploading request of the peripheral equipment and receive uploading data of the peripheral equipment based on the data receiving buffer area; an interrupt generation module configured to generate a read interrupt when the upload data is read into the data reception buffer; And the read execution module is configured to control the MCU to read the uploaded data from the data receiving buffer area in response to the read interrupt. An electronic device comprising at least one processor and a memory coupled to the processor, wherein: The memory is used for storing a computer program or instructions; The processor is configured to execute the computer program or instructions to cause the electronic device to implement the data receiving method