STM32L1xx I2C driver enters I2C_LOCKED state

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
radar_macgyver
Posts: 7
Joined: Mon Feb 13, 2017 5:57 am
Has thanked: 4 times
Been thanked: 2 times

STM32L1xx I2C driver enters I2C_LOCKED state

Post by radar_macgyver »

On my STM32L152 project, I'm using one of the I2C units in master mode at 100 kHz in a PMBUS application (talking to a PMBUS compatible power supply). All communications with the I2C is in a single thread. I found that on some occasions, my firmware was locking up, usually when other threads ran in a tight loop without yielding. When connecting with a debugger, I would find that chSysHalt was called by the I2C subsystem on the call to i2cMasterTransmitTimeout due to an assertion failure when testing the i2C driver state if it's I2C_READY. The driver always reported it is in I2C_LOCKED state.

My fix for now is to test the state of the driver prior to calling i2cMasterTransmitTimeout, and if it's not I2C_READY, stop the i2C subsystem and start it again.

I'm curious why this would happen, and if there's a more elegant way of handling this than my code inspecting the contents of the I2C driver structure.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L1xx I2C driver enters I2C_LOCKED state

Post by Giovanni »

Hi,

The I2C driver is quite old and could use an overhaul, that locked state thing should be checked explicitly and not with an assertion.

Your workaround is correct, not elegant but correct.

Giovanni
Post Reply