Skip to content

RP2040, i2c : wrong clock frequency #56230

@Thisora

Description

@Thisora

Describe the bug

SCL clock frequency generated do not correspond to DT clock-frequency definition:

&i2c1 {
	status = "okay";
	pinctrl-0 = < &i2c1_default >;
	pinctrl-names = "default";
	clock-frequency = <I2C_BITRATE_STANDARD>;
...

I2C_BITRATE_STANDARD is suppose to be 100kHz, but i measured 124kHz :
image

Which make a huge difference.
I investigate first using i2c logs and i found that hcnt and lcnt are wrong:

[00:00:00.005,000] <dbg> i2c_dw: i2c_dw_isr: I2C: interrupt received                   
[00:00:00.005,000] <dbg> i2c_dw: i2c_dw_setup: I2C: host configured as Master Device   
[00:00:00.005,000] <dbg> i2c_dw: i2c_dw_setup: I2C: speed set to STANDARD              
[00:00:00.005,000] <dbg> i2c_dw: i2c_dw_setup: I2C: lcnt = 500                         
[00:00:00.005,000] <dbg> i2c_dw: i2c_dw_setup: I2C: hcnt = 400                         
[00:00:00.005,000] <dbg> i2c_dw: i2c_dw_isr: I2C: interrupt received                   

Here is how lcnt and hcnt are defined :

#define I2C_STD_HCNT            (CONFIG_I2C_DW_CLOCK_SPEED * 4)
#define I2C_STD_LCNT            (CONFIG_I2C_DW_CLOCK_SPEED * 5)

Which is by default :

config I2C_DW_CLOCK_SPEED
    default 100 

The clock-frequency defined in device tree is not used by the driver.

Target: RP2040

To Reproduce
Can be reproduce with any program that use RP2040 as i2c controller and measure i2c frequency.

Expected behavior
clock-frequency property is used to compute SCL frequency.

Impact
Wrong scl signal frequency.

Environment (please complete the following information):

  • OS: Ubuntu 22
  • Toolchain Zephyr SDK
  • Commit sha : 07c6af3

Additional context
Link of the conversation with @yonsch in discord for infos.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions