Read Mastering STM32, Read 6.2.2 GPIO Alternate Function and 6.3 Driving a GPIO and deinitialize a GPIO.