[riot-notifications] [RIOT-OS/RIOT] cpu/efm32: fix i2c transfers (#15764)

Bas Stottelaar notifications at github.com
Wed Jan 13 22:55:22 CET 2021


### Contribution description
This PR fixes the current state of the EFM32 I2C driver.

I was using `i2c_scan` until I noticed that the driver will block forever if no device is attached. The root cause of this is caused by the I2C transfer state 'internally' waiting for an ACK or NACK. Since it this would never happen, no interrupt was triggered and [this](https://github.com/RIOT-OS/RIOT/blob/master/cpu/efm32/periph/i2c.c#L68) would block forever.

Part of this problem is caused by `i2c_init` not initializing the pins correctly. They should be open drain with pull-up, based on a [kit driver](https://siliconlabs.github.io/Gecko_SDK_Doc/efm32g/html/i2cspm_8c_source.html#l00039). 4e7df52 fixes this, which will make the problem above less likely.

Still, a rouge sensor could trigger the problem above without ed88c59. This commit removes the `cortexm_sleep_until_event` so that it will just busy-loop, guaranteeing that this loop will finish. This will be less-efficient, but without something like the [ESP32](https://github.com/RIOT-OS/RIOT/blob/master/cpu/esp32/periph/i2c_hw.c#L727-L728) does, I don't have a proper solution.

### Testing procedure
Without this PR, `USEMODULE=i2c_scan make -C examples/default -j16 flash` for a board without I2C devices on-board (e.g. (STK3200, STK3600). 

Without this PR, it will block:

```
> i2c_scan 0
Scanning I2C device 0...
addr not ack'ed = "-", addr ack'ed = "X", addr reserved = "R", error = "E"
     0 1 2 3 4 5 6 7 8 9 a b c d e f
```

With this PR, the output looks like:

```
> i2c_scan 0
Scanning I2C device 0...
addr not ack'ed = "-", addr ack'ed = "X", addr reserved = "R", error = "E"
     0 1 2 3 4 5 6 7 8 9 a b c d e f
0x00 R R R R R R R R R R R R R R - -
0x10 - - - - - - - - - - - - - - - -
0x20 - - - - - - - - - - - - - - - -
0x30 - - - - - - - - - - - - - - - -
0x40 - - - - - - - - - - - - - - - -
0x50 - - - - - - - - - - - - - - - -
0x60 - - - - - - - - - - - - - - - -
0x70 - - - - - - - - R R R R R R R R
```

Without 4e7df52, the output would be:

```
> i2c_scan 0
Scanning I2C device 0...
addr not ack'ed = "-", addr ack'ed = "X", addr reserved = "R", error = "E"
     0 1 2 3 4 5 6 7 8 9 a b c d e f
0x00 R R R R R R R R R R R R R R E E
0x10 E E E E E E E E E E E E E E E E
0x20 E E E E E E E E E E E E E E E E
0x30 E E E E E E E E E E E E E E E E
0x40 E E E E E E E E E E E E E E E E
0x50 E E E E E E E E E E E E E E E E
0x60 E E E E E E E E E E E E E E E E
0x70 E E E E E E E E R R R R R R R R
```

A board with sensors will return the following (e.g. SLTB001a):

```
> i2c_scan 0
Scanning I2C device 0...
addr not ack'ed = "-", addr ack'ed = "X", addr reserved = "R", error = "E"
     0 1 2 3 4 5 6 7 8 9 a b c d e f
0x00 R R R R R R R R R R R R R R - -
0x10 - - - - - - - - - - - - - - - -
0x20 - - - - - - - - - - - - - - - -
0x30 X - - - - - - - - - - - - - - -
0x40 X - - - - - - - - - - - - - - -
0x50 - - - - - X - - - - X - - - - -
0x60 - - - - - - - - - - - - - - - -
0x70 - - - - - - - X R R R R R R R R
```

### Issues/PRs references
None
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/15764

-- Commit Summary --

  * cpu/efm32: fix busy-loop for transfers
  * cpu/efm32: init pins with GPIO_OD_PU

-- File Changes --

    M cpu/efm32/periph/i2c.c (45)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/15764.patch
https://github.com/RIOT-OS/RIOT/pull/15764.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15764
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210113/355e3694/attachment.htm>


More information about the notifications mailing list