-
Notifications
You must be signed in to change notification settings - Fork 2k
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/stm_common: Refactor and cleanup i2c_1 #10610
Conversation
9daab57
to
a6320cd
Compare
This needs a rebase @MrKevinWeiss |
On it! |
a6320cd
to
7d095c0
Compare
aaf64ec
to
d201a97
Compare
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.
I tested this PR on L0, L4, F0, F3 and F7. It works like a charm with the sensor I have (hts221). I didn't push the testing further.
I have minor comments inline.
My general impression is that it is a very good job and I'd like to have it in the release :)
cpu/stm32_common/periph/i2c_1.c
Outdated
} | ||
|
||
/** | ||
* Cannot support continuous writes or fram splitting at this level. If an |
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.
s/fram/frame
cpu/stm32_common/periph/i2c_1.c
Outdated
size_t length, uint8_t flags, uint32_t cr2_flags) | ||
{ | ||
assert(i2c != NULL); | ||
assert(length < 256); |
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.
why ? Can we have a macro defined for this ?
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.
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.
Why the length limitation or why not combine both in a macro?
If length then it is because I would have to do a check to see if it is greater, if it is set the reload bit and keep track of everything sent. It adds extra steps and I don't know how valuable it would be (even for something like EEPROM, when you are talking about 256 bytes adding a start and stop frame isn't that much overhead).
cpu/stm32_common/periph/i2c_1.c
Outdated
if ((flags & I2C_REG16) || (flags & I2C_ADDR10)) { | ||
/* If reload was set, cannot send a repeated start */ | ||
if ((i2c->ISR & I2C_ISR_TCR) && | ||
!(flags & I2C_NOSTART)) { |
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 can be on the same line above
cpu/stm32_common/periph/i2c_1.c
Outdated
} | ||
/* If reload was NOT set, must either stop or start */ | ||
if ((i2c->ISR & I2C_ISR_TC) && | ||
(flags & I2C_NOSTART)) { |
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 can be on the same line above
cpu/stm32_common/periph/i2c_1.c
Outdated
int ret = _start(i2c, | ||
(address << 1) | | ||
(length << I2C_CR2_NBYTES_Pos) | | ||
/* I2C_FLAG_WRITE | */ |
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.
Maybe remove ?
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.
I think I would prefer to have all parameters on the same line
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.
OK will do
d201a97
to
542f7a2
Compare
@aabadie I think I did what you want. |
cpu/stm32_common/periph/i2c_1.c
Outdated
{ | ||
assert(dev < I2C_NUMOF); | ||
assert(dev < I2C_NUMOF && length < 256); |
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.
I was thinking of having a define for 256. To avoid hard coded values in the code and to have it defined once.
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.
Yup, makes sense, on it.
#define PERIPH_I2C_NEED_WRITE_REGS | ||
#endif | ||
|
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 blank line could be removed
Refactor to use common read_regs. Add error reporting and handling for unsupported low level commands. Document hardware constraints.
542f7a2
to
f3b2a62
Compare
@aabadie All done! |
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.
Thanks again for the cleanup and fixes in the I2C driver. It looks and works much better now.
I'm just wondering if we shouldn't also handle the case where more than 256 bytes are transferred on the bus. I was comparing the implementation with the reference manual, from page 713 to 718, and it seems it could be done. Maybe later though. What do you think ?
It is possible but I am not sure it is worth the extra code size at the moment. If anyone requests it in the future I can add it. |
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.
I think we are good then.
ACK and go!
Contribution description
This PR fixes many bugs discovered by the HiL.
Testing procedure
Test on stm32f0, f3, f7, l0 or l4
One can run the robot-test from the HiL branch or run term in tests/periph_i2c/
Or run manually against your favorite i2c device. No everything will be supported but everything should at least give correct error messages and not lock up the bus.
Issues/PRs references
checks some boxes in #9518
helps with some stm32 based boards for #3366
depends on #10608