GPIO control of alternate function pin
You need to reinitialize the pin as a software controlled output. For instance, if you're using the STM32 Standard Peripheral Library, and assuming the pin in question is PA5, you'd have to do something along the lines of:

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_StructInit(&amp;GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOA, &amp;GPIO_InitStructure);


Possibly you'd also need to set the field GPIO_InitStructure.GPIO_Speed if your clock signal is faster than 2 MHz (the default setting).

From now on you can do GPIO_Toggle(GPIOA, GPIO_Pin_5) and it would work, since the pin is now under software control. Of course, being under software control, the peripheral toggling the SPI clock would have no effect on the pin itself anymore. If you ever want to delegate control of the pin back to the peripheral, you'd run the code all over again, but set the field GPIO_Mode to GPIO_Mode_AF.