Skip to content

Conversation

maciejbocianski
Copy link
Contributor

Description

This PR is a continuation of the work done in #8682.
It contains all changes from #8682 plus:

  • hal-i2c slave mode fix for k64f
  • hal-i2c async mode implementation for k64f
  • I2CSlave driver adjustment to new HAL I2C API
  • async implementation in I2C driver

This PR contains reference implementations of the I2C HAL RFC changes for the FRDM-K64F and NUCLEO_F070RB boards.

  • TasksK64F Sync
  • STM32 Sync
  • STM32 Async
  • Driver API Sync
  • Driver API Async

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[X] Breaking change

Reviewers

@ARMmbed/mbed-os-hal

Release Notes

@maciejbocianski
Copy link
Contributor Author

maciejbocianski commented Apr 11, 2019

fixing astyle ...done

@ciarmcom ciarmcom requested a review from a team April 11, 2019 11:00
@ciarmcom
Copy link
Member

@maciejbocianski, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@maciejbocianski
Copy link
Contributor Author

Test results of (#9573):

master(NUCLEO_F070RB) - slave(K64F)
+--------------------------------------------------------------+---------+-------------+-------------+--------------------+----------+
| Testcase                                                     | Verdict | Fail Reason | Skip Reason |     platforms      | duration |
+--------------------------------------------------------------+---------+-------------+-------------+--------------------+----------+
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1B_MIN_FREQUENCY         |   pass  |             |             | NUCLEO_F070RB,K64F |  1.269   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1B_MAX_FREQUENCY    |   pass  |             |             | NUCLEO_F070RB,K64F |  1.365   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1025B_MAX_FREQUENCY |   pass  |             |             | NUCLEO_F070RB,K64F |  2.088   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_257B_MAX_FREQUENCY     |   pass  |             |             | NUCLEO_F070RB,K64F |  1.484   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1B_MIN_FREQUENCY    |   pass  |             |             | NUCLEO_F070RB,K64F |  1.265   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_257B_MIN_FREQUENCY  |   pass  |             |             | NUCLEO_F070RB,K64F |  2.696   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_257B_MAX_FREQUENCY  |   pass  |             |             | NUCLEO_F070RB,K64F |  1.534   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_10B_MIN_FREQUENCY      |   pass  |             |             | NUCLEO_F070RB,K64F |   1.39   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_257B_MAX_FREQUENCY       |   pass  |             |             | NUCLEO_F070RB,K64F |   1.48   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_10B_MAX_FREQUENCY      |   pass  |             |             | NUCLEO_F070RB,K64F |  1.269   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1025B_MAX_FREQUENCY      |   pass  |             |             | NUCLEO_F070RB,K64F |   2.12   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_257B_MIN_FREQUENCY       |   pass  |             |             | NUCLEO_F070RB,K64F |  2.825   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1B_MAX_FREQUENCY         |   pass  |             |             | NUCLEO_F070RB,K64F |  1.124   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_10B_MAX_FREQUENCY   |   pass  |             |             | NUCLEO_F070RB,K64F |  1.204   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_10B_MIN_FREQUENCY        |   pass  |             |             | NUCLEO_F070RB,K64F |  1.299   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_10B_MIN_FREQUENCY   |   pass  |             |             | NUCLEO_F070RB,K64F |  1.355   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_10B_MAX_FREQUENCY        |   pass  |             |             | NUCLEO_F070RB,K64F |  1.249   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_1B_MAX_FREQUENCY       |   pass  |             |             | NUCLEO_F070RB,K64F |  1.236   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_1B_MIN_FREQUENCY       |   pass  |             |             | NUCLEO_F070RB,K64F |   1.21   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_257B_MIN_FREQUENCY     |   pass  |             |             | NUCLEO_F070RB,K64F |  2.775   |
+--------------------------------------------------------------+---------+-------------+-------------+--------------------+----------+

master(K64F) - slave(NUCLEO_F070RB)
+--------------------------------------------------------------+---------+-------------+-------------+--------------------+----------+
| Testcase                                                     | Verdict | Fail Reason | Skip Reason |     platforms      | duration |
+--------------------------------------------------------------+---------+-------------+-------------+--------------------+----------+
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1B_MIN_FREQUENCY         |   pass  |             |             | K64F,NUCLEO_F070RB |  1.254   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1B_MAX_FREQUENCY    |   pass  |             |             | K64F,NUCLEO_F070RB |  1.301   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1025B_MAX_FREQUENCY |   pass  |             |             | K64F,NUCLEO_F070RB |  1.865   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_257B_MAX_FREQUENCY     |   pass  |             |             | K64F,NUCLEO_F070RB |  1.475   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1B_MIN_FREQUENCY    |   pass  |             |             | K64F,NUCLEO_F070RB |  1.236   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_257B_MIN_FREQUENCY  |   pass  |             |             | K64F,NUCLEO_F070RB |  2.827   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_257B_MAX_FREQUENCY  |   pass  |             |             | K64F,NUCLEO_F070RB |  1.553   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_10B_MIN_FREQUENCY      |   pass  |             |             | K64F,NUCLEO_F070RB |  1.341   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_257B_MAX_FREQUENCY       |   pass  |             |             | K64F,NUCLEO_F070RB |  1.576   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_10B_MAX_FREQUENCY      |   pass  |             |             | K64F,NUCLEO_F070RB |  1.203   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1025B_MAX_FREQUENCY      |   pass  |             |             | K64F,NUCLEO_F070RB |  1.916   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_257B_MIN_FREQUENCY       |   pass  |             |             | K64F,NUCLEO_F070RB |  2.699   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1B_MAX_FREQUENCY         |   pass  |             |             | K64F,NUCLEO_F070RB |  1.184   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_10B_MAX_FREQUENCY   |   pass  |             |             | K64F,NUCLEO_F070RB |  1.277   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_10B_MIN_FREQUENCY        |   pass  |             |             | K64F,NUCLEO_F070RB |  1.342   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_10B_MIN_FREQUENCY   |   pass  |             |             | K64F,NUCLEO_F070RB |  1.321   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_10B_MAX_FREQUENCY        |   pass  |             |             | K64F,NUCLEO_F070RB |  1.274   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_1B_MAX_FREQUENCY       |   pass  |             |             | K64F,NUCLEO_F070RB |  1.244   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_1B_MIN_FREQUENCY       |   pass  |             |             | K64F,NUCLEO_F070RB |  1.219   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_257B_MIN_FREQUENCY     |   pass  |             |             | K64F,NUCLEO_F070RB |   2.68   |
+--------------------------------------------------------------+---------+-------------+-------------+--------------------+----------+

master(K64F) - slave(K64F)
+--------------------------------------------------------------+---------+-------------+-------------+-----------+----------+
| Testcase                                                     | Verdict | Fail Reason | Skip Reason | platforms | duration |
+--------------------------------------------------------------+---------+-------------+-------------+-----------+----------+
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1B_MIN_FREQUENCY         |   pass  |             |             |    K64F   |  1.241   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1B_MAX_FREQUENCY    |   pass  |             |             |    K64F   |  1.195   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1025B_MAX_FREQUENCY |   pass  |             |             |    K64F   |  1.891   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_257B_MAX_FREQUENCY     |   pass  |             |             |    K64F   |  1.426   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_1B_MIN_FREQUENCY    |   pass  |             |             |    K64F   |  1.256   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_257B_MIN_FREQUENCY  |   pass  |             |             |    K64F   |  2.564   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_257B_MAX_FREQUENCY  |   pass  |             |             |    K64F   |  1.459   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_10B_MIN_FREQUENCY      |   pass  |             |             |    K64F   |  1.332   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_257B_MAX_FREQUENCY       |   pass  |             |             |    K64F   |  1.497   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_10B_MAX_FREQUENCY      |   pass  |             |             |    K64F   |  1.218   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1025B_MAX_FREQUENCY      |   pass  |             |             |    K64F   |   2.01   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_257B_MIN_FREQUENCY       |   pass  |             |             |    K64F   |  2.674   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_1B_MAX_FREQUENCY         |   pass  |             |             |    K64F   |  1.239   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_10B_MAX_FREQUENCY   |   pass  |             |             |    K64F   |  1.211   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_10B_MIN_FREQUENCY        |   pass  |             |             |    K64F   |  1.296   |
| I2C_COM_MASTER-SLAVE_BLOCKING_WRITE-READ_10B_MIN_FREQUENCY   |   pass  |             |             |    K64F   |  1.351   |
| I2C_COM_MASTER-SLAVE_ASYNC_TRANSFER_10B_MAX_FREQUENCY        |   pass  |             |             |    K64F   |  1.185   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_1B_MAX_FREQUENCY       |   pass  |             |             |    K64F   |  1.271   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_1B_MIN_FREQUENCY       |   pass  |             |             |    K64F   |  1.278   |
| I2C_COM_MASTER-SLAVE_ASYNC_WRITE-READ_257B_MIN_FREQUENCY     |   pass  |             |             |    K64F   |   2.7    |
+--------------------------------------------------------------+---------+-------------+-------------+-----------+----------+

@ithinuel
Copy link
Member

Under review

@0xc0170 0xc0170 mentioned this pull request Apr 12, 2019
Copy link
Member

@ithinuel ithinuel left a comment

Choose a reason for hiding this comment

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

  • There are inconsistencies on address' maximum lenght (9/10bits)
  • The API snippet of the design doc is inconsistent with the statements made before (eg. stop argument to i2c_read and i2c_write).
  • Why Async has a single "transfer" while sync has "read" and "write" ?
  • What is the other of read/write operations in Async ?
  • How the device is expected to process an abort of the transfer ?
    • Should it send a stop if one was requested ?
      • Are symbols atomic ? That is to say, should the transfer stop in the middle of a transmission when abort is called or should it gracefully stop after the current symbol ?
      • Is an abort considered an error and should it be reported as such in the event ?
      • Is the event callback invoked at all in case of abort ?

There are also typos here and there but they're minor issues in regards to the comment above & in the code.

I have not reviewed (yet) the implementations as I don't know (yet) the platform, my feedback on these would not be very deep. And the API should probably be fixed before we give attention to the details of the implementations.

I2C *I2C::_owner = NULL;
SingletonPtr<PlatformMutex> I2C::_mutex;

I2C::I2C(PinName sda, PinName scl) :
Copy link
Member

Choose a reason for hiding this comment

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

This implementation does not seem to deal with multiple i2c peripheral used in parallel very well.

  • Only 1 I2C can be used at a time.
  • There is no mechanism that I can see that prevent an i²c peripheral to be instantiated twice.
  • The I2C class seem to be oriented to have 1 instance per bus instead of 1 instance per slave like SPI class does.
    This is probably out of the scope of this PR as it'd create breaking change on the C++ API level but it is still worth nothing that this is inconsistent and should be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree the improvement of I2C and I2CSlave drivers should be in separate PR. This PR should include only adaptation to HAL API changes

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, adding extra functionality to the driver is out of scope


Currently the `DMAUsage` argument of the `i2c_transfer_asynch` function is unimplemented, the argument is unused by all `I2C` implementations. There is no real demand for it so can be removed from the API.

- **Change** the `stop` parameter from the `i2c_transfer_async` from an `uint32_t` to a `bool`.
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this argument removed Since it is also removed from the sync API ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually stop stays for both sync and async API

* @param data The buffer for sending
* @param length Number of bytes to write
* @param stop Stop to be generated after the transfer is done
* @param stop If true, stop will be generated after the transfer is done
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be removed from the parameter list as per the design doc ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stop stays

@mbed-ci
Copy link

mbed-ci commented Apr 16, 2019

Test run: FAILED

Summary: 5 of 7 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_mbed2-build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_mbed2-build-IAR

@adbridge
Copy link
Contributor

@ithinuel Could you please re-review?

@0xc0170
Copy link
Contributor

0xc0170 commented May 3, 2019

@ithinuel @maciejbocianski Any update? Is there anyone else who could review?

@maciejbocianski
Copy link
Contributor Author

Update for both doc and reference implementation will be available within this week

@maciejbocianski
Copy link
Contributor Author

maciejbocianski commented May 10, 2019

@ithinuel

  • typos has been fixed
  • API header file/design doc inconsistencies has been fixed
  • single ASYNC transfer function was inherited from old API and also I2C driver has single ASYNC transfer function. But actually I don't see the advantage of such API over two separata write/read function . Anyway, single ASYNC transfer function works as write and then read done one after the other. So it would be easily replaced by two functions
  • I can see that at abort sends stop signal unconditionally (at least STM and freescale SDK implementations does)
  • I2C uses byte transfer (symbol == one byte) and each byte is confirmed so single byte send is atomic
  • calling i2c_abort_async disables async callback mechanism

@adbridge
Copy link
Contributor

@ithinuel could you re-review this please

Copy link
Contributor

@jamesbeyond jamesbeyond left a comment

Choose a reason for hiding this comment

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

I am happy about the changes

@maciejbocianski
Copy link
Contributor Author

@ithinuel
after review changes:

  • i2c structure update
  • timeout functionality update
  • doc fixes/update

@maciejbocianski maciejbocianski force-pushed the i2c_ref_impl branch 2 times, most recently from d775f47 to 86c5f6c Compare May 27, 2019 13:07
@maciejbocianski
Copy link
Contributor Author

rebased

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 25, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Jun 25, 2019

Test run: FAILED

Summary: 6 of 7 test jobs failed
Build number : 5
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_mbed2-build-ARM
  • jenkins-ci/mbed-os-ci_mbed2-build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_mbed2-build-IAR
  • jenkins-ci/mbed-os-ci_build-ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 26, 2019

Please review build failures, related

@maciejbocianski
Copy link
Contributor Author

Fixes for specific errors were provided
Can we rerun CI to check if mbed-os-example-mesh-minima and nanostack-border-router still fail (locally on my PC both succeeded)

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 26, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Jun 26, 2019

Test run: FAILED

Summary: 3 of 7 test jobs failed
Build number : 6
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 26, 2019

restarted

@mbed-ci
Copy link

mbed-ci commented Jun 26, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 7
Build artifacts

@0xc0170 0xc0170 merged commit 42cafe6 into ARMmbed:feature-i2c Jun 28, 2019
@AnotherButler
Copy link
Contributor

Can someone please review ARMmbed/mbed-os-5-docs#807 to make sure it's up to date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants