stm32-rs / stm32h7xx-hal

Peripheral access API for STM32H7 series microcontrollers
BSD Zero Clause License
215 stars 101 forks source link

i2c can lock up MCU #435

Closed ost-ing closed 10 months ago

ost-ing commented 1 year ago

I've experienced a write to the i2c peripheral locking up the MCU and not returning any result, this can happen for example if the device it is connected to isn't powered up. I would expect that writing to the i2c peripheral should return an Error in this scenario.

I've also experienced this when attempting to implement BDMA and implement multiple successive i2c.write and then i2c.master_re_start commands, as adapted from the i2c bdma example.

After successfully receiving data via master_re_start and clearing appropriate interrupt flags, then on the second i2c.write, the function never returns and the MCU locks up.

cc @richardeoin

richardeoin commented 1 year ago

I'm aware this can happen, but I don't believe it is a defect in the HAL implementation.

the device it is connected to isn't powered up

It sounds like both lines on your I2C bus are low. The I2C specification states "When the bus is free, both lines are HIGH". Therefore the defect is in your bus because it is not complying to the specification.

For some applications handling non-confirming or defective busses is useful or even essential, but imo this functionality belongs in a separate crate.

richardeoin commented 1 year ago

implement multiple successive i2c.write and then i2c.master_re_start commands, as adapted from the i2c bdma example.

This sounds like a different problem. Can you provide code that triggers this? Then I can keep the issue open