usbarmory / usbarmory

USB armory - The open source compact secure computer

Home Page:https://www.withsecure.com/en/solutions/innovative-security-hardware/usb-armory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

External I2C slaves over debug accessory

gsora opened this issue · comments

Hi,
I'm trying to gain access to external I2C slaves over the debug accessory on a Armory Mk.II device, with Tamago - in particular, I'm interested in using I2C2.

Following docs on the debug accessory page, I2C2 is accessible over A10 and B2.

I wrote the following function to configure the IOMUX according to the i.MX6UL reference manual:

const (
	MUX_I2C2_SCL = 0x020e00BC
	PAD_I2C2_SCL = 0x020e0348

	MUX_I2C2_SDA = 0x020E00C0
	PAD_I2C2_SDA = 0x020E034C
)

func setupI2C() *imx6.I2C {
	p, err := imx6.NewPad(MUX_I2C2_SCL, PAD_I2C2_SCL, 0)
	if err != nil {
		panic(err)
	}

	p.Mode(2)
	p.SoftwareInput(true)
	p.Ctl(0x4001b8b0)

	p, err = imx6.NewPad(MUX_I2C2_SDA, PAD_I2C2_SDA, 0)
	if err != nil {
		panic(err)
	}

	p.Mode(2)
	p.Ctl(0x4001b8b0)
	p.SoftwareInput(true)


	imx6.I2C2.Init()

	return imx6.I2C2
}

The CTL value has been taken from the Armory Mk.II Linux device tree.

p.SoftwareInput is because the reference manual says (page 832):

Inputs of I2Cn_SCL and I2Cn_SDA also need to be manually enabled by setting the
SION bit in the IOMUX after the corresponding PADs are selected as I2C function.

No panic() or fatal error encountered up until this point.

When I try to read/write to a device address, the following errors pop up:

read: [] timeout waiting bus to be busy
write: timeout waiting bus to be busy

Am I configuring/using the IOMUX pads/control correctly?

Update!
Apparently I completely forgot about daisy registers.

The following function setups I2C2 work through the debug accessory.

func setupI2C() *imx6.I2C {
	p, err := imx6.NewPad(MUX_I2C2_SCL, PAD_I2C2_SCL, 0x020E05AC)
	if err != nil {
		panic(err)
	}

	p.Mode(2)
	p.Select(0b10)
	p.Ctl(0x4001b8b0)
	p.SoftwareInput(true)
	p, err = imx6.NewPad(MUX_I2C2_SDA, PAD_I2C2_SDA, 0x020E05B0)
	if err != nil {
		panic(err)
	}

	p.Mode(2)
	p.Select(0b10)
	p.Ctl(0x4001b8b0)
	p.SoftwareInput(true)

	imx6.I2C2.Init()
	return imx6.I2C2
}