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.
STM32L1xx I2C driver enters I2C_LOCKED state
Moderators: barthess, RoccoMarco
-
- Posts: 7
- Joined: Mon Feb 13, 2017 5:57 am
- Has thanked: 4 times
- Been thanked: 2 times
- Giovanni
- Site Admin
- Posts: 14563
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1111 times
- Been thanked: 937 times
- Contact:
Re: STM32L1xx I2C driver enters I2C_LOCKED state
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
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
Who is online
Users browsing this forum: No registered users and 13 guests