-
Notifications
You must be signed in to change notification settings - Fork 22
Rethink STM32 I2C v2 HAL #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I have created an exhaustive new test suite that covers just about every pattern of I2C reads and writes you could do, including repeated starts and use of all three different APIs on the same peripheral one after the other. It helped me catch a large number of issues in the existing and the new code. https://github.com/multiplemonomials/Mbed-CI-Test-Shield/blob/master/Software/I2CBasicTest.cpp |
Tests passed on STM32L452RE:
Tests passed on STM32H743ZI:
|
Almost there, just need to look into why this PR makes the "Simple Read - Transaction" test fail for IP v1 |
OK, I can now say that there are no more failures with IP v1 on this branch than on master. Filed #96 about the remaining test failures. |
it is difficult to test, I can connect some I2C devices and test with my currenct hardware. Maybe there is some I2C compliance test equiment, but I don't have access to it. |
@JojoS62, I believe it is about this piece of hardware - Mbed-CI-Test-Shield by @multiplemonomials. |
Yup! I can send you one of the boards if you want to run these tests locally |
I would like also one, but I am from Czech republic and the transport from USA is probably expensive. BR, Jan |
and I'm living in germany. So it is probably easier to run some simple tests with I2C devices. Although, target implementations can have very different behaviour. I have seen that with SPI on H7, it can be very complicated. |
… work properly and adds a new 'state' variable to track what the hardware is doing.
…g I2C peripheral to lock up
fb5c2b3
to
5a5ed17
Compare
* Initial attempt at rethinking the STM32 I2C v2 HAL. Makes single-byte work properly and adds a new 'state' variable to track what the hardware is doing. * Fix some initial test failures * Fix incorrect logic * Fix more incorrect logic * Tabs to spaces * Fix repeated starts with single-byte API * Fix race condition causing stop() after nacked address to sometimes break things * Fix missed i2c structs that should have been removed * Fix doing a repeated start from single-byte to transaction API causing I2C peripheral to lock up * Fix xferOperation being set wrong for repeated starts, causing the peripheral to hang * Fix race condition with repeated start after single-byte operation * Fix compilation for targets that use I2C IP v1 * Fix initialization of XferOperation for API v1, optimize stop() * Remove unneeded line * Add docs for I2C events
I saw your work was already Marged also in ArmMbed. May I close issues (61,62 and 94 mentioned above) connected to this? BR, Jan |
Sure on 61 and 62. I haven't fixed 94 yet. |
Summary of changes
This PR is a major rethink of the STM32 I2C code for their v2 I2C peripheral. It tries to get it into a more API-compliant and less buggy state. It should fix several known bugs:
Additionally, I found more issues while making this PR that will also be fixed:
The biggest change this PR makes is the addition of a new state enum,
obj_s->state
. This provides a simple indicator of what the I2C code is doing at any given time, making certain parts of the logic a lot simpler and enabling some of the fixes to work. I also added a lot of new checks based on this state variable, so if you use the I2C object in an incorrect way, you have a fighting chance of getting a useful error code back instead of undefined behavior. (it's still tough though because certain functions do not have the ability to return an error code...)Impact of changes
Lots of issues are fixed (see above)
Migration actions required
Documentation
None
Pull request type
Test results
Working on creating new tests that run this code against hardware.
Reviewers