STM32L1xx HAL_GPIO_Init Problem
IDD_CNT_EN is connected to the onboard power measurement circuitry. If not used properly, it will temporarily disrupt VDD power supply, resetting the MCU.

Look at the schematics in the User Manual



Setting IDD_CNT_EN to output low starts the external timer U3. After a delay of 150 ms, Q13 of U3 goes high, FET 1 in U20 is switched off, and the 1kΩ shunt resistor R22 is now connected in series with VDD to improve the accuracy of the power measurement. The MCU should put itself to LOWPOWER, STOP or STANDBY mode, where consumption is well below 1 mA, within 150 ms of setting IDD_CNT_EN to low, and set it back to high in less than 150 ms after the wakeup signal on PA0 arrives.