Where does the spark come from? (an embedded system circuit)
Sparks can be created by any number of things.  Certainly by high voltage; this can be seen when you touch a doorknob after walking across carpet on a dry day :)

In your case, though, I don't believe the spark was caused by this mechanism.  Instead, if your input pin was configured as a pull-down, you created a dead short between your 3.3V supply and the ground.  This dead short caused a high amount of current to flow, which literally melted/vaporized a piece of the circuit.  This vaporized material is what you saw as a "spark".

When using the circuit in your diagram the input pin must always be configured as high-impedance ("Hi-Z").  This prevents any significant current from flowing into (or out of) the pin.

Please be clear about the "pulling to ground" terminology.  That phrase is sometimes used as you used it, that is, when the pin is set low (or being "pulled" or "driven" low).  However, it is also used when referring to pull-up or pull-down resistors.  With pull-up (or pull-down) resistors, the pin is pulled high (or low) through a large resistance.  This resistor limits current, preventing circuit damage.

Pull-up (or pull-down) resistors are necessary for the circuit that you show. You have done it correctly with R314. These can be actual discrete components (as you used), or most microcontroller outputs can be configured to use internal pull-ups (or pull-downs).



By the way, any time you make or break an electrical connection there is a likelihood of some small spark. Imagine two conductors in the air separated by 1 cm.  It would take approximately 31 kV to cause a spark.  If they were only 0.5 cm apart, it would take around 17 kV.  As you can see, the breakdown voltage is dependent on the distance.

When you connect two conductors together, you are decreasing the separation distance until they actually contact.  Eventually a spark will happen, although it is often too small to detect.  It's not a problem unless the spark is fairly high-energy.

Interestingly, most ESD damage is done without noticeable sparking.  Perhaps this is because people don't realize that it's happening and so they don't correct it until it's too late...



Edit:

Thanks for posting your code.  It looks correct, although there are a few things that cause worry. For example, your comments don't match what is actually happening.  Are you intending to use PC10 and PC12 (as per the code) or PB6 and PB7 (as per the comments)?

Another problem is that you're setting the output configuration to Open Drain.  This shouldn't actually matter, since the output configuration is ignored when the pin is set to an input.  But, if you were experimenting and set it to Output, then it would cause this type of failure.

For your info, you have correctly set the pin as a digital input (implying high impedance) with this command: GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;

Once the pin has been set as an input, certain parameters are ignored and are usually omitted from your code.  In this case, you may choose to delete these lines:

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;


I hope this helps!