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

smbus read_i2c_block_data Fails on Latest Kernel #828

Closed
DexterInd opened this Issue Jun 19, 2017 · 40 comments

Comments

Projects
None yet
10 participants
@ghost

ghost commented Jun 19, 2017

Hey folks, noticed a problem when we went to update to the latest kernel on June 17 2017. I tried to isolate it as best I could with the following description. The smbus call read_i2c_block_data fails to do a block read. A couple of quick bullet

  • This does not seem to affect the write function or the single byte read function on smbus.
  • The clock speed of I2C has not changed.
  • I'm able to reproduce the problem using the same hardware (Pi3), a voltage level converter, and an atmega chip.
  • The I2C function clearly works with kernel 4.4.50-v7+
  • The I2C function fails when I update to kernel 4.9.24-v7+

I did the following to test and isolate the problem with the firmware, I created the following python script (pasted below). First, running on Jessi Lite 2017.01.11 I checked the kernel version, the updated Jessi Lite with the necessary support

#   sudo apt-get install python-pip python-smbus
#   sudo pip install future
#   sudo raspi-config to enable i2c

Running with the older firmware, I get a healthy response from the function read_i2c_block_data.

I2C Working

Then, updating to the latest firmware 4.9+ I run the same python script, and get a failure to read.

I2C NOT Working

Below is the python code you can use to replicate the problem.

# Start with raspbian jessi lite 2017.01.11
# Prep with 
#   sudo apt-get install python-pip python-smbus
#   sudo pip install future
#   sudo raspi-config to enable i2c

#   This works at first using FW version    -   Linux raspberrypi 4.4.50-v7+

#   Update the firmware with sudo apt-get update && sudo apt-get install raspberrypi-kernel
#   sudo reboot
#   To not working with version FW          -   Linux raspberrypi 4.9.24-v7+ #993

from __future__ import print_function
from __future__ import division
from builtins import input

import time
import smbus
import time
import math
import RPi.GPIO as GPIO
import struct
import operator
import pickle

# This allows us to be more specific about which commands contain unused bytes
unused = 0

rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
	bus = smbus.SMBus(1)
else:
	bus = smbus.SMBus(0)

# I2C Address of Arduino
address = 0x06

# Command Format
# analogRead() command format header
aRead_cmd = [3]

def read_sensor():
    time.sleep(1)
    try:
        bus.write_i2c_block_data(address, 1, aRead_cmd + [unused, unused, unused])
        number = bus.read_i2c_block_data(address, 1)
        return number[0]* 256 + number[1],number[2]* 256 + number[3],number[4]* 256 + number[5],number[6]* 256 + number[7],number[8]* 256 + number[9]
        time.sleep(.05)
    except IOError:
        return -1,-1,-1,-1,-1

while True:
    print(read_sensor())`

@DexterInd DexterInd changed the title from smbus read_i2c_block_data fails to smbus read_i2c_block_data Fails on Latest Kernel Jun 19, 2017

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 19, 2017

Sorry, one more piece of info on this: If I roll back the kernel version to kernel 4.4.50-v7+ the python function begins to read properly again.

ghost commented Jun 19, 2017

Sorry, one more piece of info on this: If I roll back the kernel version to kernel 4.4.50-v7+ the python function begins to read properly again.

@P33M

This comment has been minimized.

Show comment
Hide comment
@P33M

P33M Jun 19, 2017

In the second (broken) trace, the transfer diverges at the third Start bus state. The second transfer looks like it's doing a repeated start but terminating after a byte, whereas the first transfer does a stop then start and continues normally.

What is the output of lsmod on both 4.4 and 4.9?

P33M commented Jun 19, 2017

In the second (broken) trace, the transfer diverges at the third Start bus state. The second transfer looks like it's doing a repeated start but terminating after a byte, whereas the first transfer does a stop then start and continues normally.

What is the output of lsmod on both 4.4 and 4.9?

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 19, 2017

Contributor

Can you try adding dtoverlay=i2c1_bcm2708? This reverts to using the old downstream I2C driver.

Contributor

pelwell commented Jun 19, 2017

Can you try adding dtoverlay=i2c1_bcm2708? This reverts to using the old downstream I2C driver.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 20, 2017

@P33M Re output of lsmod:

For 4.4.50-v7+

Module                  Size  Used by
bnep                   10340  2
bluetooth             326105  5 bnep
lirc_dev                8310  0
rc_core                16468  1 lirc_dev
sg                     18319  0
brcmfmac              186403  0
brcmutil                5661  1 brcmfmac
cfg80211              428871  1 brcmfmac
rfkill                 16037  4 cfg80211,bluetooth
snd_bcm2835            20447  2
snd_pcm                75762  1 snd_bcm2835
snd_timer              19288  1 snd_pcm
snd                    51908  7 snd_bcm2835,snd_timer,snd_pcm
bcm2835_gpiomem         2976  2
spi_bcm2835             6678  0
bcm2835_wdt             3225  0
uio_pdrv_genirq         3164  0
uio                     8000  1 uio_pdrv_genirq
i2c_dev                 5859  0
i2c_bcm2708             4834  0
fuse                   84037  5
ipv6                  347620  61

After an upgrade . . .
For 4.9.28-v7+

Module                  Size  Used by
bnep                   12051  2
hci_uart               19956  1
btbcm                   7916  1 hci_uart
bluetooth             365511  22 hci_uart,bnep,btbcm
sg                     20825  0
brcmfmac              222874  0
brcmutil                9092  1 brcmfmac
cfg80211              543027  1 brcmfmac
rfkill                 20851  4 bluetooth,cfg80211
snd_bcm2835            24427  0
snd_pcm                98501  1 snd_bcm2835
snd_timer              23904  1 snd_pcm
snd                    70032  3 snd_timer,snd_bcm2835,snd_pcm
i2c_bcm2835             7167  0
bcm2835_gpiomem         3940  0
fixed                   3285  0
uio_pdrv_genirq         3923  0
uio                    10204  1 uio_pdrv_genirq
i2c_dev                 6913  0
ipv6                  406751  33

ghost commented Jun 20, 2017

@P33M Re output of lsmod:

For 4.4.50-v7+

Module                  Size  Used by
bnep                   10340  2
bluetooth             326105  5 bnep
lirc_dev                8310  0
rc_core                16468  1 lirc_dev
sg                     18319  0
brcmfmac              186403  0
brcmutil                5661  1 brcmfmac
cfg80211              428871  1 brcmfmac
rfkill                 16037  4 cfg80211,bluetooth
snd_bcm2835            20447  2
snd_pcm                75762  1 snd_bcm2835
snd_timer              19288  1 snd_pcm
snd                    51908  7 snd_bcm2835,snd_timer,snd_pcm
bcm2835_gpiomem         2976  2
spi_bcm2835             6678  0
bcm2835_wdt             3225  0
uio_pdrv_genirq         3164  0
uio                     8000  1 uio_pdrv_genirq
i2c_dev                 5859  0
i2c_bcm2708             4834  0
fuse                   84037  5
ipv6                  347620  61

After an upgrade . . .
For 4.9.28-v7+

Module                  Size  Used by
bnep                   12051  2
hci_uart               19956  1
btbcm                   7916  1 hci_uart
bluetooth             365511  22 hci_uart,bnep,btbcm
sg                     20825  0
brcmfmac              222874  0
brcmutil                9092  1 brcmfmac
cfg80211              543027  1 brcmfmac
rfkill                 20851  4 bluetooth,cfg80211
snd_bcm2835            24427  0
snd_pcm                98501  1 snd_bcm2835
snd_timer              23904  1 snd_pcm
snd                    70032  3 snd_timer,snd_bcm2835,snd_pcm
i2c_bcm2835             7167  0
bcm2835_gpiomem         3940  0
fixed                   3285  0
uio_pdrv_genirq         3923  0
uio                    10204  1 uio_pdrv_genirq
i2c_dev                 6913  0
ipv6                  406751  33
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 20, 2017

@pelwell to test this, I pasted dtoverlay=i2c1_bcm2708 in /boot/config.txt and rebooted. I am still seeing the same behavior. Was there anything else I was supposed to do?

When I do that I see:

pi@raspberrypi:~ $ lsmod
Module                  Size  Used by
bnep                   12051  2
hci_uart               19956  1
btbcm                   7916  1 hci_uart
bluetooth             365511  22 hci_uart,bnep,btbcm
sg                     20825  0
brcmfmac              222874  0
brcmutil                9092  1 brcmfmac
cfg80211              543027  1 brcmfmac
rfkill                 20851  4 bluetooth,cfg80211
snd_bcm2835            24427  0
i2c_bcm2835             7167  0
snd_pcm                98501  1 snd_bcm2835
snd_timer              23904  1 snd_pcm
snd                    70032  3 snd_timer,snd_bcm2835,snd_pcm
bcm2835_gpiomem         3940  0
fixed                   3285  0
uio_pdrv_genirq         3923  0
uio                    10204  1 uio_pdrv_genirq
i2c_dev                 6913  0
ipv6                  406751  34

ghost commented Jun 20, 2017

@pelwell to test this, I pasted dtoverlay=i2c1_bcm2708 in /boot/config.txt and rebooted. I am still seeing the same behavior. Was there anything else I was supposed to do?

When I do that I see:

pi@raspberrypi:~ $ lsmod
Module                  Size  Used by
bnep                   12051  2
hci_uart               19956  1
btbcm                   7916  1 hci_uart
bluetooth             365511  22 hci_uart,bnep,btbcm
sg                     20825  0
brcmfmac              222874  0
brcmutil                9092  1 brcmfmac
cfg80211              543027  1 brcmfmac
rfkill                 20851  4 bluetooth,cfg80211
snd_bcm2835            24427  0
i2c_bcm2835             7167  0
snd_pcm                98501  1 snd_bcm2835
snd_timer              23904  1 snd_pcm
snd                    70032  3 snd_timer,snd_bcm2835,snd_pcm
bcm2835_gpiomem         3940  0
fixed                   3285  0
uio_pdrv_genirq         3923  0
uio                    10204  1 uio_pdrv_genirq
i2c_dev                 6913  0
ipv6                  406751  34
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 20, 2017

@pelwell also just tried to change that line to dtoverlay=i2c1_bcm2708,sda1_pin=2,scl1=3,pin_func=6 (I am not sure where to find the numbering for the GPIO's). This didn't change the i2c behavior.

Output of lsmod is:

pi@raspberrypi:~ $ lsmod
Module                  Size  Used by
bnep                   12051  2
hci_uart               19956  1
btbcm                   7916  1 hci_uart
bluetooth             365511  22 hci_uart,bnep,btbcm
sg                     20825  0
brcmfmac              222874  0
brcmutil                9092  1 brcmfmac
cfg80211              543027  1 brcmfmac
rfkill                 20851  4 bluetooth,cfg80211
snd_bcm2835            24427  0
bcm2835_gpiomem         3940  0
snd_pcm                98501  1 snd_bcm2835
i2c_bcm2835             7167  0
snd_timer              23904  1 snd_pcm
snd                    70032  3 snd_timer,snd_bcm2835,snd_pcm
uio_pdrv_genirq         3923  0
fixed                   3285  0
uio                    10204  1 uio_pdrv_genirq
i2c_dev                 6913  0
ipv6                  406751  32

ghost commented Jun 20, 2017

@pelwell also just tried to change that line to dtoverlay=i2c1_bcm2708,sda1_pin=2,scl1=3,pin_func=6 (I am not sure where to find the numbering for the GPIO's). This didn't change the i2c behavior.

Output of lsmod is:

pi@raspberrypi:~ $ lsmod
Module                  Size  Used by
bnep                   12051  2
hci_uart               19956  1
btbcm                   7916  1 hci_uart
bluetooth             365511  22 hci_uart,bnep,btbcm
sg                     20825  0
brcmfmac              222874  0
brcmutil                9092  1 brcmfmac
cfg80211              543027  1 brcmfmac
rfkill                 20851  4 bluetooth,cfg80211
snd_bcm2835            24427  0
bcm2835_gpiomem         3940  0
snd_pcm                98501  1 snd_bcm2835
i2c_bcm2835             7167  0
snd_timer              23904  1 snd_pcm
snd                    70032  3 snd_timer,snd_bcm2835,snd_pcm
uio_pdrv_genirq         3923  0
fixed                   3285  0
uio                    10204  1 uio_pdrv_genirq
i2c_dev                 6913  0
ipv6                  406751  32
@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 20, 2017

Contributor

Ah yes, that's because the overlay no longer does what you might think from its name.

Download an updated overlay here that changes the compatible string - if you copy it into /boot/overlays and reboot you should find that the old driver (i2c_bcm2708) is loaded instead. You can then retry your test.

My theory is that the I2C device you are trying to control does not support repeated starts. If you find that everything springs into life with the old driver, try repeating your test after turning on the "combined" module parameter:

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'
Contributor

pelwell commented Jun 20, 2017

Ah yes, that's because the overlay no longer does what you might think from its name.

Download an updated overlay here that changes the compatible string - if you copy it into /boot/overlays and reboot you should find that the old driver (i2c_bcm2708) is loaded instead. You can then retry your test.

My theory is that the I2C device you are trying to control does not support repeated starts. If you find that everything springs into life with the old driver, try repeating your test after turning on the "combined" module parameter:

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 22, 2017

@pelwell , thanks! I replaced i2c_bcm2708 (i2c1_bcm2708) and update config.txt. Unfortunately this did not seem to solve the problem. Could it be anything else? Is there a way to tell when the Kernel i2c was changed?

ghost commented Jun 22, 2017

@pelwell , thanks! I replaced i2c_bcm2708 (i2c1_bcm2708) and update config.txt. Unfortunately this did not seem to solve the problem. Could it be anything else? Is there a way to tell when the Kernel i2c was changed?

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 22, 2017

Contributor
  1. Does sudo vcdbg log msg |& grep -v HDMI include any errors?
  2. What does lsmod | grep i2c show?
Contributor

pelwell commented Jun 22, 2017

  1. Does sudo vcdbg log msg |& grep -v HDMI include any errors?
  2. What does lsmod | grep i2c show?
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 23, 2017

@pelwell thanks for hanging in there with us!

  1. Here are the results:
pi@raspberrypi:~ $ sudo vcdbg log msg |& grep -v HDMI
001089.526: gpioman: gpioman_get_pin_num: pin WL_LPO_CLK not defined
001089.550: gpioman: gpioman_get_pin_num: pin BT_ON not defined
001089.569: gpioman: gpioman_get_pin_num: pin WL_ON not defined
001289.249: *** Restart logging
001293.787: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
001584.432: Loading 'kernel.img' to 0x8000 size 0x42ce30
001588.091: No kernel trailer (run mkknlimg to fix) - assuming DT-capable
001590.856: Loading 'bcm2708-rpi-b-plus.dtb' to 0x434e30 size 0x3c60
001671.507: dtparam: i2c_arm=on
001677.350: dtparam: audio=on
001705.465: Failed to load overlay 'i2c1_bcm2708'
001773.647: Device tree loaded to 0x1bfebe00 (size 0x4174)
001774.899: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
004226.826: vchiq_core: vchiq_init_state: slot_zero = 0x5b580000, is_master = 1
  1. Here are the results of lsmod | grep i2c
pi@raspberrypi:~ $ lsmod | grep i2c
i2c_bcm2835             6433  0
i2c_dev                 6642  0

ghost commented Jun 23, 2017

@pelwell thanks for hanging in there with us!

  1. Here are the results:
pi@raspberrypi:~ $ sudo vcdbg log msg |& grep -v HDMI
001089.526: gpioman: gpioman_get_pin_num: pin WL_LPO_CLK not defined
001089.550: gpioman: gpioman_get_pin_num: pin BT_ON not defined
001089.569: gpioman: gpioman_get_pin_num: pin WL_ON not defined
001289.249: *** Restart logging
001293.787: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
001584.432: Loading 'kernel.img' to 0x8000 size 0x42ce30
001588.091: No kernel trailer (run mkknlimg to fix) - assuming DT-capable
001590.856: Loading 'bcm2708-rpi-b-plus.dtb' to 0x434e30 size 0x3c60
001671.507: dtparam: i2c_arm=on
001677.350: dtparam: audio=on
001705.465: Failed to load overlay 'i2c1_bcm2708'
001773.647: Device tree loaded to 0x1bfebe00 (size 0x4174)
001774.899: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
004226.826: vchiq_core: vchiq_init_state: slot_zero = 0x5b580000, is_master = 1
  1. Here are the results of lsmod | grep i2c
pi@raspberrypi:~ $ lsmod | grep i2c
i2c_bcm2835             6433  0
i2c_dev                 6642  0
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 23, 2017

Looks like there's a failure here: 001705.465: Failed to load overlay 'i2c1_bcm2708'

ghost commented Jun 23, 2017

Looks like there's a failure here: 001705.465: Failed to load overlay 'i2c1_bcm2708'

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 23, 2017

Just to see if I had entered in the config.txt info wrong, I changed the line to dtoverlay=i2c1_bcm2708.dtbo
The output was:

pi@raspberrypi:~ $ sudo vcdbg log msg |& grep -v HDMI
001036.946: gpioman: gpioman_get_pin_num: pin WL_LPO_CLK not defined
001036.970: gpioman: gpioman_get_pin_num: pin BT_ON not defined
001036.989: gpioman: gpioman_get_pin_num: pin WL_ON not defined
001236.661: *** Restart logging
001240.994: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
001531.743: Loading 'kernel.img' to 0x8000 size 0x42ce30
001535.412: No kernel trailer (run mkknlimg to fix) - assuming DT-capable
001538.180: Loading 'bcm2708-rpi-b-plus.dtb' to 0x434e30 size 0x3c60
001618.152: dtparam: i2c_arm=on
001624.038: dtparam: audio=on
001641.290: Failed to load overlay 'i2c1_bcm2708.dtbo'
001709.634: Device tree loaded to 0x1bfebe00 (size 0x4174)
001710.886: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
004172.407: vchiq_core: vchiq_init_state: slot_zero = 0x5b580000, is_master = 1

ghost commented Jun 23, 2017

Just to see if I had entered in the config.txt info wrong, I changed the line to dtoverlay=i2c1_bcm2708.dtbo
The output was:

pi@raspberrypi:~ $ sudo vcdbg log msg |& grep -v HDMI
001036.946: gpioman: gpioman_get_pin_num: pin WL_LPO_CLK not defined
001036.970: gpioman: gpioman_get_pin_num: pin BT_ON not defined
001036.989: gpioman: gpioman_get_pin_num: pin WL_ON not defined
001236.661: *** Restart logging
001240.994: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
001531.743: Loading 'kernel.img' to 0x8000 size 0x42ce30
001535.412: No kernel trailer (run mkknlimg to fix) - assuming DT-capable
001538.180: Loading 'bcm2708-rpi-b-plus.dtb' to 0x434e30 size 0x3c60
001618.152: dtparam: i2c_arm=on
001624.038: dtparam: audio=on
001641.290: Failed to load overlay 'i2c1_bcm2708.dtbo'
001709.634: Device tree loaded to 0x1bfebe00 (size 0x4174)
001710.886: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
004172.407: vchiq_core: vchiq_init_state: slot_zero = 0x5b580000, is_master = 1
@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 23, 2017

Contributor

Ah - although the module is called i2c_bcm2708, the overlay uses a hyphen - i2c1-bcm2708. Try:

dtoverlay=i2c1-bcm2708
Contributor

pelwell commented Jun 23, 2017

Ah - although the module is called i2c_bcm2708, the overlay uses a hyphen - i2c1-bcm2708. Try:

dtoverlay=i2c1-bcm2708
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 27, 2017

@pelwell that worked! We're reading I2C again! Thanks!

Just to repeat the entire process . . . .

  1. Download the old module here.
  2. Copy this file into /boot/overlays.
  3. In /boot/config.txt add the line dtoverlay=i2c1-bcm2708 at the end.

Does that sound about right?

Again, THANK YOU SO MUCH FOR YOUR HELP WITH THIS!

ghost commented Jun 27, 2017

@pelwell that worked! We're reading I2C again! Thanks!

Just to repeat the entire process . . . .

  1. Download the old module here.
  2. Copy this file into /boot/overlays.
  3. In /boot/config.txt add the line dtoverlay=i2c1-bcm2708 at the end.

Does that sound about right?

Again, THANK YOU SO MUCH FOR YOUR HELP WITH THIS!

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 27, 2017

Contributor

Now that you have a workaround you can help to diagnose the real problem by trying with the combined module parameter enabled:

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'

I am expecting your test to fail again, in which case we would need to find a way to disable combined (repeated start) transactions for i2c_bcm2835.

Contributor

pelwell commented Jun 27, 2017

Now that you have a workaround you can help to diagnose the real problem by trying with the combined module parameter enabled:

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'

I am expecting your test to fail again, in which case we would need to find a way to disable combined (repeated start) transactions for i2c_bcm2835.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 27, 2017

@pelwell should this be run on a fresh Jessie Lite without the workaround on it, or on the one we've applied the workaround to?

ghost commented Jun 27, 2017

@pelwell should this be run on a fresh Jessie Lite without the workaround on it, or on the one we've applied the workaround to?

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 27, 2017

Contributor

This test requires the workaround - you need the overlay to get the old driver loaded, and only the old driver has that parameter.

Contributor

pelwell commented Jun 27, 2017

This test requires the workaround - you need the overlay to get the old driver loaded, and only the old driver has that parameter.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 27, 2017

Ok, so after applying the workaround, and then running the command

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'

the example code does not work. However, after a reboot, the i2c readings returned to normal and gave expected readings.

So what do you make of that? Strange or expected?

ghost commented Jun 27, 2017

Ok, so after applying the workaround, and then running the command

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'

the example code does not work. However, after a reboot, the i2c readings returned to normal and gave expected readings.

So what do you make of that? Strange or expected?

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 27, 2017

Contributor

It is what I was expecting - and hoping for, really. Now I'm sure what the problem is, finding a solution should just be a matter of having some time to work on it - either to find an existing way of disabling combined transaction, or to add one.

Contributor

pelwell commented Jun 27, 2017

It is what I was expecting - and hoping for, really. Now I'm sure what the problem is, finding a solution should just be a matter of having some time to work on it - either to find an existing way of disabling combined transaction, or to add one.

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 27, 2017

Contributor

By the way, rebooting should not be necessary to get back to a working system, just:

sudo sh -c '/bin/echo N > /sys/module/i2c_bcm2708/parameters/combined'
Contributor

pelwell commented Jun 27, 2017

By the way, rebooting should not be necessary to get back to a working system, just:

sudo sh -c '/bin/echo N > /sys/module/i2c_bcm2708/parameters/combined'
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 28, 2017

That's great to hear. Should I leave this open?

ghost commented Jun 28, 2017

That's great to hear. Should I leave this open?

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 28, 2017

Contributor

Yes - until a proper fix is found, it's better to keep the history in a single thread.

Contributor

pelwell commented Jun 28, 2017

Yes - until a proper fix is found, it's better to keep the history in a single thread.

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Jun 29, 2017

Contributor

I've been looking at this for quite a while now, and I can't find a satisfactory solution.

Linux expects to be able to use a repeated START when issuing a read from a device. If your device doesn't support that then I think it is broken - the I2C protocol seems pretty clear that a repeated start should be accepted. Fortunately there seem to be two workarounds:

  1. Issue a write with no data and a read with no address (using the I2C_M_NOSTART flag).
  2. Some bus controller drivers understand the I2C_M_STOP flag that forces a stop in situations where a repeated start would otherwise be used, but it doesn't seem to be widely supported.

Normally these flags are passed with each transfer using the I2C_RDWR ioctl. However, the SMBus API doesn't have these flags, and the Python SMBus module adds yet another abstraction layer.

Preventing an entire I2C interface from using a repeated start just because a particular device doesn't support it is a kludge, but I can't see a better way while continuing to use the Python smbus module. I did find an alternative Python library using I2C_RDWR - https://github.com/quick2wire/quick2wire-python-api/blob/master/quick2wire/i2c.py - perhaps that might be worth a try. Otherwise, you're going to have to continue to use the modified i2c1_bcm2708 overlay.

Contributor

pelwell commented Jun 29, 2017

I've been looking at this for quite a while now, and I can't find a satisfactory solution.

Linux expects to be able to use a repeated START when issuing a read from a device. If your device doesn't support that then I think it is broken - the I2C protocol seems pretty clear that a repeated start should be accepted. Fortunately there seem to be two workarounds:

  1. Issue a write with no data and a read with no address (using the I2C_M_NOSTART flag).
  2. Some bus controller drivers understand the I2C_M_STOP flag that forces a stop in situations where a repeated start would otherwise be used, but it doesn't seem to be widely supported.

Normally these flags are passed with each transfer using the I2C_RDWR ioctl. However, the SMBus API doesn't have these flags, and the Python SMBus module adds yet another abstraction layer.

Preventing an entire I2C interface from using a repeated start just because a particular device doesn't support it is a kludge, but I can't see a better way while continuing to use the Python smbus module. I did find an alternative Python library using I2C_RDWR - https://github.com/quick2wire/quick2wire-python-api/blob/master/quick2wire/i2c.py - perhaps that might be worth a try. Otherwise, you're going to have to continue to use the modified i2c1_bcm2708 overlay.

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Apr 18, 2018

Contributor

The modified overlay changes the compatible string of the i2c1 node to use the old i2c_bcm2708 driver. I created it as an experiment.

The shipping overlay as it stands is misnamed because it also changes the pins for the i2c_bcm2835 driver, but I'm reluctant to change the current behaviour because most users won't need the old driver and we want to be able to remove it in the future. However, I could add another parameter that enables the change to compatible.

With the custom overlay loaded, can you try enabling transaction combining:

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'

If the theory is correct it should no longer work.

Contributor

pelwell commented Apr 18, 2018

The modified overlay changes the compatible string of the i2c1 node to use the old i2c_bcm2708 driver. I created it as an experiment.

The shipping overlay as it stands is misnamed because it also changes the pins for the i2c_bcm2835 driver, but I'm reluctant to change the current behaviour because most users won't need the old driver and we want to be able to remove it in the future. However, I could add another parameter that enables the change to compatible.

With the custom overlay loaded, can you try enabling transaction combining:

sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'

If the theory is correct it should no longer work.

@MrCollor

This comment has been minimized.

Show comment
Hide comment
@MrCollor

MrCollor Apr 18, 2018

Using sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'
Sensor no longer work.

MrCollor commented Apr 18, 2018

Using sudo sh -c '/bin/echo Y > /sys/module/i2c_bcm2708/parameters/combined'
Sensor no longer work.

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Apr 18, 2018

Contributor

Good - the problem is as I thought.

I'll push a patch adding a new parameter to the standard overlay allowing combined transactions to be turned off. The first implementation will revert to the old driver, but we should look for a way of modifying the new driver to achieve the same effect.

Contributor

pelwell commented Apr 18, 2018

Good - the problem is as I thought.

I'll push a patch adding a new parameter to the standard overlay allowing combined transactions to be turned off. The first implementation will revert to the old driver, but we should look for a way of modifying the new driver to achieve the same effect.

@MrCollor

This comment has been minimized.

Show comment
Hide comment
@MrCollor

MrCollor Apr 18, 2018

So is there any "official" way to get working my DHT12 sensor or i can only use yours experimental file ?
I am making master thesis, som i can not write only something like this :
I downoladed this experimental file and it started to work :D

MrCollor commented Apr 18, 2018

So is there any "official" way to get working my DHT12 sensor or i can only use yours experimental file ?
I am making master thesis, som i can not write only something like this :
I downoladed this experimental file and it started to work :D

@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Apr 18, 2018

Contributor

I think I answered this one when I said:

I'll push a patch adding a new parameter to the standard overlay allowing combined transactions to be turned off.

I'll post here when the updated overlay is available.

Contributor

pelwell commented Apr 18, 2018

I think I answered this one when I said:

I'll push a patch adding a new parameter to the standard overlay allowing combined transactions to be turned off.

I'll post here when the updated overlay is available.

@MrCollor

This comment has been minimized.

Show comment
Hide comment
@MrCollor

MrCollor Apr 18, 2018

Yes, you did. Thanks !

MrCollor commented Apr 18, 2018

Yes, you did. Thanks !

pelwell added a commit to raspberrypi/linux that referenced this issue Apr 18, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
@pelwell

This comment has been minimized.

Show comment
Hide comment
@pelwell

pelwell Apr 18, 2018

Contributor

The patched overlay (actually overlays - I changed i2c0-bcm2708 as well) is in the source tree and will be picked up by the next firmware build.

Usage: dtoverlay=i2c1-bcm2708,combine=no (or =off).

Contributor

pelwell commented Apr 18, 2018

The patched overlay (actually overlays - I changed i2c0-bcm2708 as well) is in the source tree and will be picked up by the next firmware build.

Usage: dtoverlay=i2c1-bcm2708,combine=no (or =off).

popcornmix added a commit that referenced this issue Apr 26, 2018

kernel: Bump to 4.14.37
kernel: BCM270X_DT: Add sdio_overclock parameter

kernel: gpiolib: Don't prevent IRQ usage of output GPIOs
See: raspberrypi/linux#2527

kernel: Driver for Allo Katana DAC
See: raspberrypi/linux#2519

kernel: Prevent voltage low warnings from filling log
See: raspberrypi/linux#2520

kernel: overlays: Add 'combine' option to i2c overlays
See: #828

firmware: Extra reg writes to ensure the LCD display starts up at 800 wide

firmware: platform: Lower temperature thresholds for extra pips to 50/60

firmware: video_encode: Add support for YVU420Planar and YVU420SemiPlanar
firmware: video_decode: Support YV12, NV12, and NV21 output
firmware: video_decode: Support reporting colour space
firmware: IL rawcam: Fix copy/paste error on timing setup
firmware: MMAL: Populate buffer header TYPE_SPECIFIC fields

popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Apr 26, 2018

kernel: Bump to 4.14.37
kernel: BCM270X_DT: Add sdio_overclock parameter

kernel: gpiolib: Don't prevent IRQ usage of output GPIOs
See: raspberrypi/linux#2527

kernel: Driver for Allo Katana DAC
See: raspberrypi/linux#2519

kernel: Prevent voltage low warnings from filling log
See: raspberrypi/linux#2520

kernel: overlays: Add 'combine' option to i2c overlays
See: raspberrypi/firmware#828

firmware: Extra reg writes to ensure the LCD display starts up at 800 wide

firmware: platform: Lower temperature thresholds for extra pips to 50/60

firmware: video_encode: Add support for YVU420Planar and YVU420SemiPlanar
firmware: video_decode: Support YV12, NV12, and NV21 output
firmware: video_decode: Support reporting colour space
firmware: IL rawcam: Fix copy/paste error on timing setup
firmware: MMAL: Populate buffer header TYPE_SPECIFIC fields

popcornmix added a commit that referenced this issue Apr 26, 2018

kernel: Bump to 4.14.37
kernel: BCM270X_DT: Add sdio_overclock parameter

kernel: gpiolib: Don't prevent IRQ usage of output GPIOs
See: raspberrypi/linux#2527

kernel: Driver for Allo Katana DAC
See: raspberrypi/linux#2519

kernel: Prevent voltage low warnings from filling log
See: raspberrypi/linux#2520

kernel: overlays: Add 'combine' option to i2c overlays
See: #828

firmware: Extra reg writes to ensure the LCD display starts up at 800 wide

firmware: platform: Lower temperature thresholds for extra pips to 50/60

firmware: video_encode: Add support for YVU420Planar and YVU420SemiPlanar
firmware: video_decode: Support YV12, NV12, and NV21 output
firmware: video_decode: Support reporting colour space
firmware: IL rawcam: Fix copy/paste error on timing setup
firmware: MMAL: Populate buffer header TYPE_SPECIFIC fields

popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Apr 26, 2018

kernel: Bump to 4.14.37
kernel: BCM270X_DT: Add sdio_overclock parameter

kernel: gpiolib: Don't prevent IRQ usage of output GPIOs
See: raspberrypi/linux#2527

kernel: Driver for Allo Katana DAC
See: raspberrypi/linux#2519

kernel: Prevent voltage low warnings from filling log
See: raspberrypi/linux#2520

kernel: overlays: Add 'combine' option to i2c overlays
See: raspberrypi/firmware#828

firmware: Extra reg writes to ensure the LCD display starts up at 800 wide

firmware: platform: Lower temperature thresholds for extra pips to 50/60

firmware: video_encode: Add support for YVU420Planar and YVU420SemiPlanar
firmware: video_decode: Support YV12, NV12, and NV21 output
firmware: video_decode: Support reporting colour space
firmware: IL rawcam: Fix copy/paste error on timing setup
firmware: MMAL: Populate buffer header TYPE_SPECIFIC fields

pelwell added a commit to raspberrypi/linux that referenced this issue May 1, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

pelwell added a commit to raspberrypi/linux that referenced this issue May 1, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit to raspberrypi/linux that referenced this issue May 5, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit to raspberrypi/linux that referenced this issue May 5, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

rsalveti added a commit to OpenSourceFoundries/linux that referenced this issue May 9, 2018

[OSF extras] overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Signed-off-by: Ricardo Salveti <ricardo@opensourcefoundries.com>

popcornmix added a commit to raspberrypi/linux that referenced this issue May 17, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

pelwell added a commit to raspberrypi/linux that referenced this issue May 20, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

pelwell added a commit to raspberrypi/linux that referenced this issue May 20, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit to raspberrypi/linux that referenced this issue May 21, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit to raspberrypi/linux that referenced this issue May 25, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit to raspberrypi/linux that referenced this issue May 29, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit to raspberrypi/linux that referenced this issue Jun 5, 2018

overlays: Add 'combine' option to i2c overlays
The i2c0-bcm2708 and i2c1-bcm2708 overlays allow the I2C pin usage to
be changed. The names also suggest they revert to the old i2c_bcm2708
driver, but they don't. The newer i2c_bcm2835 driver forces
transactions to be combined where possible, but this breaks some
devices.

Add an option to disable transaction combining, which is currently
implemented by reverting to the old driver.

See: raspberrypi/firmware#828

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
@roncapat

This comment has been minimized.

Show comment
Hide comment
@roncapat

roncapat Aug 6, 2018

Has the overlay thing been properly fixed in the last FW release?

roncapat commented Aug 6, 2018

Has the overlay thing been properly fixed in the last FW release?

@popcornmix

This comment has been minimized.

Show comment
Hide comment
@popcornmix

popcornmix Aug 7, 2018

Contributor

Yes, "combine" option was added in 4.14.37.
Latest stable apt kernel is 4.14.52.
So if you've apt upgraded in the last month you should have this.

Contributor

popcornmix commented Aug 7, 2018

Yes, "combine" option was added in 4.14.37.
Latest stable apt kernel is 4.14.52.
So if you've apt upgraded in the last month you should have this.

@roncapat

This comment has been minimized.

Show comment
Hide comment
@roncapat

roncapat Aug 7, 2018

Why this issue is still open? :)

roncapat commented Aug 7, 2018

Why this issue is still open? :)

@JamesH65

This comment has been minimized.

Show comment
Hide comment
@JamesH65

JamesH65 Aug 7, 2018

Contributor

Well, we haven't had third party confirmation it's actually fixed, but reading back it does seem that it can be closed. @pelwell happy to close?

Contributor

JamesH65 commented Aug 7, 2018

Well, we haven't had third party confirmation it's actually fixed, but reading back it does seem that it can be closed. @pelwell happy to close?

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