A GPIO edge splitting event detection device and method

By using a GPIO edge splitting event detection device, which employs pin grouping configuration and event flag bit latching, the problems of complex configuration and high power consumption of GPIO edge interrupt detection circuits are solved, and reliable wake-up and event detection are achieved in a low-power state.

CN123114233APending Publication Date: 2026-11-17SHANDONG LUHAI EQUIPMENT GROUP RIZHAO CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611576681.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-13
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing GPIO edge interrupt detection circuits suffer from complex configuration, event loss, and high power consumption, and are particularly difficult to effectively wake up from low-power sleep states.

Method used

The GPIO edge splitting event detection device includes a GPIO input pin group, a two-level cascaded synchronous sampling unit, an edge configuration register group, an edge detection unit, an interrupt status register, and an interrupt aggregation unit. It generates level-type interrupt signals through pin group configuration, event flag bit latching, and bitwise logic operations.

Benefits of technology

The software configuration logic is simplified, edge events are not lost, system power consumption is reduced, and accurate wake-up of the microcontroller is achieved in a low-power state.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123114233A_ABST
    Figure CN123114233A_ABST
Patent Text Reader

Abstract

This invention discloses a GPIO edge splitting event detection device and method. The detection device includes: a GPIO input pin group; two cascaded synchronous sampling units electrically connected to the GPIO input pin group; an edge configuration register group; an edge detection unit electrically connected to the two cascaded synchronous sampling units and the edge configuration register group respectively; an interrupt status register electrically connected to the edge detection unit; an interrupt enable register; an interrupt aggregation unit electrically connected to the interrupt status register and the interrupt enable register; and a level-type interrupt output port electrically connected to the interrupt aggregation unit and the microcontroller. The level-type interrupt signal is used to output as an interrupt request during normal operation of the microcontroller and as a wake-up source for WFI low-power instructions. This invention enables the microcontroller to remain in a low-power sleep state for extended periods, only being woken up when an edge event occurs, effectively reducing the overall system power consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of integrated circuit interface interrupt control technology, and in particular to a GPIO edge splitting event detection device and method. Background Technology

[0002] Embedded microcontrollers commonly utilize the edge interrupt function of GPIO (General-Purpose Input / Output) pins to acquire external events, such as button triggers, limit switch actions, and rotary encoder pulse signals. Existing GPIO edge interrupt detection circuits mainly suffer from three technical shortcomings:

[0003] Traditional GPIO edge configuration registers are not designed to be separated according to pin groups, and the edge configuration bits of all pins are mixed together in the register. When the software modifies the edge trigger mode of some pins, it must perform masking operations to protect the bits that do not need to be modified. The software configuration logic is cumbersome, the code overhead is large, and configuration errors are easy to occur. If you want to simplify software access, you need to reserve extra register holes, resulting in a waste of register address resources.

[0004] Most existing GPIO edge events lack event sticky latching capabilities. When the microcontroller temporarily disables interrupt enable (interrupt masking state), if an edge transition event occurs on a GPIO pin, the event will be lost. After the interrupt enable is subsequently re-enabled, the microcontroller will be completely unable to detect the external events that occurred during the masking period, resulting in missed external input events. This can cause functional abnormalities in key and encoder sampling scenarios.

[0005] Most existing GPIO interrupts output pulse-type interrupt signals, requiring microcontroller software to poll and read the status register to identify the event. In some architectures, pulse-type interrupt signals are difficult to reliably serve as the wake-up source for the microcontroller's WFI (WaitForInterrupt) low-power instruction. If the pulse width is shorter than the processor's sleep / wake-up response window, there is a risk of missing wake-up requests. When the microcontroller enters sleep mode, using pulse interrupts often requires the microcontroller to frequently wake up and poll the GPIO status, significantly increasing system power consumption and making it difficult to adapt to event-driven low-power scheduling schemes. Summary of the Invention

[0006] The technical problem to be solved by the embodiments of the present invention is to provide a GPIO edge splitting event detection device and method, which enables the microcontroller to remain in a low-power sleep state for a long time and be woken up only when an edge event occurs, effectively reducing the overall power consumption of the system.

[0007] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows:

[0008] Embodiments of the present invention provide a GPIO edge splitting event detection device, comprising:

[0009] GPIO input pin group is used to receive raw electrical signals from external devices;

[0010] Two cascaded synchronous sampling units electrically connected to the GPIO input pin group are used to perform signal synchronization processing on the original electrical signal and output a synchronous stable signal.

[0011] The edge configuration register group is used to store the edge configuration parameters corresponding to different GPIO input pin groups and output them to the edge detection unit.

[0012] An edge detection unit, which is electrically connected to the two-stage cascaded synchronous sampling unit and the edge configuration register group respectively, is used to perform edge detection on the synchronous stable signal according to the edge configuration parameters and filter to generate event pulses corresponding to the GPIO input pins;

[0013] An interrupt status register electrically connected to the edge detection unit is used to set the event flag bit of the corresponding GPIO input pin according to the event pulse. The event flag bit is latched after being set and cleared in response to a write 1 operation of the microcontroller.

[0014] The interrupt enable register is used to store the interrupt enable flag bits corresponding to each GPIO input pin;

[0015] The interrupt aggregation unit, which is electrically connected to the interrupt status register and the interrupt enable register, is used to perform bitwise AND logic operations on the event flag bit and interrupt enable flag bit corresponding to the same GPIO input pin, and aggregate the operation results of all GPIO input pins to generate a single level interrupt signal.

[0016] The level-type interrupt output port, which is electrically connected to the interrupt aggregation unit and the microcontroller, is used to output the level-type interrupt signal as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions.

[0017] Optionally, the edge configuration register group includes: a first edge configuration register and a second edge configuration register with consecutively set addresses; the first edge configuration register is used to store the edge configuration parameters of the first group of GPIO input pins, and the second edge configuration register is used to store the edge configuration parameters of the second group of GPIO input pins.

[0018] Optionally, the two-stage cascaded synchronous sampling unit includes: a first flip-flop and a second flip-flop cascaded in two stages; the first flip-flop receives the original electrical signal for sampling and outputs a first-stage sampling signal; the second flip-flop receives the first-stage sampling signal and samples it again, outputting a synchronous stable signal.

[0019] Embodiments of the present invention also provide a GPIO edge splitting event detection method, applied to the GPIO edge splitting event detection device described above, the method comprising:

[0020] Write the edge configuration parameters corresponding to different GPIO input pin groups into the edge configuration register group, and at the same time configure the interrupt enable flag bit corresponding to each GPIO input pin in the interrupt enable register.

[0021] It receives raw electrical signals from external devices, performs signal synchronization processing on the raw electrical signals, and outputs a stable synchronization signal.

[0022] Read the edge configuration parameters in the edge configuration register group, perform edge detection on the synchronization stable signal according to the edge configuration parameters, and filter to generate event pulses for the corresponding GPIO input pins;

[0023] Based on the event pulse, the event flag bit of the corresponding GPIO input pin is set; the event flag bit is latched after being set, and cleared in response to a microcontroller write-1 operation;

[0024] Read the event flag and interrupt enable flag corresponding to the same GPIO input pin, perform bitwise AND logic operation on each pin, and aggregate the operation results of all GPIO input pins to generate a single level interrupt signal;

[0025] The level-type interrupt signal is output; the level-type interrupt signal serves as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions.

[0026] Optionally, the edge configuration parameters corresponding to different GPIO input pin groups are written into the edge configuration register group, and the interrupt enable flag bits corresponding to each GPIO input pin in the interrupt enable register are configured, including:

[0027] Write the edge configuration parameters corresponding to the first group of GPIO input pins into the first edge configuration register;

[0028] Write the edge configuration parameters corresponding to the second group of GPIO input pins into the second edge configuration register;

[0029] For each GPIO input pin, write the interrupt enable flag bit to the corresponding bit in the interrupt enable register.

[0030] Optionally, it receives raw electrical signals input from external devices, performs signal synchronization processing on the raw electrical signals, and outputs a stable synchronization signal, including:

[0031] Receive raw electrical signals input from external devices;

[0032] The original electrical signal is input to the first flip-flop, and the first flip-flop performs the first sampling on the original electrical signal and outputs the first-level sampling signal.

[0033] The first-stage sampling signal is input to the second flip-flop, which resamples the first-stage sampling signal and outputs a synchronous stable signal.

[0034] Optionally, the edge configuration parameters in the edge configuration register group are read, and edge detection is performed on the synchronization stabilization signal according to the edge configuration parameters to filter and generate event pulses for the corresponding GPIO input pins, including:

[0035] Read the edge configuration parameters from the edge configuration register group;

[0036] Edge detection is performed on the synchronous stable signal to obtain rising edge transitions and falling edge transitions;

[0037] The rising edge transition and falling edge transition are filtered and judged according to the edge configuration parameters to generate the event pulse corresponding to the GPIO input pin.

[0038] Optionally, based on the event pulse, the event flag bit of the corresponding GPIO input pin is set; the event flag bit is latched after being set, and cleared in response to a microcontroller write-1 operation, including:

[0039] According to the event pulse, the event flag bit of the corresponding GPIO input pin is set to a valid state, and the event flag bit is latched after it is set;

[0040] In response to a write-1 operation by the microcontroller, the event flag bit of the corresponding GPIO input pin is cleared to an invalid state.

[0041] Optionally, the event flag and interrupt enable flag corresponding to the same GPIO input pin are read, and a bitwise AND operation is performed pin by pin. The results of the operations on all GPIO input pins are then aggregated to generate a single level-type interrupt signal, including:

[0042] Read the event flag and interrupt enable flag corresponding to the same GPIO input pin;

[0043] For each GPIO input pin, perform a bitwise AND operation on the corresponding event flag bit and interrupt enable flag bit to obtain the corresponding valid interrupt sub-signal;

[0044] All valid interrupt sub-signals corresponding to the GPIO input pins are aggregated, and any valid interrupt sub-signal corresponding to any GPIO input pin is valid, outputting a valid level-type interrupt signal.

[0045] Optionally, the level-type interrupt signal is output; the level-type interrupt signal serves as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions, including:

[0046] The level-type interrupt signal is transmitted to two parallel signal paths respectively;

[0047] The first signal path sends the level-type interrupt signal to the microcontroller's normal interrupt request input. When the microcontroller is in normal operation, after the microcontroller recognizes the valid level-type interrupt signal, it responds to the interrupt request and enters the interrupt service routine to handle the GPIO edge event.

[0048] The second signal path directly sends the level-type interrupt signal to the microcontroller's WFI low-power wake-up circuit; when the microcontroller executes the WFI instruction to enter sleep mode, if a valid level-type interrupt signal is detected, it triggers the microcontroller to exit sleep mode and complete the wake-up process.

[0049] The above-described solutions of the embodiments of the present invention have at least the following beneficial effects:

[0050] In the above-described scheme of this invention, the two-stage cascaded synchronous sampling unit performs two-stage pipelined synchronous processing on the external asynchronous raw electrical signal, reducing the risk of metastability propagation and outputting a synchronously stable signal after clock domain synchronization to the subsequent edge detection unit. This ensures that the subsequent edge detection logic can reliably sample external input signals and improves the reliability of edge event acquisition. The edge configuration register group stores edge configuration parameters according to pin groups. The edge detection unit can flexibly select no event generation, rising edge triggering, falling edge triggering, or dual edge triggering modes according to the configuration, adapting to diverse external signal acquisition needs. The interrupt status register adopts an event flag bit latching mechanism. Once an event pulse is received, the event flag bit is set and held in a latched state. The flag bit can only be cleared by writing 1 to the microcontroller. Even if the event pulse disappears, the captured edge event will not be lost. The interrupt aggregation unit performs a bitwise AND operation on the event flag bit and the interrupt enable flag bit pin by pin and then aggregates them uniformly. Only when the event flag bit and the interrupt enable flag bit are both valid will a valid level-type interrupt signal be generated, realizing hardware-level interrupt masking control. The final output level-type interrupt signal can serve as a regular interrupt request during normal microcontroller operation, and can also directly act as a wake-up source for WFI low-power instructions. Compared to pulse-type interrupt signals, the continuously valid level signal will not lose the interrupt request because the microcontroller has not yet completed wake-up preparation. The microcontroller can remain in a low-power sleep state for a long time and will only be woken up when an external edge event occurs, effectively reducing the overall power consumption of the system. Attached Figure Description

[0051] Figure 1 This is a schematic diagram of a GPIO edge splitting event detection device provided in an embodiment of the present invention.

[0052] Figure 2 This is a schematic diagram of the edge detection timing of the GPIO edge splitting event detection device according to an embodiment of the present invention.

[0053] Figure 3 This is a flowchart illustrating the GPIO edge splitting event detection method provided in an embodiment of the present invention. Detailed Implementation

[0054] Exemplary embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this invention will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.

[0055] like Figure 1 As shown, an embodiment of the present invention provides a GPIO edge splitting event detection device, comprising:

[0056] GPIO input pin group is used to receive raw electrical signals from external devices;

[0057] Two cascaded synchronous sampling units electrically connected to the GPIO input pin group are used to perform signal synchronization processing on the original electrical signal and output a synchronous stable signal.

[0058] The edge configuration register group is used to store the edge configuration parameters corresponding to different GPIO input pin groups and output them to the edge detection unit.

[0059] An edge detection unit, which is electrically connected to the two-stage cascaded synchronous sampling unit and the edge configuration register group respectively, is used to perform edge detection on the synchronous stable signal according to the edge configuration parameters and filter to generate event pulses corresponding to the GPIO input pins;

[0060] An interrupt status register electrically connected to the edge detection unit is used to set the event flag bit of the corresponding GPIO input pin according to the event pulse. The event flag bit is latched after being set and cleared in response to a write 1 operation of the microcontroller.

[0061] The interrupt enable register is used to store the interrupt enable flag bits corresponding to each GPIO input pin;

[0062] The interrupt aggregation unit, which is electrically connected to the interrupt status register and the interrupt enable register, is used to perform bitwise AND logic operations on the event flag bit and interrupt enable flag bit corresponding to the same GPIO input pin, and aggregate the operation results of all GPIO input pins to generate a single level interrupt signal.

[0063] The level-type interrupt output port, which is electrically connected to the interrupt aggregation unit and the microcontroller, is used to output the level-type interrupt signal as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions.

[0064] In practical operation, the raw electrical signals generated by external devices are sent to the GPIO input pin group. The raw electrical signals are asynchronous signals from outside the chip. They are first sent to a two-stage cascaded synchronous sampling unit to complete two-stage pipeline synchronization processing, reducing the risk of metastability propagation across clock domains, and outputting a synchronously stable signal after clock domain synchronization. The edge detection unit reads the edge configuration parameters corresponding to each GPIO pin in the edge configuration register group, identifies rising and falling edge transitions for the synchronously stable signal, filters out edges that meet the configuration conditions, and outputs the event pulse of the corresponding GPIO pin. After the event pulse is input to the interrupt status register, the event flag bit of the corresponding pin is latched. The interrupt aggregation unit reads the event flag bit of the interrupt status register and the interrupt enable flag bit of the interrupt enable register in parallel, performs bitwise AND logic operations on each pin, and then aggregates the results of all pin operations to generate a level-type interrupt signal. The level-type interrupt output port outputs the level-type interrupt signal in parallel to the microcontroller's normal interrupt request input terminal and the WFI low-power wake-up circuit.

[0065] In this embodiment, the two-stage cascaded synchronous sampling unit performs two-stage pipelined synchronous processing on the external asynchronous raw electrical signal, reducing the risk of metastability propagation. This provides the subsequent edge detection unit with a clock-domain synchronized stable signal, ensuring that the subsequent edge detection logic can reliably sample external input signals and improving the reliability of edge event acquisition. The edge configuration register group stores edge configuration parameters according to pin groups. The edge detection unit can flexibly select no event generation, rising edge trigger, falling edge trigger, or dual edge trigger mode according to the configuration, adapting to diverse external signal acquisition needs. The interrupt status register adopts an event flag bit latching mechanism. Once an event pulse is received, the event flag bit is set and held in a latched state. The flag bit can only be cleared by writing 1 to the microcontroller. Even if the event pulse disappears, the captured edge event will not be lost. The interrupt aggregation unit performs a bitwise AND operation on the event flag bit and interrupt enable flag bit pin by pin and then aggregates them uniformly. Only when the event flag bit and interrupt enable flag bit are both valid will a valid level-type interrupt signal be generated, realizing hardware-level interrupt masking control. The final output level-type interrupt signal can serve as a regular interrupt request during normal microcontroller operation, and can also directly act as a wake-up source for WFI low-power instructions. Compared to pulse-type interrupt signals, the continuously valid level signal will not lose the interrupt request because the microcontroller has not yet completed wake-up preparation. The microcontroller can remain in a low-power sleep state for a long time and will only be woken up when an external edge event occurs, effectively reducing the overall power consumption of the system.

[0066] In an optional embodiment of the present invention, the edge configuration register group includes: a first edge configuration register and a second edge configuration register whose addresses are set consecutively; the first edge configuration register is used to store the edge configuration parameters of the first group of GPIO input pins, and the second edge configuration register is used to store the edge configuration parameters of the second group of GPIO input pins.

[0067] Specifically, this embodiment uses 32 GPIO input pins, which are divided into a first group of GPIO[15:0] and a second group of GPIO[31:16]. The first edge configuration register stores the edge configuration parameters corresponding to GPIO[15:0], and the second edge configuration register, whose address follows immediately, stores the edge configuration parameters corresponding to GPIO[31:16]. When the software only modifies the configuration of one group of pins, it only needs to access one register, without having to perform masking operations to protect irrelevant bits, thus simplifying the software configuration logic.

[0068] In this embodiment, the edge configuration register group is set as a first edge configuration register and a second edge configuration register with contiguous addresses, storing the edge configuration parameters of two sets of GPIO input pins respectively. The 32 GPIO input pins are divided into two groups, GPIO[15:0] and GPIO[31:16], and assigned to the corresponding two registers. When the software needs to modify the edge configuration of a pin in a certain group, it only needs to access the corresponding register, without needing to mask or protect other irrelevant bits through masking operations. This simplifies the software configuration code logic, reduces the code overhead caused by masking operations, and lowers the probability of configuration errors caused by improper masking; at the same time, the register addresses are arranged continuously, there are no register address gaps, and the register address resources are fully utilized.

[0069] In an optional embodiment of the present invention, the two-stage cascaded synchronous sampling unit includes: a first flip-flop and a second flip-flop cascaded in two stages; the first flip-flop receives the original electrical signal for sampling and outputs a first-stage sampling signal; the second flip-flop receives the first-stage sampling signal for further sampling and outputs a synchronous stable signal.

[0070] Specifically, the first and second flip-flops use the same internal system clock for pipelined cascaded sampling. The external raw electrical signal from the GPIO input pin group is an asynchronous input signal. Directly inputting asynchronous signals into the register for sampling can easily lead to metastability issues. The raw electrical signal is first fed into the first flip-flop, where a first-stage synchronous sampling is performed at the system clock edge to obtain the first-stage sampled signal. The first-stage sampled signal is then fed into the second flip-flop, where a second-stage synchronous sampling is performed at the next system clock edge. The signal output by the second flip-flop is the synchronously stable signal. This two-stage pipelined synchronization effectively reduces the risk of metastability introduced by asynchronous signals propagating to subsequent edge detection units, providing a stable input signal synchronized with the system clock domain for subsequent circuits.

[0071] In this embodiment, the two-stage flip-flops adopt a pipelined cascade structure. The original electrical signal passes through the first flip-flop and the second flip-flop sequentially to complete the two-stage synchronous sampling, rather than the two flip-flops sampling the original electrical signal in parallel. This circuit structure is specifically designed to perform cross-clock domain synchronization processing for asynchronous GPIO input signals from outside the chip, focusing on solving the metastability risk caused by asynchronous input. It provides a synchronous and stable signal after clock domain alignment for the edge detection unit, ensuring stable and reliable edge detection results.

[0072] like Figure 2 As shown in the edge detection timing diagram, this timing diagram fully demonstrates the core working timing of this device: the original electrical signal is the external input signal received by the GPIO input pin group. This original electrical signal is input to two cascaded synchronous sampling units, and after synchronous processing, a synchronous stable signal is output.

[0073] When a rising edge appears on the synchronization stabilization signal, the edge detection unit generates a rising edge event pulse, which sets the corresponding event flag in the interrupt status register. At this time, the interrupt enable flag is active. The interrupt aggregation unit performs a bitwise AND operation on the event flag and the interrupt enable flag, and outputs a valid level-type interrupt signal. When the interrupt enable flag is deactivated, the interrupt masking phase begins. During this phase, even if a falling edge appears on the subsequent synchronization stabilization signal or the edge detection unit generates a falling edge event pulse, the event flag remains latched and will not be cleared when the event pulse disappears. However, because the interrupt enable flag is deactivated, the level-type interrupt signal becomes invalid. When the interrupt enable flag is reconfigured to active, the interrupt aggregation unit immediately outputs a valid level-type interrupt signal again based on the latched event flag. After the microcontroller completes the GPIO edge event processing, it performs a write-1 clear operation, clearing the corresponding event flag, and the level-type interrupt signal is then canceled. This timing sequence visually confirms that edge events occurring during the masking period when the interrupt enable flag is invalid will be fully latched and saved by the interrupt status register; once the interrupt enable flag is restored to validity, a level-type interrupt signal can be output immediately without losing the edge events captured during the masking period.

[0074] like Figure 3 As shown, embodiments of the present invention also provide a GPIO edge splitting event detection method, applied to the GPIO edge splitting event detection device described above, the method comprising:

[0075] Step 11: Write the edge configuration parameters corresponding to different GPIO input pin groups into the edge configuration register group, and at the same time configure the interrupt enable flag bit corresponding to each GPIO input pin in the interrupt enable register.

[0076] Step 12: Receive the raw electrical signal input from the external device, perform signal synchronization processing on the raw electrical signal, and output a stable synchronization signal;

[0077] Step 13: Read the edge configuration parameters in the edge configuration register group, perform edge detection on the synchronization stable signal according to the edge configuration parameters, and filter to generate event pulses for the corresponding GPIO input pins;

[0078] Step 14: Based on the event pulse, set the event flag bit of the corresponding GPIO input pin; the event flag bit is latched after being set, and is cleared only in response to a microcontroller write 1 operation;

[0079] Step 15: Read the event flag and interrupt enable flag corresponding to the same GPIO input pin, perform bitwise AND logic operation on each pin, and aggregate the operation results of all GPIO input pins to generate a single level interrupt signal;

[0080] Step 16: Output the level-type interrupt signal; the level-type interrupt signal serves as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions.

[0081] In this embodiment, the GPIO edge event detection process is fully implemented by sequentially executing the steps of configuration, two-stage asynchronous signal synchronization processing, edge detection, event latching, interrupt aggregation, and level signal output. Edge configuration parameters and interrupt enable flags are pre-configured to establish working rules for hardware edge detection. Two-stage pipeline synchronization processing is performed on the external asynchronous raw electrical signal to reduce the risk of metastability propagation and ensure the quality of the input signal for subsequent edge detection. The hardware performs edge detection filtering based on the pre-written edge configuration parameters, generating event pulses for the corresponding pins to achieve differentiated identification of the edge triggering modes of each GPIO pin. Upon detecting an event pulse, the corresponding event flag is latched. The event flag can only be cleared by a write-1 operation from the microcontroller, reliably preserving the edge events that have occurred. The event flag and interrupt enable flag are bitwise ANDed pin by pin and aggregated to generate a level-type interrupt signal. The output level-type interrupt signal can serve as both a normal interrupt request and a WFI low-power instruction wake-up source, simultaneously meeting the microcontroller's requirements for normal service response and low-power sleep wake-up.

[0082] In an optional embodiment of the present invention, step 11 involves writing the edge configuration parameters corresponding to different GPIO input pin groups into the edge configuration register group, and simultaneously configuring the interrupt enable flag bits corresponding to each GPIO input pin in the interrupt enable register, including:

[0083] Step 11.1: Write the edge configuration parameters corresponding to the first group of GPIO input pins into the first edge configuration register;

[0084] Specifically, each GPIO input pin in the first group is assigned a 2-bit edge mode code. The edge mode code supports four configurations: no event generation mode, rising edge trigger mode, falling edge trigger mode, and double edge trigger mode. All the 2-bit edge mode codes of the pins in the first group are packaged and written into the first edge configuration register.

[0085] Step 11.2: Write the edge configuration parameters corresponding to the second group GPIO input pins into the second edge configuration register;

[0086] Specifically, the second group of GPIO input pins also uses 2-bit edge mode encoding to independently configure the edge detection mode of each pin, and writes the edge configuration parameters of all pins in the second group into the second edge configuration register whose address is continuous with that of the first edge configuration register.

[0087] Step 11.3: For each GPIO input pin, write the interrupt enable flag bit to the corresponding bit in the interrupt enable register.

[0088] Specifically, each bit of the interrupt enable register corresponds to one GPIO input pin; when the flag bit is valid, the event generated by the pin is allowed to be output as an interrupt; when the flag bit is invalid, the interrupt output by the pin is blocked, but edge event detection and the latching action of the interrupt status register on the event flag bit are not blocked.

[0089] In this embodiment, the edge configuration parameters of different grouped GPIO input pins are written into the first edge configuration register and the second edge configuration register, which are address-contiguous. Each group of pins uses 2-bit edge mode encoding and can be independently configured to four modes: no event generation, rising edge triggering, falling edge triggering, and double edge triggering. Grouped and packaged writing to registers means that when the software modifies the configuration of a pin in a certain group, it only needs to operate on the corresponding register, eliminating the need for masking operations, simplifying the software configuration logic and reducing the risk of configuration errors. Simultaneously, the interrupt enable register is configured bit-by-bit with an interrupt enable flag, enabling independent control of the interrupt output of each GPIO input pin. When the flag is invalid, only the pin event output interrupt is masked; it does not block the hardware detection of edge events, nor does it affect the latching and storage of the event flag. Edge events occurring during the masking phase can still be recorded. When the flag is valid, interrupt output is allowed, balancing the needs of interrupt masking control and complete event recording.

[0090] In an optional embodiment of the present invention, step 12, receiving the original electrical signal input from an external device, performing signal synchronization processing on the original electrical signal, and outputting a stable synchronization signal, includes:

[0091] Step 12.1: Receive the raw electrical signal input from the external device;

[0092] Specifically, the original electrical signal comes from external hardware devices such as buttons, limit switches, and rotary encoders. It is an asynchronous input signal relative to the chip system clock domain. Direct sampling can easily introduce metastability risks.

[0093] Step 12.2: Input the original electrical signal into the first flip-flop. The first flip-flop performs the first sampling of the original electrical signal and outputs the first-level sampling signal.

[0094] Specifically, the first flip-flop samples the asynchronous original electrical signal on the effective edge of the system clock to complete the first stage of synchronization and output the first stage sampled signal;

[0095] Step 12.3: Input the first-level sampling signal into the second flip-flop. The second flip-flop resamples the first-level sampling signal and outputs a synchronous stable signal.

[0096] Specifically, the second flip-flop also uses the system clock to complete the second-stage synchronous sampling of the first-stage sampling signal and output a synchronous stable signal. After the pipeline synchronization of the two flip-flops, the probability of metastability caused by asynchronous input propagating to subsequent circuits is reduced, and a synchronous stable signal aligned with the system clock domain is output for use by the edge detection unit.

[0097] In this embodiment, a pipelined two-stage synchronous sampling process is implemented for the asynchronous raw electrical signal from external hardware. The raw electrical signal sequentially passes through a first flip-flop and a second flip-flop to complete two-stage clock synchronization, outputting a stable synchronous signal. This processing flow relies on hardware pipelined synchronization logic, eliminating the need for additional filtering operations in software and reducing microcontroller software overhead. The two-stage cascaded synchronous sampling reduces the risk of metastability propagation, providing a stable signal after clock domain synchronization for subsequent edge detection units, ensuring the reliability of GPIO edge event acquisition.

[0098] In an optional embodiment of the present invention, step 13, reading the edge configuration parameters in the edge configuration register group, performing edge detection on the synchronization stabilization signal according to the edge configuration parameters, and filtering to generate event pulses corresponding to the GPIO input pins, includes:

[0099] Step 13.1: Read the edge configuration parameters from the edge configuration register group;

[0100] Specifically, the edge detection unit reads the 2-bit edge mode code corresponding to the current GPIO input pin in parallel to determine the type of edge that the pin needs to capture;

[0101] Step 13.2: Perform edge detection on the synchronous stable signal to obtain the rising edge transition and falling edge transition;

[0102] Specifically, the edge detection unit compares the synchronous stable signal levels of two consecutive clock cycles. A change from low to high level is identified as a rising edge, and a change from high to low level is identified as a falling edge.

[0103] Step 13.3: Filter and judge the rising edge transition and falling edge transition according to the edge configuration parameters, and generate the event pulse of the corresponding GPIO input pin;

[0104] Specifically, if the detected edge transition matches the trigger condition configured in the edge mode encoding, an event pulse with a clock cycle width is output; if the detected edge transition does not match the configuration condition, the edge transition is discarded and no event pulse is output.

[0105] In this embodiment, the edge detection unit reads the 2-bit edge mode code corresponding to each GPIO input pin in parallel to determine the edge type to be captured for each pin. By comparing the levels of the synchronous stable signal in two consecutive clock cycles, rising edge transitions and falling edge transitions are identified respectively, achieving complete capture of both edge changes. The detected edge transitions are compared with the trigger conditions corresponding to the edge mode codes. Only when the edge transition matches the configuration conditions is an event pulse of one clock cycle width output; edge transitions that do not match the configuration are discarded without generating an event pulse. This method ensures that the edge detection rules for each GPIO pin are independent, and each pin can flexibly select the edge type to respond to. The hardware directly completes the edge filtering without the need for software to participate in the judgment and processing, reducing the computational burden on the microcontroller. At the same time, it can filter out edge changes that do not meet the configuration requirements, avoid invalid edges generating redundant event pulses, and improve the accuracy of GPIO edge event acquisition.

[0106] In an optional embodiment of the present invention, in step 14, the event flag bit of the corresponding GPIO input pin is set according to the event pulse; the event flag bit is latched after being set, and is cleared only in response to a microcontroller write-1 operation, including:

[0107] Step 14.1: Based on the event pulse, set the event flag bit of the corresponding GPIO input pin to a valid state, and hold the event flag bit latched after it is set;

[0108] Specifically, once an event pulse is received from the edge detection unit, regardless of whether the interrupt enable flag is valid or invalid at this time, the interrupt status register will set the event flag of the corresponding GPIO input pin to valid; after the event pulse disappears, the event flag will not be automatically reset, but will be continuously latched and saved to record the current edge event, so that the event will not be lost during the interrupt masking period;

[0109] Step 14.2: Only respond to the microcontroller's write 1 operation and clear the event flag bit of the corresponding GPIO input pin to an invalid state;

[0110] Specifically, after the microcontroller processes the corresponding GPIO edge event, it writes 1 to the corresponding bit in the interrupt status register to clear the event flag bit to invalid; writing 0 to the bit will not change the state of the event flag bit, thereby avoiding software from accidentally clearing the event records of other pins.

[0111] In this embodiment, upon receiving an event pulse, regardless of whether the interrupt enable flag is active or inactive, the event flag of the corresponding GPIO input pin is set to active and latched. The event flag does not automatically reset after the event pulse disappears, continuously latching and saving edge event records. Even in interrupt-masked mode, edge events can be completely recorded without event loss. The event flag can only be cleared to an inactive state via a write-1 operation by the microcontroller; writing a 0 to the corresponding bit does not change the event flag state. This write-1 clear mechanism prevents accidental clearing of unprocessed pin event flags by writing a 0 in software, thus preventing unprocessed edge event records from being accidentally erased. The entire event latching and clearing logic is directly implemented in hardware, eliminating the need for additional software caching of event information and ensuring the reliability and security of edge event records.

[0112] In an optional embodiment of the present invention, step 15 involves reading the event flag bit and interrupt enable flag bit corresponding to the same GPIO input pin, performing a bitwise AND logic operation pin by pin, and aggregating the operation results of all GPIO input pins to generate a single level-type interrupt signal, including:

[0113] Step 15.1: Read the event flag and interrupt enable flag corresponding to the same GPIO input pin;

[0114] Specifically, the interrupt aggregation unit reads all event flag bits of the interrupt status register and all interrupt enable flag bits of the interrupt enable register in parallel;

[0115] Step 15.2: For each GPIO input pin, perform a bitwise AND operation on the corresponding event flag bit and interrupt enable flag bit to obtain the corresponding valid interrupt sub-signal;

[0116] Specifically, the corresponding valid interrupt sub-signal is valid only if the event flag bit and the interrupt enable flag bit of the same GPIO input pin are both valid. If the event flag bit is valid but the interrupt enable flag bit is invalid, the valid interrupt sub-signal output is invalid, but the event flag bit remains latched. When the interrupt enable flag bit switches from invalid to valid, the bitwise AND operation is immediately re-executed.

[0117] Step 15.3: Aggregate the valid interrupt sub-signals corresponding to all GPIO input pins, and output a valid level-type interrupt signal if any valid interrupt sub-signal corresponding to any GPIO input pin is valid.

[0118] Specifically, a logic OR gate is used to aggregate all valid interrupt sub-signals of the pins; as long as any one pin has a valid interrupt sub-signal, the overall level interrupt signal output remains high; when all valid interrupt sub-signals of the pins are invalid, the level interrupt signal outputs a low level.

[0119] In this embodiment, the interrupt aggregation unit reads all event flag bits and interrupt enable flag bits in parallel, and performs a bitwise AND operation on the two sets of flag bits pin by pin to generate a valid interrupt sub-signal for each pin. Only when the event flag bit and interrupt enable flag bit of the same GPIO input pin are both valid will the corresponding valid interrupt sub-signal be output as valid. When the event flag bit is valid but the interrupt enable flag bit is invalid, only the sub-signal is output as invalid, and the event flag bit remains latched. When the interrupt enable flag bit switches from invalid to valid, the bitwise AND operation is immediately re-executed. All valid interrupt sub-signals are then aggregated using a logic OR gate. If any one sub-signal is valid, a continuously high-level interrupt signal is output; if all sub-signals are invalid, a low-level signal is output. This hardware aggregation method allows interrupt masking to avoid destroying latched event records, and enables immediate response to events after enable recovery. Multiple pin interrupts are uniformly aggregated into a single level signal, simplifying the backend interrupt receiving logic and eliminating the need for software to poll the pin status one by one.

[0120] In an optional embodiment of the present invention, in step 16, the level-type interrupt signal is output; the level-type interrupt signal serves as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions, including:

[0121] Step 16.1: The level-type interrupt signal is transmitted to two parallel signal paths respectively;

[0122] Specifically, the level-type interrupt signal is a continuous level signal, rather than a short pulse signal, and is simultaneously transmitted to two independent hardware paths;

[0123] Step 16.2: The first signal path sends the level-type interrupt signal to the microcontroller's normal interrupt request input. When the microcontroller is in normal operation, after the microcontroller recognizes the valid level-type interrupt signal, it responds to the interrupt request and enters the interrupt service routine to handle the GPIO edge event.

[0124] Specifically, when the microcontroller is working normally, after receiving a level interrupt signal, it jumps to the GPIO interrupt service routine, reads the interrupt status register, identifies the GPIO pin where the event occurred, and completes the business processing of the button, limit switch, and encoder. After the processing is completed, the software writes 1 to clear the corresponding event flag bit, and the level interrupt signal is canceled.

[0125] Step 16.3: The second signal path directly sends the level interrupt signal to the microcontroller's WFI low-power wake-up circuit; when the microcontroller executes the WFI instruction to enter sleep mode, if a valid level interrupt signal is detected, it triggers the microcontroller to exit sleep mode and completes the wake-up process.

[0126] Specifically, pulse signals cannot reliably wake up a processor in WFI sleep mode. This application outputs a continuous level interrupt signal, which can directly trigger the sleep circuit without requiring the microcontroller to periodically poll the GPIO pin status, thus reducing the overall power consumption of the system.

[0127] In this embodiment, a continuous level interrupt signal is sent to two independent parallel hardware paths, serving two different operating scenarios: normal microcontroller operation and WFI sleep mode. The first path sends the level interrupt signal to the normal interrupt request input. During normal operation, the microcontroller detects a valid signal and responds to the interrupt request, jumping to the interrupt service routine, identifying the GPIO pin that triggered the event, and completing the corresponding business processing for the button, limit switch, and encoder. The level interrupt signal is then canceled after the software writes a 1 to clear the event flag. The second path directly connects the level interrupt signal to the WFI low-power wake-up circuit. When the microcontroller executes the WFI instruction to enter sleep mode, a valid level signal can directly trigger the processor to exit sleep mode. Compared to pulse signals, continuous level signals can reliably achieve sleep wake-up without requiring the microcontroller to periodically poll the GPIO pin status, reducing unnecessary wake-up actions and effectively lowering the overall system power consumption.

[0128] The following example, Scenario 1, further illustrates this solution: An external mechanical button is connected to the GPIO pin, configured as a double-edge triggered mode. The software temporarily disables the interrupt enable flag of this pin (interrupt masking). When the button is pressed, the GPIO generates a falling edge transition. After synchronous processing by two cascaded synchronous sampling units, the edge detection unit identifies a valid falling edge and outputs an event pulse. The interrupt status register latches the event flag of this pin as valid. Because the interrupt enable flag is invalid, the interrupt aggregation unit outputs an invalid level, and the microcontroller does not receive an interrupt. Subsequently, the software re-enables the interrupt enable flag of this pin, and the interrupt aggregation unit immediately detects that both the event flag and the interrupt enable flag are valid simultaneously, outputting a valid level interrupt signal. This directly wakes up the microcontroller in WFI sleep mode, allowing the microcontroller to acquire the button events that occurred during this masking period without event loss.

[0129] The following example, Scenario 2, further illustrates this solution: The A and B phases of the rotary encoder are connected to two GPIO input pins, and the edge configuration parameters of both GPIO pins are configured to a dual-edge trigger mode. The quadrature pulse signals of the encoder A / B phases are fed into the GPIO input pin group as raw electrical signals. The signals undergo two-stage cascaded synchronous sampling units to complete two-stage synchronous processing, reducing the risk of metastability propagation, and then outputting a stable synchronous signal to the edge detection unit. Based on the dual-edge trigger configuration, the edge detection unit identifies and outputs event pulses for the rising edge of phase A, the falling edge of phase A, the rising edge of phase B, and the falling edge of phase B. Within each complete quadrature cycle, phases A and B generate a total of four edge transitions. The hardware generates event pulses for each of the four edges and sends them to the interrupt status register to latch the corresponding event flag bits. The interrupt aggregation unit reads the event flag bits and interrupt enable flag bits corresponding to the two GPIOs, performs a bitwise AND operation, and aggregates them to generate a level-type interrupt signal. This level-type interrupt signal serves as both an interrupt request for normal microcontroller operation and a wake-up source for the WFI sleep instruction. When the microcontroller executes WFI and enters sleep mode, the encoder rotation generates an A / B phase edge transition. The hardware latches the edge event and outputs a valid level interrupt signal to directly wake up the microcontroller. The microcontroller enters the interrupt service routine, reads the interrupt status register, identifies which pin of the A / B phase generated the edge event, and determines the rotation direction by combining the A and B phase levels. Simultaneously, it realizes quadrature encoder frequency multiplication counting. This scheme does not require the microcontroller to continuously poll the encoder pin status. Each edge transition of the encoder generates an event latch, and the microcontroller can be directly woken up from sleep mode to complete the quadrature frequency multiplication decoding. Even if the software temporarily disables interrupt enable, the A / B phase edge event that occurs during this stage will still be latched in the interrupt status register. When the interrupt enable is re-enabled, a level interrupt is generated immediately, without losing the encoder transition event. This is very suitable for low-power encoder sampling scenarios.

[0130] This invention employs a two-stage cascaded synchronous sampling unit to perform pipelined two-stage synchronous processing on external asynchronous raw electrical signals, effectively reducing the risk of metastability propagation across clock domains and ensuring the reliability of edge detection. Edge configuration registers are arranged continuously in pin groups; software modification of grouped pin configurations eliminates the need for masking operations, simplifying software logic and saving register address resources. The interrupt status register features event latching and write-to-clear functionality, ensuring complete preservation of edge events occurring during interrupt masking and preventing missed event sampling. The interrupt aggregation unit aggregates multiple pin events into a single level-type interrupt signal. This signal can serve as both a regular interrupt request and a direct wake-up source for WFI sleep instructions, avoiding the problem of wake-up loss due to insufficient pulse width in pulse interrupts. The microcontroller only wakes up when an edge event occurs, eliminating the need for periodic polling of pin states, significantly reducing system power consumption and adapting to low-power event acquisition scenarios such as button input and quadrature rotary encoder frequency multiplication.

Claims

1. A GPIO edge split event detection apparatus, characterized by, include: GPIO input pin group is used to receive raw electrical signals from external devices; Two cascaded synchronous sampling units electrically connected to the GPIO input pin group are used to perform signal synchronization processing on the original electrical signal and output a synchronous stable signal. The edge configuration register group is used to store the edge configuration parameters corresponding to different GPIO input pin groups and output them to the edge detection unit. An edge detection unit, which is electrically connected to the two-stage cascaded synchronous sampling unit and the edge configuration register group respectively, is used to perform edge detection on the synchronous stable signal according to the edge configuration parameters and filter to generate event pulses corresponding to the GPIO input pins; An interrupt status register electrically connected to the edge detection unit is used to set the event flag bit of the corresponding GPIO input pin according to the event pulse. The event flag bit is latched after being set and cleared in response to a write 1 operation of the microcontroller. The interrupt enable register is used to store the interrupt enable flag bits corresponding to each GPIO input pin; The interrupt aggregation unit, which is electrically connected to the interrupt status register and the interrupt enable register, is used to perform bitwise AND logic operations on the event flag bit and interrupt enable flag bit corresponding to the same GPIO input pin, and aggregate the operation results of all GPIO input pins to generate a single level interrupt signal. The level-type interrupt output port, which is electrically connected to the interrupt aggregation unit and the microcontroller, is used to output the level-type interrupt signal as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions.

2. The GPIO edge split event detection apparatus of claim 1, wherein, The edge configuration register group includes a first edge configuration register and a second edge configuration register with consecutively set addresses; the first edge configuration register is used to store the edge configuration parameters of the first group of GPIO input pins, and the second edge configuration register is used to store the edge configuration parameters of the second group of GPIO input pins.

3. The GPIO edge split event detection apparatus of claim 1, wherein, The two-stage cascaded synchronous sampling unit includes: a first flip-flop and a second flip-flop cascaded in two stages; the first flip-flop receives the original electrical signal for sampling and outputs a first-stage sampling signal; the second flip-flop receives the first-stage sampling signal for sampling and outputs a synchronous stable signal.

4. A GPIO edge split event detection method applied to the GPIO edge split event detection device according to any one of claims 1 to 3, characterized in that, The method includes: Write the edge configuration parameters corresponding to different GPIO input pin groups into the edge configuration register group, and at the same time configure the interrupt enable flag bit corresponding to each GPIO input pin in the interrupt enable register. It receives raw electrical signals from external devices, performs signal synchronization processing on the raw electrical signals, and outputs a stable synchronization signal. Read the edge configuration parameters in the edge configuration register group, perform edge detection on the synchronization stable signal according to the edge configuration parameters, and filter to generate event pulses for the corresponding GPIO input pins; Based on the event pulse, the event flag bit of the corresponding GPIO input pin is set; the event flag bit is latched after being set, and cleared in response to a microcontroller write-1 operation; Read the event flag and interrupt enable flag corresponding to the same GPIO input pin, perform bitwise AND logic operation on each pin, and aggregate the operation results of all GPIO input pins to generate a single level interrupt signal; The level-type interrupt signal is output; the level-type interrupt signal serves as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions.

5. The GPIO edge split event detection method of claim 4, wherein, Write the edge configuration parameters corresponding to different GPIO input pin groups into the edge configuration register group, and simultaneously configure the interrupt enable flag bits corresponding to each GPIO input pin in the interrupt enable register, including: Write the edge configuration parameters corresponding to the first group of GPIO input pins into the first edge configuration register; Write the edge configuration parameters corresponding to the second group of GPIO input pins into the second edge configuration register; For each GPIO input pin, write the interrupt enable flag bit to the corresponding bit in the interrupt enable register.

6. The GPIO edge split event detection method of claim 4, wherein, It receives raw electrical signals input from external devices, performs signal synchronization processing on the raw electrical signals, and outputs a stable synchronization signal, including: Receive raw electrical signals input from external devices; The original electrical signal is input to the first flip-flop, and the first flip-flop performs the first sampling on the original electrical signal and outputs the first-level sampling signal. The first-stage sampling signal is input to the second flip-flop, which resamples the first-stage sampling signal and outputs a synchronous stable signal.

7. The GPIO edge split event detection method of claim 4, wherein, Read the edge configuration parameters from the edge configuration register group, perform edge detection on the synchronization stabilization signal according to the edge configuration parameters, and filter to generate event pulses for the corresponding GPIO input pins, including: Read the edge configuration parameters from the edge configuration register group; Edge detection is performed on the synchronous stable signal to obtain rising edge transitions and falling edge transitions; The rising edge transition and falling edge transition are filtered and judged according to the edge configuration parameters to generate the event pulse corresponding to the GPIO input pin.

8. The GPIO edge split event detection method of claim 4, wherein, Based on the event pulse, the event flag bit of the corresponding GPIO input pin is set; the event flag bit is latched after being set, and cleared in response to a microcontroller write-1 operation, including: According to the event pulse, the event flag bit of the corresponding GPIO input pin is set to a valid state, and the event flag bit is latched after it is set; In response to a write-1 operation by the microcontroller, the event flag bit of the corresponding GPIO input pin is cleared to an invalid state.

9. The GPIO edge split event detection method of claim 4, wherein, Read the event flag and interrupt enable flag corresponding to the same GPIO input pin, perform bitwise AND logic operations on each pin, and aggregate the results of all GPIO input pin operations to generate a single level-type interrupt signal, including: Read the event flag and interrupt enable flag corresponding to the same GPIO input pin; For each GPIO input pin, perform a bitwise AND operation on the corresponding event flag bit and interrupt enable flag bit to obtain the corresponding valid interrupt sub-signal; All valid interrupt sub-signals corresponding to the GPIO input pins are aggregated, and any valid interrupt sub-signal corresponding to any GPIO input pin is valid, outputting a valid level-type interrupt signal.

10. The GPIO edge split event detection method of claim 4, wherein, Output the level-type interrupt signal; the level-type interrupt signal serves as an interrupt request during normal operation of the microcontroller and a wake-up source for WFI low-power instructions, including: The level-type interrupt signal is transmitted to two parallel signal paths respectively; The first signal path sends the level-type interrupt signal to the microcontroller's normal interrupt request input. When the microcontroller is in normal operation, after the microcontroller recognizes the valid level-type interrupt signal, it responds to the interrupt request and enters the interrupt service routine to handle the GPIO edge event. The second signal path directly sends the level-type interrupt signal to the microcontroller's WFI low-power wake-up circuit; when the microcontroller executes the WFI instruction to enter sleep mode, if a valid level-type interrupt signal is detected, it triggers the microcontroller to exit sleep mode and complete the wake-up process.