STM32 gotchas
260. In 'G4, COMP output glitches, this makes processing it using EXTI almost impossible

Some STM32 - especially the families aimed at mixed-signal mode, such as 'F3 and 'G4 - contain one or more comparators (COMP). They have features such as calibration and hysteresis, but these features and the overall performance of comparators vary from family to family (quite naturally, as the different families are manufactured using different technologies).

The comparators can have both inputs connected to pins, or some of the inputs can be connected to DAC output internally, or to a reference voltage derived from the internal VREFINT reference source. Their outputs can be connected to external pin, or internally to timers, and to EXTI in order to facilitate interrupts.

As user Michal Dudka found out in the hard way, COMP4 on STM32G431KB generated cca 2ns pulses/glitches next to the output transitions, when fed with a slowly varying (and very clean) input signal. These glitches could be observed using oscilloscope when the COMP output was connected to external pin.

Disturbingly, these glitches trigger EXTI interrupts, if used, which generates false interrupts on the "other" edge (e.g. an unexpected rising-edge interrupt was generated when the output went nominally from high to low). This is due to the fact that EXTI's edge detectors are asynchronous, i.e. does not work out of any internal clock, and are quite fast.

According to ST's employee responding on that thread, these glitches are due to Miller effect inside the comparator circuitry, and can be mitigated by setting bit#1 (not documented) in COMP_CxCSR, which enables a compare feature which hold the comparator output during the duration of the Miller effect.

While this apparently fixed the problem, the fact that this is an undocumented feature and thus has unpublished consequences, is unsettling.