Skip to content

driver: i2c: cc13xx_cc26xx: to support i2c scan #38584

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

Closed
wants to merge 1 commit into from

Conversation

Pillar1989
Copy link

Sending address without data, make i2c scan I2C_0 work.

Signed-off-by: Baozhu Zuo [email protected]

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

@Pillar1989 - please file an issue and link it to this PR. Describe the bug in more detail.

I know what this is for, but other reviewers might not.

It's mainly just because we are in our stabilization period right before release.

@Pillar1989
Copy link
Author

thanks @cfriedt guide me , that's the issue. #38645

@cfriedt cfriedt linked an issue Sep 18, 2021 that may be closed by this pull request
@cfriedt
Copy link
Member

cfriedt commented Sep 18, 2021

@Pillar1989 - just a few minor whitespace formatting issues. Please fix up so that CI passes and then it should be merged relatively quickly.

@Pillar1989
Copy link
Author

update

Copy link

@devanlai devanlai left a comment

Choose a reason for hiding this comment

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

I've tested this with an LPSTK-CC1352R with the i2c scan command from the i2c shell and I can confirm that scanning works as expected.

It also would've been great to have this patch a few weeks ago when I was bringing up some new hardware and was puzzled by the i2c scan not showing anything.

Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

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

Blocking this until we can validate this change.

Comment on lines 61 to 66
/* Sending address without data is not supported */
I2CMasterSlaveAddrSet(base, addr, false);

/* Sending address without data */
if (len == 0) {
return -EIO;

I2CMasterControl(base, I2C_MASTER_CMD_SINGLE_SEND);

k_sem_take(&data->complete, K_FOREVER);

return data->error == I2C_MASTER_ERR_NONE ? 0 : -EIO;
}

I2CMasterSlaveAddrSet(base, addr, false);
Copy link
Member

Choose a reason for hiding this comment

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

Does this really work as expected?

As far as I can see, I2C_MASTER_CMD_SINGLE_SEND sends both address and data (written to I2CMDR); and we do not write to I2CMDR in this case, so we will be sending garbage data here:

image

Can you post an oscilloscope or logic analyser capture of the SCL/SDA waveforms and confirm that no data is sent here?

Choose a reason for hiding this comment

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

Your trace matches what I see with a logic analyzer. It is disappointing that the peripheral doesn't seem to be able to send just the address without also pushing a data byte.

image

Copy link
Author

Choose a reason for hiding this comment

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

@leadercxn let's figure out why there is append a data.

Choose a reason for hiding this comment

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

I consult this document -- CC13x2, CC26x2 SimpleLink™ Wireless MCU Technical Reference Manual (Rev. D) , in chapter 25.3.5 , it introduces several models of I2C communication, but i can't see any modes that just send the address without I2C_MDR data.
In the chapter 23.5 , there are no any registers refer to how to just send the address. I try to modify the MCTRL register, but it doesn't work . so i don‘t think it's hardware I2C supports this feature that just send the address without I2C_MDR data.

i2c_scan

CC13x2, CC26x2 SimpleLink™ Wireless MCU Technical Reference Manual

Copy link
Author

Choose a reason for hiding this comment

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

@devanlai @stephanosio It seems that after some research, this additional data is justified.

Copy link
Member

Choose a reason for hiding this comment

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

It seems that after some research, this additional data is justified.

@Pillar1989 Could you elaborate?

Copy link
Author

Choose a reason for hiding this comment

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

In chapter 23.5, which has many Master TRANSMIT modes. But every mode needs append data after the i2c address.

image

Copy link
Member

Choose a reason for hiding this comment

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

In chapter 23.5, which has many Master TRANSMIT modes. But every mode needs append data after the i2c address.

@Pillar1989 That means that the original comment is correct and this change is invalid.

/* Sending address without data is not supported */

@cfriedt
Copy link
Member

cfriedt commented Sep 21, 2021

@Pillar1989 - try to pull from main and rebase your branch. I vaguely recall that this MAINTAINERS issue was solved that way.

@@ -58,12 +58,18 @@ static int i2c_cc13xx_cc26xx_transmit(const struct device *dev,
const uint32_t base = get_dev_config(dev)->base;
struct i2c_cc13xx_cc26xx_data *data = get_dev_data(dev);

/* Sending address without data is not supported */
Copy link
Member

@cfriedt cfriedt Sep 22, 2021

Choose a reason for hiding this comment

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

/* Sending address without data is not supported */

I'm not 100% convinced that this statement is true, as I'm sure is the case for everyone else working with this SoC.

Let's ask the contributor with arguably the most experience with the vendor API in question.

@vanti - is there a way to perform an I2C scan / probe using the simplelink I2C driverlib? I.e. sending the address bits without sending data bits (with some indication as to whether the connected peripheral has ACK'ed the address bits). If so, how do we do it?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@Pillar1989, @Vaishnav98 - given what everyone else has said, I think we may not find the answer in the SimpleLink SDK. However, i sort of wonder if this could be bit-banged 🤔

Copy link
Author

Choose a reason for hiding this comment

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

@cfriedt @stephanosio Assume that we need to add more code to i2c scan to support some SoC like CC13xx serial. any suggest? Or maybe this is a half-baked idea, and we still need to fix the problem of sending only addresses.

@Pillar1989
Copy link
Author

@Pillar1989 - try to pull from main and rebase your branch. I vaguely recall that this MAINTAINERS issue was solved that way.

let me try again

@Pillar1989
Copy link
Author

@stephanosio any more questions need to discuss ?

Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

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

It looks like the I2C peripheral of the CC13xx and CC26xx SoCs do not support sending address without data as described by the original comment, so this change is invalid.

The current I2C scan implementation expects the I2C peripheral to be able to only send the address to probe the peripherals on the bus, and that is with a good reason because sending data byte can be an intrusive behaviour.

If you want to make the I2C scan function work for this SoC (and others that do not support sending address without data), you will need to modify the I2C scan function itself and introduce something like a "intrusive" scan mode.

cc @nashif since he initially implemented the I2C scan function.

 Sending address without data, make `i2c scan I2C_0` work.

Signed-off-by: Baozhu Zuo <[email protected]>
@Pillar1989
Copy link
Author

https://manpages.debian.org/unstable/i2c-tools/i2cdetect.8.en.html @stephanosio
I have tried i2cdetect on Raspberry Pi,It can't appear your want which just sends the address. It seems that these tools are inherently two-sided. If you want zephyr to keep the I2C bus uninsurable, I think it should be without introducing i2c scan.
image

@stephanosio
Copy link
Member

The source of the problem is the I2C shell scan command implementation that requires a zero-length message to be sent, which the I2C peripheral of this particular SoC cannot support:

msgs[0].len = 0U;

The current behaviour of the I2C driver returning -EIO when zero-length message is specified is correct because this particular SoC indeed does not support sending a zero-length message.

It does not make sense to change/introduce an incorrect behaviour to the I2C driver in order to support the I2C shell scan command -- this is simply not a correct thing to do.

Instead, the I2C shell scan command should be changed to support the class of devices that do not allow sending zero-length message by design (e.g. through a separate "intrusive scan" feature or by making all scans intrusive; I leave this decision up to whomever maintains this feature).

@cfriedt
Copy link
Member

cfriedt commented Sep 27, 2021

The source of the problem is the I2C shell scan command implementation that requires a zero-length message to be sent, which the I2C peripheral of this particular SoC cannot support:

Has TI stated that? There could be a bug or undersupported feature in the SimpleLink SDK, but I wasn't able to find anything elaborating on the '-ENOTSUP' conclusion here. It would be surprising if a TI part could not accomplish zero-length transfers, because presumably TI parts have been doing that for a long time.

@Pillar1989 - have you asked about this on e2e.ti.com?

Instead, the I2C shell scan command should be changed to support the class of devices that do not allow sending zero-length message by design (e.g. through a separate "intrusive scan" feature or by making all scans intrusive; I leave this decision up to whomever maintains this feature).

I would second that as a feature.

@cfriedt
Copy link
Member

cfriedt commented Sep 28, 2021

The source of the problem is the I2C shell scan command implementation that requires a zero-length message to be sent, which the I2C peripheral of this particular SoC cannot support:

Has TI stated that? There could be a bug or undersupported feature in the SimpleLink SDK, but I wasn't able to find anything elaborating on the '-ENOTSUP' conclusion here. It would be surprising if a TI part could not accomplish zero-length transfers, because presumably TI parts have been doing that for a long time.

@Pillar1989 - have you asked about this on e2e.ti.com?

The same question asked on e2e.

https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/898040/cc1310-zero-length-write-over-i2c-to-wake-up-a-sensor

@Vaishnav98 - are you aware if anyone at TI has investigated this issue? It seems to be a common problem and has an e2e ticket associated with it.

I sort of wonder if it could be bitbanged .. 🤔

@cfriedt
Copy link
Member

cfriedt commented Sep 28, 2021

I think this would be best handled by pinctrl, to be honest. e.g. a gpio i2c device that shares pins with the dedicated i2c device, add a devicetree property..

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

Will likely require some work involving the upcoming pinctrl feature

@Pillar1989
Copy link
Author

OK, close this PR

@Pillar1989 Pillar1989 closed this Oct 13, 2021
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.

cc13xx and cc26xx serial boards i2c scan not work
5 participants