Resolved! Strange STM32L476RG GPIO behaviour when leaving STOP mode 2. Is it a silicone bug?
Before I enter the stop mode 2 I save all the GPIO MODER, OSPEEDR and PUDPR registers, configure pins as analogue (to save some power) and enter the STOP mode 2. When I exit the stop mode (I use RTC wakeup and GPIOs for that) I restore the above reg...