-
Notifications
You must be signed in to change notification settings - Fork 7.4k
drivers: i2c_sam0: Optimize and add i2c slave #24050
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
drivers: i2c_sam0: Optimize and add i2c slave #24050
Conversation
37a545f
to
3345b25
Compare
There is an issue when two transactions run back to back. I added an idle check loop and timeout to address this. |
@sslupsky Could you revisit this PR, please? First the single commit has far too much stuff in it. It should be split out into separate commits that fix each isolated problem separately. (It looks like it was that way originally, but then got squashed; I believe that was a misunderstanding of expectations that's been corrected.) We're particularly interested in #21232 which is medium priority so affects the release. Ideally a fix for that would be pulled out to a separate PR that we can merge: this one has too much other stuff in it. I don't see how this PR fixes #21114; if it doesn't please remove it from the list of fixed issues. (I edited the description so that all of them, not just the first on the line, were recognized by github as related.) |
@sslupsky could you rebase. |
@nandojve Against what? master? I haven't updated my local to the most recent master since release of 2.3 yet. |
Well, there is a file conflict, at least for me shows below: |
Ok, I will have a look. I am filtering out the commit for the i2c slave changes and will push the updated PR shortly. |
3345b25
to
ed1e180
Compare
I added a commit for some changes made since the original PR was submitted. |
293862d
to
672fd65
Compare
hmm, I forced pushed the changes but it seems to have only updated the commit dealing with the i2c_slave. Can someone please advise how to push the changes to the earlier commit (I squashed those changes). |
Optimizations: When using system power management, the bus transactions can be interrupted by low power modes which causes excessive power consumption and can cause the transactions to terminate before completed. Further, other interrupts can cause bus transaction anomalies. When using the RESTART flag, the MB and SB bits must be cleared. This commit prevents interruption of the bus during low power modes and correctly clears the MB or SB flags when a bus transaction is restarted. Also fixes an initialization problem with the INACTOUT timer and ensures the LOWTOUT is properly configured when using i2c_configure(). The GCLK_SERCOM_SLOW clock is used to time the i2c time-outs and must be configured to use a 32KHz oscillator. See 28.6.3.1 This commit configures GCLK4 to 32768 Hz Fixes zephyrproject-rtos#21711, zephyrproject-rtos#21549, zephyrproject-rtos#21233, zephyrproject-rtos#21232, zephyrproject-rtos#21114, zephyrproject-rtos#21092 A problem can arise when back to back transactions occur before the STOP transaction is complete. This commit also introduces a busy wait for the STOP to complete with an timeout in the event there is a bus failure. Signed-off-by: Steven Slupsky <[email protected]>
The existing sam0 i2c driver does not support slave mode. This commit enables slave support for sam0 devices. The Slave support is based on Linux I2C Slave support by Wolfram Sang and documented at https://www.kernel.org/doc/Documentation/i2c/slave-interface The code for this commit is largely based on code taken from PR zephyrproject-rtos#5224 and the stm mcu implementation. This was modified to work with the sam0 SERCOM perhiperal and integrated into the sam0 driver. A slave must wait for data ready when there is an address match to ensure the data is valid. Disable SCLSM (SCL stetch mode) when operating in slave mode to ensure that i2c ACK's are handled properly. Fix k_timeout_t. Signed-off-by: Steven Slupsky <[email protected]>
672fd65
to
8c5cad9
Compare
Ok. I think I have properly rebased this now and the two commits accurately separate the i2c slave changes. |
needs a review from the relevant folks |
Hi @sslupsky, you are doing a great job, thanks! I would like run this on HW and I have two R21 and one D20 that I can use it. How do you suggests to do it? How do you are testing, loopback? Do you have anything that can share to speed up my tests? I would like know what app is building this on CI, do you know one? We need make sure code is covered on CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs to be updated for the change to replace u32_t
with uint32_t
back in June. A pinned message in the general slack channel has these instructions, which would need to be adapted now.
git checkout ${BR}
git rebase e77985a2f0 # last commit before rename
rm -rf c99
git format-patch -o c99 e77985a2f0..HEAD
sed -i.bak -r \
-e 's/\bu(8|16|32|64)_t\b/uint\1_t/g' \
-e 's/\bs(8|16|32|64)_t\b/int\1_t/g' \
c99/*
for f in c99/*.patch ; do
diff -u ${f}.bak ${f}
done
git branch BU/${BR}
git reset --hard a2d4292a96 # the last commit of the rename
git am c99/*.patch
@nandojve I have a couple boards that I have been using for my testing. Mostly, I have tested with a few sensors on my board (temp/humidity, barometer, ambient light, accelerometer). I have another board to board connection where two D21's talk to each other using I2C as well. The sensor application periodically reads the sensors and the application on the other board pulls the sensor readings from the sensor board using the AT24 memory device emulation driver. I do not have a dedicated test suite so there is no CI set up. |
Optimizations:
When using system power management, the bus transactions
can be interrupted by low power modes which causes excessive
power consumption and can cause the transactions to terminate
before completed. Further, other interrupts can cause bus transaction
anomalies.
When using the RESTART flag, the MB and SB bits must be cleared.
This commit prevents interruption of the bus during low power modes and
correctly clears the MB or SB flags when a bus transaction is restarted.
Also fixes an initialization problem with the INACTOUT timer and ensures
the LOWTOUT is properly configured when using i2c_configure().
Add i2c slave support:
The existing sam0 i2c driver does not support slave mode.
This commit enables slave support for sam0 devices.
The Slave support is based on Linux I2C Slave support by Wolfram Sang
and documented at
https://www.kernel.org/doc/Documentation/i2c/slave-interface
The code for this commit is largely based on code taken from PR #5224
and the stm mcu implementation. This was modified to work with the
sam0 SERCOM perhiperal and integrated into the sam0 driver.
Fix whitespace and comments
This PR replaces #24047
Fixes #21711
Fixes #21549
Fixes #21233
Fixes #21232
Fixes #21114
Fixes #21092