I corrected the issue by adding the code at the bottom of this post to a user section of generated stm32f4xx_hal_msp.c:
This fix is specifically for my situation, and will have to be adapted for other SPI busses / CPUs.
In my opinion the neglection of this part of the SPI configuration is a bug and should not have to be added by the user, but should have been generated by CubeMX, and/or have been part of stm32f4xx_hal_spi.c.
As also mentioned in my comments below with this fix a call to HAL_SPI_DeInit () is required to re-execute this initialization.
This may be a little ineficient in some circumstances, but it is good enough for me.
HAL_SPI_Init () returns no error when it is called while it was already initialized, however it's effect depends on the value hspi->State this may be efficient in some cases, but is not very robust in terms of reproducibility.
/* USER CODE BEGIN SPI1_MspInit 1 */
/* Setup the initial idle level of SCK according to note at botom of
* page 564 of STM32F401 reference manual (RM0368 Rev 5):
*
* The idle state of SCK must correspond to the polarity selected in the
* SPI_CR1 register (by pulling up SCK if CPOL=1 or pulling down SCK if
* CPOL=0).
*
* Warning: For a proper reconfiguration of the SPI bus initial SCK level
* hspi->State has to be HAL_SPI_STATE_RESET, therefore call
* HAL_SPI_DeInit() before the reconfiguring HAL_SPI_Init ().
*/
GPIO_InitStruct.Pin = SPI1_SCLCK_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
if (hspi->Init.CLKPolarity==SPI_POLARITY_HIGH) {
GPIO_InitStruct.Pull = GPIO_PULLUP;
} else {
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
}
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE END SPI1_MspInit 1 */