STM32 controllers can't be powered with 5V, they can take at most 3.6V, and usually powered with 3.3V.
You can connect pull-up resistors to the pins and set them to open-drain mode (set corresponding bits in GPIOA->OTYPER), as long as they are 5V tolerant - check the pin definitions table in the datasheet for that, PA4 and PA5 are NOT 5V tolerant, pick another pins instead.