Skip to content
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

Miss shift i2c slave address in i2c_sifive #25713

Closed
tamnguyenchi93 opened this issue May 28, 2020 · 1 comment
Closed

Miss shift i2c slave address in i2c_sifive #25713

tamnguyenchi93 opened this issue May 28, 2020 · 1 comment
Assignees
Labels
area: I2C area: RISCV RISCV Architecture (32-bit & 64-bit) bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug Stale

Comments

@tamnguyenchi93
Copy link

Describe the bug
I try to run an example that connect hifive_revb with adxl345 sensor with renode simulate platform. I create overlay file for hifive_revb board

hifive1_revb.overlay:

&i2c0 {
	status = "okay";
	clock-frequency = <I2C_BITRATE_STANDARD>;
	adxl345@53 {
		compatible = "adi,adxl345";
		reg = < 0x53 >;
		label = "ADXL345";
	};
};

Here is my renode platform description:

maskRom: Memory.MappedMemory @sysbus 0x1000
    size: 0x1000

otp: Memory.MappedMemory @sysbus 0x20000
    size: 0x2000

dtim: Memory.MappedMemory @ sysbus 0x80000000
    size: 0x4000

uart0: UART.SiFive_UART @ sysbus 0x10013000
    IRQ -> plic@3

uart1: UART.SiFive_UART @ sysbus 0x10023000
    IRQ -> plic@4

cpu: CPU.RiscV32 @ sysbus
    cpuType: "rv32imac"
    privilegeArchitecture: PrivilegeArchitecture.Priv1_10
    timeProvider: clint

plic: IRQControllers.PlatformLevelInterruptController @ sysbus 0x0C000000
    3 -> cpu@11
    numberOfSources: 52

clint: IRQControllers.CoreLevelInterruptor  @ sysbus 0x02000000
    [0,1] -> cpu@[3,7]
    frequency: 62000000

qspi0Xip: Memory.MappedMemory @ sysbus 0x20000000
    size: 0x20000000

gpioInputs: GPIOPort.SiFive_GPIO @  sysbus 0x10012000
    [0-31] -> plic@[8-39]

i2c0: I2C.OpenCoresI2C @ sysbus 0x10016000
    // our model does not support interrupts yet, but if it did:
    // IRQ -> plic@52

sensor: Sensors.ADXL345 @ i2c0 0x53

sysbus:
    init:
        ApplySVD @https://dl.antmicro.com/projects/renode/svd/FE310.svd.gz

When start renode simulation, zephyr console show these error:

Booting Zephyr OS build v2.3.0-rc1-337-g9e923ee7131e  ***
Could not get ADXL345 device
[00:00:15.515,136] <err> i2c_sifive: I2C Rx failed to acknowledge
[00:00:15.515,136] <err> i2c_sifive: I2C failed to write message
[00:00:15.515,136] <err> i2c_sifive: I2C failed to transfer messages
[00:00:15.515,136] <err> ADXL345: Read PART ID failed: 0xfffffffb

And here is the log from renode console:

23:00:24.5376 [WARNING] i2c0: Unhandled write to offset 0x0, value 0x1F.
23:00:24.5376 [WARNING] i2c0: Unhandled write to offset 0x4, value 0x0.
23:00:24.5395 [WARNING] i2c0: Addressing unregistered slave: 0x29

As my understand that zephyr try to communicate with i2c slave at address 0x29 but it did not register on renode system.
After investigate I found that i2c_sifive driver does not left shift slave add 1 bit.

/* Set transmit register to address with read/write flag */
sys_write8((addr | rw_flag), I2C_REG(config, REG_TRANSMIT));
/* Addresses are always written */
command = SF_CMD_WRITE | SF_CMD_START;
/* Write the command register to start the transfer */
sys_write8(command, I2C_REG(config, REG_COMMAND));

I think the correct way is:

	/* Set transmit register to address with read/write flag */
	sys_write8((addr << 1| rw_flag), I2C_REG(config, REG_TRANSMIT));

Environment (please complete the following information):

  • OS: Linux 16.04
  • Toolchain: Zephyr SDK
  • Commit: 9e923ee
  • Renode: Self build on commit: a0332d3c7bfe90cfcc71e8d743803e6ea85da38f
@tamnguyenchi93 tamnguyenchi93 added the bug The issue is a bug, or the PR is fixing a bug label May 28, 2020
@carlescufi carlescufi added area: RISCV RISCV Architecture (32-bit & 64-bit) area: I2C priority: low Low impact/importance bug labels May 28, 2020
@github-actions
Copy link

github-actions bot commented Aug 2, 2020

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: I2C area: RISCV RISCV Architecture (32-bit & 64-bit) bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug Stale
Projects
None yet
Development

No branches or pull requests

5 participants