Chris Chua

[bug report] STM32H7 HAL I2S FifoThreshold bug

Discussion created by Chris Chua on Mar 14, 2018

Hi, just submitting this in case anyone else experiences this:


If trying to use the HAL libraries to access I2S on STM32, the I2S_Fifo_Threshold values are defined in stm32h7xx_hal_i2s.h as:

#define I2S_FIFO_THRESHOLD_01DATA              (0x00000000U)
#define I2S_FIFO_THRESHOLD_02DATA              (0x00000020U)
#define I2S_FIFO_THRESHOLD_03DATA              (0x00000040U)
#define I2S_FIFO_THRESHOLD_04DATA              (0x00000060U)
#define I2S_FIFO_THRESHOLD_05DATA              (0x00000080U)
#define I2S_FIFO_THRESHOLD_06DATA              (0x000000A0U)
#define I2S_FIFO_THRESHOLD_07DATA              (0x000000C0U)
#define I2S_FIFO_THRESHOLD_08DATA              (0x000000E0U)

These are clearly meant to be written unshifted into SPI_CFG1, as the FIFO threshold level register FTHVL occupies bits 5 to 8.

However, in the function HAL_I2S_Init in stm32h7xx_hal_i2s.c, there is the line:

MODIFY_REG(hi2s->Instance->CFG1, SPI_CFG1_FTHLV, (uint32_t)(hi2s->Init.FifoThreshold << 5U));

where the FifoThreshold value is shifted left 5 bits. Fourtunately, the use of the MODIFY_REG macro ensures that no other fields are clobbered, but the effect of this bug is that I2S FIFO threshold values are not set correctly. The fix is to modify the line to:

MODIFY_REG(hi2s->Instance->CFG1, SPI_CFG1_FTHLV, (uint32_t)(hi2s->Init.FifoThreshold));


This issue is present in the latest (V1.2.0) STM32H7xx HAL Drivers.