Program execution during Flash operation?

Your global objects execute their constructors before setup. One of them likely touched the SPI pins too.