FXOS8700 linux driver for SPI bus

136 views
Skip to first unread message

TitusRathinaraj Stalin

unread,
Jul 12, 2017, 7:00:45 AM7/12/17
to >warpx.io
Hello,

I saw the FXOS8700 sensor interfaced with warpx board (imxsl) using SPI interface and want to read the raw data from it.
I can't see any drivers loaded for that, I have seen i2c FXOS8700 driver but not for SPI bus.
Any help ?
Thanks for your support.

Regards,
Titus S.

diego....@kynetics.com

unread,
Jul 17, 2017, 6:06:32 AM7/17/17
to >warpx.io

Hi Titus,

Actually there's an I2C driver for FXOS8700, and it's been developed specifically for the warp_0x01, but it's for the outdated 3.0.35 kernel:
https://github.com/warpboard/linux-imx6/commit/fcb3c8d6db3ad939870cfdb14890c93d4037a8c9

It would be awesome if you could step up to port it to a newer kernel (e.g. 4.1 or newer) and contribute it back to the community.

If you need any professional support, just let us know.

Bests,
Diego Rondini
Sr. Embedded Engineer

Kynetics
www.kynetics.com

TitusRathinaraj Stalin

unread,
Jul 18, 2017, 10:41:40 AM7/18/17
to >warpx.io, diego....@kynetics.com
Hi Diego,

I am able to build the FXOS8700 SPI driver in linux 4.1 version.
The current problem is that always I'm getting 0xFF while reading the WHO_AM_I register (0x0D)

What could be the problem ?

fxos 8700 read chip ID 0xff is not equal to 0xc7 or 0xc4
fxos8700: probe of spi1.0 failed with error -22

Any hint ?

Thanks for your support.

Regards,
Titus S.

diego....@kynetics.com

unread,
Jul 19, 2017, 3:34:47 AM7/19/17
to >warpx.io, diego....@kynetics.com

Hi Titus,

that is very good news. We kindly ask you to share the patch for 4.1 on this mailing list, as the code is GPLv2.

I think your issue is that the chip is incorrectly brought up by default in I2C mode, while we need it to work in SPI mode.
We workarounded the issue in U-Boot with the following patch:
https://github.com/warpboard/uboot-imx/commit/4ded4419e3c729117f801decda852aff43db77a5

Let us know if you succeed, and of course share the patches in any case. If you have problems they provide a good starting point to help you, if you succeed they'll benefit other users of the warpx community.

TitusRathinaraj Stalin

unread,
Jul 19, 2017, 5:17:20 AM7/19/17
to >warpx.io, diego....@kynetics.com
Hi Diego,
Thank you so much for your hint.
Sure, will share you patch once it started working, also will update the status here.

Regards,
Titus S.

TitusRathinaraj Stalin

unread,
Jul 20, 2017, 3:04:35 AM7/20/17
to >warpx.io, diego....@kynetics.com
Hello Diego,

Thanks for your support.

Facing difficulties once I patched that uboot code into latest uboot source.
If I patch those FXOS8700 SPI code implementation in warp.c file then I am getting hangs while DDR init.


U-Boot 2016.07-23134-g9da4a42-dirty (Jul 19 2017 - 18:31:37 +0100)

CPU:   Freescale i.MX6SL rev1.2 at 792 MHz
Reset cause: WDOG
Board: WaRP Board
       Watchdog enabled
I2C:   ready
DRAM:

So I've used the FXOS8700 code as command interface.... I just created a command to use this fix....
I've attached the code. Getting an error for i2c address write when I enter the command to apply the fix in uboot shell.



New U-boot Log:
=>
=> fxos8700
fxos8700 command is executed!
Failed sending device address to FXOS
=> boot

Any suggestions please.
Or we have to use this code only in warp.c (board file) source file ?


Regards,
Titus S.
fxos8700.c

diego....@kynetics.com

unread,
Jul 20, 2017, 4:48:12 AM7/20/17
to >warpx.io, diego....@kynetics.com

Hi Titus,

thanks for the effort of looking into this!

After a quick look at the code, it looks like the execution completes correctly: if you notice the comment just before the "Failed sending device address to FXOS" error is:
// Doesn't actually fail - device just resets immediately.

What we are probably missing is a confirmation the FXOS is now in SPI mode.
A quick check can be done with your ported driver: if you look at the last page of the Software Reference Manual you can see the message you should get if the FXOS is correctly detected by the driver.

Bests,
Diego

TitusRathinaraj Stalin

unread,
Jul 20, 2017, 10:08:49 AM7/20/17
to >warpx.io, diego....@kynetics.com
Hi Diego,
Thanks for the support.
I'm not sure, because that comment for sending the data not for device address right.
For me, its failed in sending device address itself, and thus exit to stop_seq.

+    ret = BBI2C_TransmitByte((FXOS8700_I2C_ADDR << 1) | (BBI2C_WRITE));
+    if(ret){
+        printf("Failed sending device address to FXOS\n");
+        goto stop_seq;

+    }
+    ret = BBI2C_TransmitByte(0x2B);
+    if(ret){
+        printf("Failed sending register address to FXOS\n");
+        goto stop_seq;
+    }
+
+    ret = BBI2C_TransmitByte(0x40);
+    if(ret){
+        // Doesn't actually fail - device just resets immediately.
+        printf("Failed sending data to FXOS\n");
+    }


I suspect that the code which should be used as command and it should be done while board init ? anything like that ?
Can you please point out where the problem could be ?

Regards,
Titus S.

TitusRathinaraj Stalin

unread,
Jul 20, 2017, 10:27:25 AM7/20/17
to >warpx.io, diego....@kynetics.com
Hi Diego,
I have also used the code inside the warp.c file (inside the MMC init section) here is the same result.
Please correct me if I'm wrong.

U-Boot 2016.07-23134-g9da4a42-dirty (Jul 20 2017 - 15:25:01 +0100)


CPU:   Freescale i.MX6SL rev1.2 at 792 MHz
Reset cause: WDOG
Board: WaRP Board
       Watchdog enabled
I2C:   ready
DRAM:  512 MiB
board init is done!
PMIC:  MAX77696 detected, rev=0x21
MMC:   fxos8700 command is executed!

Failed sending device address to FXOS
fxos8700_init done!
FSL_SDHC: 0
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0
=>
=>


TitusRathinaraj Stalin

unread,
Jul 20, 2017, 10:41:04 AM7/20/17
to >warpx.io, diego....@kynetics.com
Hi Deigo,

Here are the my changes in driver, dts and u-boot.
Can you please help me out on this issue ?
Any hints please ?

fxos8700.c is same file as in linux 3.0 kernel

Attached the uboot code and modified linux driver.

&ecspi2 {
    fsl,spi-num-chipselects = <1>;
    cs-gpios = <&gpio4 15 0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_ecspi2>;
    status = "okay";

    fxos8700-acc-gyro@0 {
        compatible = "nxp,fxos8700";
        reg = <0>;
        status = "okay";

        spi-max-frequency = <500000>;
        buswidth = <8>;
//        interrupt-parent = <&gpio4>;
//        interrupts = <18 0>;
    };

};


Thanks for your help so far.

Regards,
Titus S.
fxos8700-spi.c
warp.c

TitusRathinaraj Stalin

unread,
Jul 20, 2017, 1:13:15 PM7/20/17
to >warpx.io, diego....@kynetics.com
Here is the kernel log:

########### fxos8700_spi_probe:170 Called!  #########
########### fxos8700_spi_probe:184 Called!  #########
ret 0 tmp[0] 255 tmp[1] 255
########### fxos8700_spi_read:156 Called!  #########
########### fxos8700_spi_xfer:106 Called!  #########
########### fxos8700_spi_xfer:144  _rx_buf[0] 0xffff #########
FXOS8700_WHO_AM_I ret 0xffff
########### fxos8700_spi_read_byte:62 Called!  #########
FXOS8700_WHO_AM_I val 0xff
########### fxos8700_spi_read_byte:62 Called!  #########
fxos 8700 read chip ID 0x0 is not equal to 0xc7 or 0xc4

TitusRathinaraj Stalin

unread,
Jul 20, 2017, 10:54:16 PM7/20/17
to >warpx.io, diego....@kynetics.com
Hi Diego,

Finally I was able to detect the fxos8700 chip in linux 4.1.15 kernel version.

1. We should reset the chip.
2. Do a dummy SPI read

FXOS8700_WHO_AM_I val 0xff
input: FreescaleAccelerometer as /devices/virtual/input/input3
input: FreescaleMagnetometer as /devices/virtual/input/input4
input: eCompass as /devices/virtual/input/input5
read m_ctrl_reg1 0x0
fxos8700_device_init succ


I've attached the modified linux driver and u-boot code.

DTS code:

        pinctrl_ecspi2: ecspi2grp {
            fsl,pins = <
                MX6SL_PAD_FEC_RXD1__GPIO4_IO18        0x41b0b1 // ACCL_INT1
                MX6SL_PAD_FEC_RX_ER__GPIO4_IO19        0x41b0b1 // ACCL_INT2
                MX6SL_PAD_HSIC_DAT__GPIO3_IO19        0x41b0b1 // FXOS_RESET
                MX6SL_PAD_ECSPI2_SS0__GPIO4_IO15    0x41b0b1 // FX8700 CS GPIO
                MX6SL_PAD_ECSPI2_SCLK__ECSPI2_SCLK    0x41b0b1
                MX6SL_PAD_ECSPI2_MOSI__ECSPI2_MOSI    0x41b0b1
                MX6SL_PAD_ECSPI2_MISO__ECSPI2_MISO    0x41b0b1
            >;
        };


&ecspi2 {
    fsl,spi-num-chipselects = <1>;
    cs-gpios = <&gpio4 15 0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_ecspi2>;
    status = "okay";

    fxos8700-acc-gyro@0 {
        compatible = "nxp,fxos8700";
        reg = <0>;
        status = "okay";

        spi-max-frequency = <500000>;
        buswidth = <8>;
        interrupt-parent = <&gpio4>;
        interrupts = <18 0>;
    };

};


Thanks for your support.

Regards,
Titus S.
fxos8700-spi.c
warp.c
fxos8700.c

diego....@kynetics.com

unread,
Jul 21, 2017, 4:37:48 AM7/21/17
to >warpx.io, diego....@kynetics.com
Hi Titus,


On Friday, July 21, 2017 at 4:54:16 AM UTC+2, TitusRathinaraj Stalin wrote:
Hi Diego,

Finally I was able to detect the fxos8700 chip in linux 4.1.15 kernel version.

1. We should reset the chip.
2. Do a dummy SPI read

this is very good news Titus, thanks for you contribution!

We're looking forward to testing your changes as soon as we get the chance to.

TitusRathinaraj Stalin

unread,
Jul 22, 2017, 1:19:32 AM7/22/17
to >warpx.io, diego....@kynetics.com
Hi Diego,

I have tested the accelerometer and gyro sensors, it worked like charm.

We should enable the both.
echo 1 > /sys/devices/virtual/input/input3/enable
echo 1 > /sys/devices/virtual/input/input4/enable


I think, we can also enable the modifed fxos8700 driver can be used without uboot changes, please test without modified uboot too to confirm.

root@warp:/#
root@warp:/# evtest /dev/input/event1
Input driver version is 1.0.1
Input device ID: bus 0x1c vendor 0x0 product 0x0 version 0x0
Input device name: "FreescaleAccelerometer"
Supported events:
  Event type 0 (EV_SYN)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value  -1352
      Min   -32767
      Max    32767
    Event code 1 (ABS_Y)
      Value    808
      Min   -32767
      Max    32767
    Event code 2 (ABS_Z)
      Value -16184
      Min   -32767
      Max    32767
Properties:
Testing ... (interrupt to exit)
Event: time 1500662502.019174, type 3 (EV_ABS), code 0 (ABS_X), value -1372
Event: time 1500662502.019174, type 3 (EV_ABS), code 1 (ABS_Y), value 840
Event: time 1500662502.019174, type 3 (EV_ABS), code 2 (ABS_Z), value -16200
Event: time 1500662502.019174, -------------- SYN_REPORT ------------
Event: time 1500662502.119153, type 3 (EV_ABS), code 0 (ABS_X), value -1368
Event: time 1500662502.119153, type 3 (EV_ABS), code 1 (ABS_Y), value 832
Event: time 1500662502.119153, type 3 (EV_ABS), code 2 (ABS_Z), value -16152
Event: time 1500662502.119153, -------------- SYN_REPORT ------------
Event: time 1500662502.219202, type 3 (EV_ABS), code 0 (ABS_X), value -1320
Event: time 1500662502.219202, type 3 (EV_ABS), code 1 (ABS_Y), value 824
Event: time 1500662502.219202, type 3 (EV_ABS), code 2 (ABS_Z), value -16160
Event: time 1500662502.219202, -------------- SYN_REPORT ------------
Event: time 1500662502.319150, type 3 (EV_ABS), code 0 (ABS_X), value -1384
Event: time 1500662502.319150, type 3 (EV_ABS), code 1 (ABS_Y), value 780
Event: time 1500662502.319150, type 3 (EV_ABS), code 2 (ABS_Z), value -16168
Event: time 1500662502.319150, -------------- SYN_REPORT ------------
root@warp:/#
root@warp:/#
root@warp:/# evtest /dev/input/event2
Input driver version is 1.0.1
Input device ID: bus 0x1c vendor 0x0 product 0x0 version 0x0
Input device name: "FreescaleMagnetometer"
Supported events:
  Event type 0 (EV_SYN)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value    747
      Min   -32767
      Max    32767
    Event code 1 (ABS_Y)
      Value    -13
      Min   -32767
      Max    32767
    Event code 2 (ABS_Z)
      Value    250
      Min   -32767
      Max    32767
Properties:
Testing ... (interrupt to exit)
Event: time 1500662509.619605, type 3 (EV_ABS), code 0 (ABS_X), value 740
Event: time 1500662509.619605, type 3 (EV_ABS), code 1 (ABS_Y), value -6
Event: time 1500662509.619605, type 3 (EV_ABS), code 2 (ABS_Z), value 240
Event: time 1500662509.619605, -------------- SYN_REPORT ------------
Event: time 1500662509.719651, type 3 (EV_ABS), code 0 (ABS_X), value 744
Event: time 1500662509.719651, type 3 (EV_ABS), code 1 (ABS_Y), value -7
Event: time 1500662509.719651, type 3 (EV_ABS), code 2 (ABS_Z), value 242
Event: time 1500662509.719651, -------------- SYN_REPORT ------------
Event: time 1500662509.819645, type 3 (EV_ABS), code 0 (ABS_X), value 759
Event: time 1500662509.819645, type 3 (EV_ABS), code 1 (ABS_Y), value -26
Event: time 1500662509.819645, type 3 (EV_ABS), code 2 (ABS_Z), value 231
Event: time 1500662509.819645, -------------- SYN_REPORT ------------
Event: time 1500662509.919616, type 3 (EV_ABS), code 0 (ABS_X), value 739
Event: time 1500662509.919616, type 3 (EV_ABS), code 1 (ABS_Y), value 1
Event: time 1500662509.919616, type 3 (EV_ABS), code 2 (ABS_Z), value 259
^Croot@warp:/#
root@warp:/#


Regards,
Titus S.

diego....@kynetics.com

unread,
Jul 26, 2017, 9:44:26 AM7/26/17
to >warpx.io, diego....@kynetics.com
Hi Titus,


On Saturday, July 22, 2017 at 7:19:32 AM UTC+2, TitusRathinaraj Stalin wrote:
Hi Diego,

I have tested the accelerometer and gyro sensors, it worked like charm.

We should enable the both.
echo 1 > /sys/devices/virtual/input/input3/enable
echo 1 > /sys/devices/virtual/input/input4/enable


I think, we can also enable the modifed fxos8700 driver can be used without uboot changes, please test without modified uboot too to confirm.
 

Thanks you very much for your contribution!

To have a confirmation of what you mean, you have implemented the bit-bang in the Linux driver instead of in U-Boot, right?

Also remember you are free to fork our github repository, and we gladly accept pull requests!
https://github.com/warpboard/linux-imx6/tree/warpx/imx_4.1.15_1.0.0_ga

TitusRathinaraj Stalin

unread,
Jul 27, 2017, 9:32:49 AM7/27/17
to >warpx.io, diego....@kynetics.com
Hi Diego,

You are most welcome :)



To have a confirmation of what you mean, you have implemented the bit-bang in the Linux driver instead of in U-Boot, right?

Nope, in other hand, I have also tried that not changing the uboot source code and tried to use the kernel with modified FXOS8700 driver, this time also I was able to see the accelerometer driver was loaded.
It seems, just I did the reset and did dummy SPI read, then it started working.
So please try the given driver without changing the uboot code.

Regards,
Titus S.
Reply all
Reply to author
Forward
0 new messages