Skip to content
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

cpu/cc2538: adapt periph to new I2C API #9347

Merged
merged 3 commits into from
Jun 25, 2018
Merged

Conversation

smlng
Copy link
Member

@smlng smlng commented Jun 14, 2018

Contribution description

This adapt the CC2538 I2C to the new API.

Problem right now: it works with debug enabled but not without.

Issues/PRs references

#6577

@smlng smlng added Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. TF: I2C Marks issues and PRs related to the work of the I²C rework task force Area: cpu Area: CPU/MCU ports labels Jun 14, 2018
@smlng smlng self-assigned this Jun 14, 2018
@smlng smlng requested a review from MrKevinWeiss June 14, 2018 11:06
@MrKevinWeiss
Copy link
Contributor

Hmmm, it seems like the register is volatile which means it shouldn't be optimized out. It could just be the delay from the print of the debug. I'll do a proper test (and might need some hardware from you) after I finish current task.

@smlng smlng force-pushed the pr/cc2538/i2c branch 2 times, most recently from 94fc38d to cdc9d0d Compare June 14, 2018 16:05
@smlng
Copy link
Member Author

smlng commented Jun 14, 2018

Hey I fixed the issue by adding a small delay incrementing a variable, now it works with and without debug output.

@smlng
Copy link
Member Author

smlng commented Jun 14, 2018

please note this also introduces a new gpio init function because the present cannot handle init of I2C pins but is used for UART. I'll will sort out things later on ...

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 14, 2018
@smlng smlng force-pushed the pr/cc2538/i2c branch 2 times, most recently from d3e0f91 to 08a7ab5 Compare June 14, 2018 19:53
@dylad
Copy link
Member

dylad commented Jun 15, 2018

@smlng Can you tell us on which sensors did you test it ? It can help merging some devices faster at the same time.
I'll take a look at it but if @MrKevinWeiss or someone can test it. It would be awesome !

@smlng
Copy link
Member Author

smlng commented Jun 15, 2018

I used the reworked periph_i2c by @MrKevinWeiss for testing, this is even better than just using some i2c sensor driver.

@MrKevinWeiss
Copy link
Contributor

Ya, so far it looks like there is a way to go... I will play around with it for the remainder of the day but currently it seems like there is unexpected behavior in the remote-reva.

  • read/write to wrong addr will result in data clk after failed addr
  • a wrong addr write seems to block all reads until the correct write happens

I will spend the rest of the day trying to test/provide fix suggestions

@MrKevinWeiss
Copy link
Contributor

Man, I thought the sam_common0 had HW issues. So I believe that the hardware will automatically send/clk a data byte regardless of an addr ack. We probably have to accept it. It seems like the write addr ack error does not get cleared properly. If a read is issued after it will fail and will not be able to clear the byte (even though the scope looks fine). It seems the only way to clear the error is with a successful write...

DEBUG("\tI2C master error: ");
if (stat & DATACK) {
DEBUG("data ack lost!\n");
return -EIO;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can find a way to clear the error flags before exiting that would be nice... I ran out of time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I came to the same conclusion - will look into it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way I could clear the flag is with a successful write. Maybe try the standard solution? (turn it off and on again)

@smlng smlng mentioned this pull request Jun 18, 2018
@dylad
Copy link
Member

dylad commented Jun 18, 2018

@smlng Overall changes look ok but you need to add unsupported features check at the beginning of read_bytes and write_bytes.

if (flags & (I2C_REG16 | I2C_ADDR10)) {
    return -EOPNOTSUPP;
}

@jnohlgard
Copy link
Member

@dylad I edited your comment to fix some typos in the code example

@smlng
Copy link
Member Author

smlng commented Jun 18, 2018

@dylad good point, will do - but also need to sort out the write issue reported by @MrKevinWeiss

@MrKevinWeiss
Copy link
Contributor

I could be convinced to remove that from the test (or make it not critical). This would mean that there must be a successful write before a read can happen. Ideally there should be a reset of error state though. I imagine the hardware isn't the most versatile.

@smlng
Copy link
Member Author

smlng commented Jun 19, 2018

@MrKevinWeiss maybe the STOP command on error is not (always) needed, i.e., only put STOP when flags wasn't set in the original command. I need to tests this, because the data sheet doesn't say anything about reset error state (only IRQs), but it does say the STOP is either for successful write/read or error.

I also need to add the flags handling as noted by @dylad, try to get this done in the next hours.

@smlng
Copy link
Member Author

smlng commented Jun 20, 2018

hey @dylad I added the flags check and I (believe) have fixed read/write issue with wrong addresses -> need to access the data register before checking for errors 😩 @MrKevinWeiss can you verify by (re)testing? THX!!

@smlng smlng added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Jun 20, 2018
@MrKevinWeiss
Copy link
Contributor

So the problem of not clearing error flags before a read is still there. The test was altered to specify a successful write must occur before a read.
Also an error was expected when sending a nostart read outside of a frame and did not occur. The test was altered to allow for this.

It is up to you to decide if that should be acceptable behavior. Everything else seems to work fine (ie 99% of use cases).

Results

@MrKevinWeiss
Copy link
Contributor

If you would like to reproduce the two questionable error cases.

  1. Send read_reg to a incorrect addr, then read_bytes to the correct one
  2. Send a read_reg, then send a read_bytes with I2C_NOSTART flag active (should be an error since it no address should be sent after stop)

@MrKevinWeiss
Copy link
Contributor

Just to confirm if a NOSTART read is done it says it succeeds, nothing happens on the scope, it seems to just read back whatever data was last in the register... This is improper use of the I2C frame, if it is not easy to catch in hardware though maybe we just leave if for the time being.

@smlng smlng force-pushed the pr/cc2538/i2c branch 2 times, most recently from a383147 to 32cd13f Compare June 22, 2018 12:43
@MrKevinWeiss
Copy link
Contributor

I retested and it seems like the only issue left is the error flag not resetting when triggered with a NACK addr write. To keep things simple I suggest we just specify that any read should have had a ACKed write before. Eventually we will make this a warning for the test but not a test failure. If that is the case just make Travis happy then we can merge.

@MrKevinWeiss
Copy link
Contributor

Also I don't think new_i2c_if branch goes through murdock... but I could be wrong.

@dylad
Copy link
Member

dylad commented Jun 25, 2018

Murdock will only be used at the very end, right now, this branch is completely broken :)
For now, Travis is enough.

@smlng smlng removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jun 25, 2018
@MrKevinWeiss
Copy link
Contributor

@dylad Is it ok to merge? Aside from the one corner case I mentioned it seems to be alright!

@dylad
Copy link
Member

dylad commented Jun 25, 2018

Here we go !

@dylad dylad merged commit 6236fb0 into RIOT-OS:new_i2c_if Jun 25, 2018
@smlng smlng deleted the pr/cc2538/i2c branch June 25, 2018 12:26
basilfx pushed a commit to basilfx/RIOT that referenced this pull request Jul 10, 2018
cpu/cc2538: adapt periph to new I2C API
dylad added a commit to dylad/RIOT that referenced this pull request Jul 10, 2018
cpu/cc2538: adapt periph to new I2C API
dylad added a commit that referenced this pull request Jul 11, 2018
cpu/cc2538: adapt periph to new I2C API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. TF: I2C Marks issues and PRs related to the work of the I²C rework task force
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants