STM32 gotchas
176. SPI/I2S set to PCM runs twice the expected sample rate

The SPI/I2S module in STM32 in I2S mode allows to select, by setting SPI_I2SCFGR.I2SSTD, one of several commonly used audio protocols: I2S, left-justified, right-justified, or PCM. While the former three are basically a variant to the same scheme - stereo samples framed by a left-right signal - PCM is a relatively simple mono protocol.

Reference manual provides formulas to calculate/set sampling rate, but those are intended for the I2S-like protocols. For PCM protocols, they result in twice the intended sampling rate - logically, the same number of data frames results in twice the samples in MONO than in STEREO.

As manual does not contain PCM-specific guidelines, users have to adjust the formulas accordingly. Similarly, users have to take this into consideration when using libraries such as Cube/HAL, which may be written without this PCM-specific detail in mind.

Issue spotted by user vincent.