-
Notifications
You must be signed in to change notification settings - Fork 3k
Dev stm i2c v2 unitary functions #3488
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
STM32 supported targets have 2 possible versions of I2C. This patch makes the start / stop / read and write byte work ok for IP V2. This was not working before and does not seem to be widely used.
This avoids conflicts with slave on ci-test-shield
depending on timing and HW, there might be some delay before the master request gets notified, so better loop in while than a single call to slave.receive()
it's master not slave that shall send STOP at the end of I2C transfer
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 for all of your work on this! I've found a few lines that need some clarification, could you please take a look?
@@ -514,7 +525,7 @@ int i2c_byte_read(i2c_t *obj, int last) { | |||
timeout = FLAG_TIMEOUT; | |||
while (__HAL_I2C_GET_FLAG(handle, I2C_FLAG_RXNE) == RESET) { | |||
if ((timeout--) == 0) { | |||
return -1; | |||
return 2; |
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.
Can you clarify the reason for this change? Seems like this should return an error instead of what could be considered valid data?
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.
that's how this is defined in the MBED HAL API of i2c_byte_read
https://github.com/ARMmbed/mbed-os/blob/master/hal/i2c_api.h#L144
- @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
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.
@LMESTM the line you have highlighted for i2c_byte_write
, not i2c_byte_read
.
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.
@bridadan sorry ! I missed the point ... will post an update
if ((tmpreg & I2C_CR2_RELOAD) != 0) { | ||
while (!__HAL_I2C_GET_FLAG(handle, I2C_FLAG_TCR)) { | ||
if ((timeout--) == 0) { | ||
printf("timeout in byte_read\r\n"); |
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.
Looks like this printf
was left in by mistake? This should probably just return an error code (or maybe print a debug message if debug messages are enabled? Haven't looked at our debug prints in a while though...)
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.
right - will correct this !
if ((timeout--) == 0) { | ||
return -1; | ||
return 2; |
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.
Similar comment to what I made above. If this is a timeout, we probably shouldn't return anything non-negative, as that could be perceived as actual data, correct?
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.
same as above
if ((tmpreg & I2C_CR2_RELOAD) != 0) { | ||
while (!__HAL_I2C_GET_FLAG(handle, I2C_FLAG_TCR)) { | ||
if ((timeout--) == 0) { | ||
printf("timeout in byte_write\r\n"); |
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.
Found another printf
!
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.
will correct - thx for review
@LMESTM bump btw, where is version v2 macro defined? |
Few debug lines were to be removed / updated. Move the printf to DEBUG_PRINTF and return the error when needed.
@bridadan please review again |
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 for removing the printfs! I still have concerns over the return value for i2c_byte_read
. The return values are different than that of i2c_byte_write
, but this PR makes them the same.
To make clear that an error is being reported, we shall report -1, 2 being the timeout error for i2c_byte_write only.
@LMESTM I noticed |
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.
Great work!
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
@VeliMattiLahtela Can you comment on the Oulu CI failure please? |
@0xc0170 Issue #3522 submitted |
@bridadan sounds good - thx ! |
Ports for Upcoming Targets Fixes and Changes 3488: Dev stm i2c v2 unitary functions ARMmbed/mbed-os#3488 3492: Fix #3463 CAN read() return value ARMmbed/mbed-os#3492 3503: [LPC15xx] Ensure that PWM=1 is resolved correctly ARMmbed/mbed-os#3503 3504: [LPC15xx] CAN implementation improvements ARMmbed/mbed-os#3504 3539: NUCLEO_F412ZG - Add support of TRNG peripheral ARMmbed/mbed-os#3539 3540: STM: SPI: Initialize Rx in spi_master_write ARMmbed/mbed-os#3540 3438: K64F: Add support for SERIAL ASYNCH API ARMmbed/mbed-os#3438 3519: MCUXpresso: Fix ENET driver to enable interrupts after interrupt handler is set ARMmbed/mbed-os#3519 3544: STM32L4 deepsleep improvement ARMmbed/mbed-os#3544 3546: NUCLEO-F412ZG - Add CAN peripheral ARMmbed/mbed-os#3546 3551: Fix I2C driver for RZ/A1H ARMmbed/mbed-os#3551 3558: K64F UART Asynch API: Fix synchronization issue ARMmbed/mbed-os#3558 3563: LPC4088 - Fix vector checksum ARMmbed/mbed-os#3563 3567: Dev stm32 F0 v1.7.0 ARMmbed/mbed-os#3567 3577: Fixes linking errors when building with debug profile ARMmbed/mbed-os#3577
Description
This PR shall close my recent series of rework (and fixes) to get STM32 I2C into a single file.
This one covers the unitary start / stop / byte read and write functions for STM32 for F0, F3, F3, L0 and L4 families.
Status
Status READY
Test report:

Related PRs
To have ARM ci test shield I2C tests working ok as well on those targets, an update of the I2Ceeprom driver is also needed on top of this PR. The proposed patch has been submitted here:
https://developer.mbed.org/users/LMESTM/code/I2CEeprom/
With the I2Ceeprom driver update and this PR, the I2C ci test shield is tested ok:
+-------------------+---------------+---------------+------------------------------------+--------+--------+--------+--------------------+
| target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
+-------------------+---------------+---------------+------------------------------------+--------+--------+--------+--------------------+
| NUCLEO_L073RZ-ARM | NUCLEO_L073RZ | tests-api-i2c | I2C - EEProm WR 10 Bytes | 1 | 0 | OK | 0.06 |
| NUCLEO_L073RZ-ARM | NUCLEO_L073RZ | tests-api-i2c | I2C - EEProm WR 100 Bytes | 1 | 0 | OK | 0.08 |
| NUCLEO_L073RZ-ARM | NUCLEO_L073RZ | tests-api-i2c | I2C - EEProm WR 2 Bytes | 1 | 0 | OK | 0.06 |
| NUCLEO_L073RZ-ARM | NUCLEO_L073RZ | tests-api-i2c | I2C - EEProm WR Single Byte | 1 | 0 | OK | 0.02 |
| NUCLEO_L073RZ-ARM | NUCLEO_L073RZ | tests-api-i2c | I2C - Instantiation of I2C Object | 1 | 0 | OK | 0.03 |
| NUCLEO_L073RZ-ARM | NUCLEO_L073RZ | tests-api-i2c | I2C - LM75B Temperature Read | 1 | 0 | OK | 0.07 |
+-------------------+---------------+---------------+------------------------------------+--------+--------+--------+--------------------+