This is a tutorial with the NUCLEO Board STM32L412KB where I show you how buttons in software are reliably debounced. You can download the code and the project files on github: https://github.com/STM32-Microcontroller/Code-Examples-Project-Files/tree/main/Button_1