Sensing +12V signal using ST STM8AF5288 microcontroller digital input
Move your R1 resistor and place it in parallel with the C1 capacitor so that you get a voltage divider effect from the 12V signal down to the acceptable input voltage of the MCU. You may have to adjust the resistor values to get the correct divider ratio.

Do not rely on the input voltage clamps on the MCU to limit the input high voltage level. Clamps are put on the chip to protect the inputs for extreme conditions and are never meant to be used in normal usage application.