STM32 context switching power consumption optimization method and device and storage medium

The problem of increasing power consumption by setting low-power operating states during STM32 MCU context switching, calling low-power peripherals, dynamically managing power consumption, and efficiently saving contexts, the problem of context switching increases is solved, and power consumption optimization and battery life is achieved.

CN119916916APending Publication Date: 2025-05-02SIEMENS (CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311432710.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-31
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

When using a real-time operating system on a battery-powered STM32 MCU, context switching can increase power consumption, resulting in a rapid attenuation of battery life.

Method used

During the context switching period of STM32, the CPU is set to a low-power operating state, the low-power peripheral is called, dynamic power consumption management is performed, and efficient context storage is carried out, and the power consumption during the context switching is optimized.

Benefits of technology

It effectively reduces the power consumption during STM32 context switching, extends battery life, and improves battery power efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119916916A_ABST
    Figure CN119916916A_ABST
Patent Text Reader

Abstract

The invention provides an STM32 context switching power consumption optimization method and device and a storage medium. The method comprises the following steps: during the context switching period of the STM32, setting a CPU (Central Processing Unit) of the STM32 to be in a low-power-consumption running state; calling a low-power-consumption peripheral; performing dynamic power consumption management; and efficient context saving is performed. According to the technical scheme in the embodiment of the invention, the power consumption during context switching can be reduced, and the service life of the battery of the STM32 based on battery power supply is remarkably prolonged.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of real-time operating systems and low-power control, and in particular to a method, device and storage medium for optimizing the context switching power consumption of an STM32. Background Art

[0002] When using a real-time operating system (RTOS) on a battery-powered STM32-based MCU (Microcontroller Unit), context switching is a key operation in the RTOS, which may increase power consumption, which leads to a rapid decay of battery life. Therefore, it is necessary to reduce the power consumption during context switching on the STM32. Summary of the invention

[0003] To achieve the above object, the present invention proposes a context switching power consumption optimization method, device and storage medium for STM32, so as to reduce the power consumption during context switching on STM32.

[0004] A method for optimizing the power consumption of a context switch of STM32 proposed in an embodiment of the present invention comprises: during the context switch of STM32, setting the CPU of the STM32 to a low-power operation state; calling a low-power peripheral; performing dynamic power management; and performing efficient context saving. By comprehensively utilizing the CPU architecture, functions, and peripherals of STM32, the power consumption during the context switch is optimized.

[0005] A context switching power consumption optimization device for STM32 proposed in an embodiment of the present invention comprises: during context switching of STM32, a setting module is configured to set the CPU of the STM32 to a low-power operation state; a peripheral calling module is configured to call a low-power peripheral; a dynamic management module is configured to perform dynamic power consumption management; and a context saving module is configured to perform efficient context saving. By comprehensively utilizing the CPU architecture, functions and peripherals of STM32, the power consumption during context switching is optimized.

[0006] An electronic device proposed in an embodiment of the present invention includes: at least one processor; and a memory coupled to the at least one processor, wherein the memory is used to store instructions, and when the instructions are executed by the at least one processor, the processor executes the method described above.

[0007] An embodiment of the present invention provides a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed, the method described in any of the above embodiments is executed.

[0008] A computer program product provided in an embodiment of the present invention includes a computer program. When the computer program is executed by a processor, the method described in any one of the above embodiments is implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] The following drawings are intended only to illustrate and explain the present invention, and do not limit the scope of the present invention.

[0010] Figure 1 1 is a flow chart of a method 100 for optimizing power consumption of context switching of STM32 according to an embodiment of the present invention.

[0011] Figure 2 1 is a schematic diagram of the structure of a context switching power consumption optimization device 200 for STM32 according to an embodiment of the present invention.

[0012] Figure 3 Is a schematic diagram of an electronic device 300 according to an embodiment of the present invention.

[0013] The following are the descriptions of the reference numerals:

[0014] serial number meaning 100 A context switching power consumption optimization method for STM32 S101 Step S101 S102 Step S102 S103 Step S103 S104 Step S104 200 A context switching power consumption optimization device for STM32 201 Setting module 202 Peripheral call module 203 Dynamic Management Module 204 Context saving module 300 Electronic devices 310 processor 320 Memory DETAILED DESCRIPTION

[0015] In order to have a clearer understanding of the technical features, purposes and effects of the present invention, specific embodiments of the present invention are now described with reference to the accompanying drawings.

[0016] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0017] As shown in this application and claims, unless the context clearly indicates an exception, the words "a", "an", "an" and / or "the" do not refer to the singular and may also include the plural. Generally speaking, the terms "include" and "comprise" only indicate the inclusion of the steps and elements that have been clearly identified, and these steps and elements do not constitute an exclusive list. The method or device may also include other steps or elements.

[0018] In the past, in the RTOS context switching of battery-powered devices, the reduction of power consumption is usually achieved by means such as low-power operating mode, optimizing clock frequency, and selectively disabling peripheral devices. However, these means have not yet fully utilized the unique CPU architecture, functions and peripherals provided by the MCU of STM32. In addition, the existing solutions for context switching in RTOS are mainly focused on task scheduling and performance optimization, without much emphasis on power consumption. These solutions usually do not make full use of the unique functions of the MCU of STM32, resulting in poor power efficiency of battery power devices. In the embodiment of the present invention, it is considered that the power consumption during the context switching on STM32 needs to be reduced.

[0019] Therefore, in the embodiments of the present invention, a more optimized STM32 context switching power consumption optimization method, device and storage medium are provided.

[0020] Figure 1 It is a flowchart of a method 100 for optimizing power consumption of context switching of STM32 according to an embodiment of the present invention.

[0021] like Figure 1 As shown, during the context switching of the STM32, the method 100 may include:

[0022] Step S101, setting the CPU of the STM32 to a low power consumption operation state.

[0023] In one embodiment, setting the CPU of the STM32 to a low power consumption operation state includes: setting a low power consumption operation mode, and / or clock gating to enable the CPU of the STM32 to operate in a low power consumption state.

[0024] Specifically, the specific features of STM32 are utilized, such as low-power working modes and clock gating mechanisms, to minimize power consumption during context switching. The CPU architecture is fully utilized to efficiently manage power resources.

[0025] Step S102, calling low power consumption peripherals.

[0026] In one embodiment, calling the low power consumption peripheral includes: calling a low power consumption timer and a high efficiency communication interface to offload tasks on the CPU.

[0027] Specifically, during context switching, peripherals are strategically utilized to offload tasks and reduce CPU usage, thereby reducing power consumption.

[0028] Step S103: performing dynamic power consumption management.

[0029] In one embodiment, the dynamic power consumption management includes: dynamically adjusting the clock frequency, the working mode, and / or the peripheral configuration according to the CPU usage.

[0030] Specifically, the working state during context switching is adjusted according to the workload and system requirements. The power consumption during context switching is optimized by intelligently adjusting the clock frequency, power mode, and peripheral configuration.

[0031] Step S104: performing efficient context preservation.

[0032] In one embodiment, performing efficient context saving includes storing and restoring necessary CPU registers and system states.

[0033] Specifically, during a context switch, only necessary CPU registers and system states are stored and restored, minimizing the power overhead associated with context switches while ensuring proper task resumption.

[0034] Figure 2 It is a structural diagram of a context switching power consumption optimization device 200 of STM32 according to an embodiment of the present invention.

[0035] like Figure 2 As shown, during the context switching of STM32, the device 200 may include:

[0036] The setting module 201 is configured to set the CPU of the STM32 to a low power consumption operation state.

[0037] The peripheral calling module 202 is configured to call low-power peripherals.

[0038] The dynamic management module 202 is configured to perform dynamic power consumption management.

[0039] The context saving module 202 is configured to perform efficient context saving.

[0040] The present invention also provides an electronic device 300 . Figure 3 FIG. 3 is a schematic diagram of an electronic device 300 according to an embodiment of the present invention. Figure 3 As shown, the electronic device 300 includes a processor 310 and a memory 320 , wherein the memory 320 stores instructions, wherein when the instructions are executed by the processor 310 , the method 100 described above is implemented.

[0041] The present invention further provides a computer-readable storage medium on which computer instructions are stored. When the computer instructions are executed, the method described above is executed.

[0042] The present invention also provides a computer program product, comprising a computer program, and when the computer program is executed by a processor, the method described above is implemented.

[0043] Some aspects of the methods and apparatus of the present invention may be performed entirely by hardware, entirely by software (including firmware, resident software, microcode, etc.), or by a combination of hardware and software. The above hardware or software may be referred to as "data blocks", "modules", "engines", "units", "components" or "systems". The processor may be one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DAPDs), programmable logic devices (PLCs), field programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors or combinations thereof. In addition, various aspects of the present invention may be expressed as computer products located in one or more computer-readable media, which include computer-readable program codes. For example, computer-readable media may include, but are not limited to, magnetic storage devices (e.g., hard disks, floppy disks, tapes, etc.), optical disks (e.g., compact disks (CDs), digital versatile disks (DVDs) ...), smart cards, and flash memory devices (e.g., cards, sticks, key drives ...).

[0044] Flowchart is used here to illustrate the operations performed according to the method of the embodiment of the present application. It should be understood that the above operations are not necessarily performed accurately in order. On the contrary, various steps can be processed in reverse order or simultaneously. At the same time, other operations may be added to these processes, or a certain step or several steps of operations may be removed from these processes.

[0045] It should be understood that although this specification is described according to various embodiments, not every embodiment contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.

[0046] The above description is only an illustrative embodiment of the present invention and is not intended to limit the scope of the present invention. Any equivalent changes, modifications and combinations made by any person skilled in the art without departing from the concept and principle of the present invention shall fall within the scope of protection of the present invention.

Claims

1. A context switching power consumption optimization method (100) for STM32, characterized in that: During context switching of the STM32, the method comprises: The CPU of the STM32 is set to a low power consumption operation state (S101); Calling low power peripherals (S102); Performing dynamic power consumption management (S103); Efficient context saving is performed (S104).

2. The method according to claim 1, wherein: The step of setting the CPU of the STM32 to a low power consumption operation state comprises: A low power operation mode and / or clock gating is set to enable the CPU of the STM32 to operate in a low power state.

3. The method according to claim 1, wherein: The calling of low power consumption peripherals comprises: Low power timers and efficient communication interfaces are invoked to offload tasks from the CPU.

4. The method according to claim 1, wherein: The dynamic power consumption management comprises: Dynamically adjust clock frequency, operating mode, and / or peripheral configuration based on CPU usage.

5. The method according to claim 1, wherein: The efficient context saving includes: Stores and restores necessary CPU registers and system state.

6. A context switching power consumption optimization device (200) for STM32, characterized in that: During context switching of the STM32, the device comprises: A setting module (201) is configured to set the CPU of the STM32 to a low power consumption operation state; A peripheral calling module (202) is configured to call a low-power peripheral; A dynamic management module (203), configured to perform dynamic power consumption management; The context saving module (204) is configured to perform efficient context saving.

7. An electronic device (300), comprising: at least one processor (310); as well as A memory (320) coupled to the at least one processor (310), the memory (320) being used to store instructions, which, when executed by the at least one processor (310), causes the processor (310) to perform the method according to any one of claims 1 to 5.

8. A computer-readable storage medium having computer instructions stored thereon, wherein the computer instructions, when executed, execute the method according to any one of claims 1 to 5.

9. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 5 when being executed by a processor.