I have an BluePill board (Arm Cortex M3 Dev. Board). Also a a4988 stepper motor driver. BluePill is powered from usb of my PC. Stepper motor driver is powered by external power supply which is 220V -> 12V. Both my pc and the external power supply are connected to same plugs. The grounds are wired between a4988 and BluePill. The weird problem is, when I connect my PC13 pin to STEP pin. I can smoothly drive my stepper motor. When I connect to another pin such as A7, A6 my stepper motor turns randomly. Power supply and wires are too close to each other (approximately 10-15cm). I think that emf occurs on the wire and the noise causes to move motor randomly but why it doesn't happen when I connect it to PC13.
When I connect a wire to STEP pin and the other side of wire is unconnected, there is also random turns.
Added my setup as @laptop2d said. Here is my setup