I2C4 issue on STM32F76xx
Posted: Wed Aug 16, 2023 6:33 pm
Hi,
Running 21.1.1 on a board with I2C slave devices on both I2C3 and I2C4 busses (device has the same address so needed to be separated that way). I started with the STM32F769-discovery demo code, and adapted it to my board, which uses a F765 but seemingly close enough for I2C.
With a working config, I can successfully write a command and read back the result to the device on I2C3. All looks good on the logic analyzer.
Just switching that same test code to use I2C4 and the same configuration, and it stops working. The driver returns MSG_RESET, and digging in I can see that the I2CD4 structure has error=4 which seems to mean that the NACKF bit was set and it prematurely stopped. However, inspecting the SDA/SCL lines with a logic analyzer, the start bit is sent, then the slave address, the device is indeed acking after the slave address is clocked out (just like the one on I2C3) but then the peripheral aborts and finishes.
I have tried with and without DMA, same result.
I have also tried running 21.1.3 in case this was a bug that was fixed and to no avail.
I also blindly tried a change similar to bug #1202 (in case ordering matters) and it did nothing (again it doesn't work non-DMA either). As an aside, the RM seems to have errata in the I2C4 DMA channels (one of the TX channels seems to have been mislabelled as RX, but the definitions in stm32_registry.h seem to follow the CubeMX tool).
I'm not sure what to try next. I had a quick look thru the HAL code for obvious cut/paste errors between drivers and didn't see anything myself.
Dave
Running 21.1.1 on a board with I2C slave devices on both I2C3 and I2C4 busses (device has the same address so needed to be separated that way). I started with the STM32F769-discovery demo code, and adapted it to my board, which uses a F765 but seemingly close enough for I2C.
With a working config, I can successfully write a command and read back the result to the device on I2C3. All looks good on the logic analyzer.
Just switching that same test code to use I2C4 and the same configuration, and it stops working. The driver returns MSG_RESET, and digging in I can see that the I2CD4 structure has error=4 which seems to mean that the NACKF bit was set and it prematurely stopped. However, inspecting the SDA/SCL lines with a logic analyzer, the start bit is sent, then the slave address, the device is indeed acking after the slave address is clocked out (just like the one on I2C3) but then the peripheral aborts and finishes.
I have tried with and without DMA, same result.
I have also tried running 21.1.3 in case this was a bug that was fixed and to no avail.
I also blindly tried a change similar to bug #1202 (in case ordering matters) and it did nothing (again it doesn't work non-DMA either). As an aside, the RM seems to have errata in the I2C4 DMA channels (one of the TX channels seems to have been mislabelled as RX, but the definitions in stm32_registry.h seem to follow the CubeMX tool).
I'm not sure what to try next. I had a quick look thru the HAL code for obvious cut/paste errors between drivers and didn't see anything myself.
Dave