Description
The implementation of SPIClass::setClockDivider
does not do what it should. For compatibility/history's sake it should interpret the SPI_CLOCK_DIVn
relative the original 16Mhz Arduino clock. Instead, it applies the divider to the current SPI device clock.
Specifically:
spiSettings[idx].clk = spiClkFreq/_divider;
at https://github.com/stm32duino/Arduino_Core_STM32/blob/master/libraries/SPI/src/SPI.cpp#L255 should be replaced by something like
spiSettings[idx].clk = 16000000/_divider;
Of course other ways to implement the same notion are also possible. If you want to look at what one of the official ARM cores does, see https://github.com/arduino/ArduinoCore-sam/blob/master/libraries/SPI/src/SPI.h#L138-L146 and https://github.com/arduino/ArduinoCore-sam/blob/master/libraries/SPI/src/SPI.cpp#L167-L173, i.e., they define the divider values such that it comes out right, which probably works because they fix the processor's clock speed.