STM32 Standard Peripheral Library (SPL) - Modify SPI Configuration
If you find the SPI_CR1 register in the Reference Manual, you can see that the speed is set by the BR bits (bits 5:3 in SPI_CR1). You can adjust the baud rate on the fly by changing these bits, as long as there isn't a transmission currently in progress:



Conveniently, the SPI_BaudRatePrescaler defines provided by the Standard Peripheral Library map directly on top of the SPI_CR1 bits.

What I do is create the following #defines:

#define BAUD_RATE_BITMASK    0xFFC7                // Used to clear CR1-&gt;BR[2:0]
#define SPI_SPEED_LOW    SPI_BaudRatePrescaler_32  // 72/32 = 2.25MHz
#define SPI_SPEED_HIGH   SPI_BaudRatePrescaler_4   // 72/4 = 18MHz


Then I use something like this to adjust the speed (where NewSpeed is one of the SPL defines):

void spiSetSpeed(uint16_t NewSpeed)
{
    // Assert the new speed setting
    SPI1-&gt;CR1 &amp;= BAUD_RATE_BITMASK;                // Clear the BR[2:0] bits
    SPI1-&gt;CR1 = (uint16_t)(SPI1-&gt;CR1 | NewSpeed);  // Set the bits
}