Welcome, Guest

Author Topic: spidev problems  (Read 19285 times)

jeroends

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +2/-0
spidev problems
« on: February 13, 2013, 05:42:32 PM »
Hello,
after experimenting with spi port (with spidev) on the A13 I hoped I could do the same on the imx233.

I'm using kernel version 3.7.1 build with the instructions of Fadil (https://github.com/koliqi/imx23-olinuxino) and enabled the spidev as been build in.

Also edited the .dts file as follows:
Code: [Select]
ssp1: ssp@80034000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "fsl,imx23-spi";
pinctrl-names = "default";
pinctrl-0 = <&spi2_pins_a>;
clock-frequency = <1000000>;
status = "okay";

spidev: spidev@0 {
compatible = "spidev";
spi-max-frequency = <1000000>;
reg = <1>;
};
};

The spidev gets created (spidev32766.1) but when trying to send data to it, it first takes a long time, the data being send isn't correct and in the log there's a message:

Code: [Select]
[  386.530000] mxs-spi 80034000.ssp: DMA transfer timeout
[  386.530000] spi_master spi32766: failed to transfer one message from queue

Data send to the bus (standard spi test example but with the rx buffer zeroed):
Code: [Select]
FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

output at the bus:


Also noticed one thing: when starting the app, SCK goes high immediately, the app waits and then after some time the SCK goes into real clock and the app continues. I didn't had those issues with the A13 (nor did the raspPI).

Are there know issues with the spidev driver or am I doing something the wrong way?

jlumme

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +1/-1
Re: spidev problems
« Reply #1 on: February 14, 2013, 12:53:11 AM »
I have been successfully transfering data with spidev on my setup..

Looks like you have run into same problem I did with the DMA transfer... I made a patch for that with help from Marek who is working on the spi driver on mxs.
https://patchwork-mail1.kernel.org/patch/1910641/

But this probably is a different issue than in A13, I think this problem was only affecting mx23.
Good you noticed zeroing the rx buffer.. that took me a while to realize why it was failing :)

jeroends

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +2/-0
Re: spidev problems
« Reply #2 on: February 14, 2013, 10:25:16 AM »
thanks for the reply.
I will try the patch next weekend. As far as I know, the A13 also has a problem with bidirectional communcication. But since this isn't needed for my app, I'll leave it as it is.

jlumme

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +1/-1
Re: spidev problems
« Reply #3 on: February 14, 2013, 11:23:53 AM »
BTW that's Freescale design decision (half duplex HW SPI). Just the error message made no sense, and I was doubting myself of course  ;)

jeroends

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +2/-0
Re: spidev problems
« Reply #4 on: February 14, 2013, 11:44:10 AM »
Haha,
couldn't resist to try it right away and ...
Worked like a charm!! The data is send immediatly and the error message is gone!!

Thanks for the hint because google didn't pointed me over there!

jlumme

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +1/-1
Re: spidev problems
« Reply #5 on: February 14, 2013, 04:10:00 PM »
You're welcome  8)

orstig

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: spidev problems
« Reply #6 on: February 27, 2013, 11:12:21 AM »
Hello, i'm trying to get spidev on a imx233 micro to work but spidev_test witch i compiled like this (gcc -o ./spidev_test spidev_test.c) on the running imx233 micro gives me.
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
can't send spi message: Invalid argument
Aborted

I have also tried to compile spidev_test.c with include path but that ends up in conflict.

root@debian:~/spi# gcc -o ./spidev_test spidev_test.c -I /usr/src/linux/include/
In file included from spidev_test.c:21:
/usr/src/linux/include/linux/types.h:14: error: conflicting types for 'fd_set'
/usr/include/sys/select.h:78: note: previous declaration of 'fd_set' was here
/usr/src/linux/include/linux/types.h:15: error: conflicting types for 'dev_t'
/usr/include/sys/types.h:62: note: previous declaration of 'dev_t' was here
/usr/src/linux/include/linux/types.h:17: error: conflicting types for 'mode_t'
/usr/include/sys/types.h:72: note: previous declaration of 'mode_t' was here
/usr/src/linux/include/linux/types.h:25: error: conflicting types for 'timer_t'
/usr/include/time.h:104: note: previous declaration of 'timer_t' was here
/usr/src/linux/include/linux/types.h:36: error: conflicting types for 'uintptr_t'
/usr/include/stdint.h:129: note: previous declaration of 'uintptr_t' was here
/usr/src/linux/include/linux/types.h:134: error: conflicting types for 'blkcnt_t'
/usr/include/sys/types.h:235: note: previous declaration of 'blkcnt_t' was here

ssp1 section in imx23-olinuxino.dts:

ssp1: ssp@80034000 {
            #address-cells = <1>;
            #size-cells = <0>;
            compatible = "fsl,imx23-spi";
            pinctrl-names = "default";
            pinctrl-0 = <&spi2_pins_a>;
            status = "okay";
            
            ucontroller: spidev@0 {
                      #address-cells = <1>;
               #size-cells = <1>;
               compatible = "linux,spidev";
                    spi-max-frequency = <1000000>;
                    reg = <0>;
                };
               
         };

Dist: debian 6
Kernel 3.7.1 + patches

/orstig

jeroends

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +2/-0
Re: spidev problems
« Reply #7 on: February 27, 2013, 01:02:02 PM »
have you've checked that your spidev is created in the "/dev/" directory and if so, did you adjust the right device in the spi_test.c file?

Linking the libs isn't neccessary.

jlumme

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +1/-1
Re: spidev problems
« Reply #8 on: February 27, 2013, 03:31:40 PM »
Hello, i'm trying to get spidev on a imx233 micro to work but spidev_test witch i compiled like this (gcc -o ./spidev_test spidev_test.c) on the running imx233 micro gives me.
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
can't send spi message: Invalid argument
Aborted


imx23 supports only half duplex hw spi, and kernel is correctly refusing to run the default example. The error message should be better.
You have to zero either tx or rx buffer in the datagram (struct spi_ioc_transfer), then it will work.

orstig

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: spidev problems
« Reply #9 on: February 27, 2013, 06:29:39 PM »
@jeroends, yes i have /dev/spidev32766.0 and it looks like it work if a do echo "hello" > /dev/spidev32766.0 i can see both clock and mosi on my scope.

@jlumme, half duplex spi, had to look that up :)

thanks for replys /orstig

jeroends

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +2/-0
Re: spidev problems
« Reply #10 on: February 27, 2013, 10:34:23 PM »
change for example in the test spi code:

Code: [Select]
.rx_buf = (unsigned long)rx,to
Code: [Select]
.rx_buf = 0,
this will give you a working spi output.

orstig

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: spidev problems
« Reply #11 on: February 28, 2013, 01:08:10 AM »
I made the change (rx_buf = 0) and now spidev_test doesn’t complain :D

root@debian:~/spi# ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00

but this leaves me with one question, my plan is to interface with a nrf24l01 radio module, but it uses full duplex spi, will I not be able to do this with hw spi or is there a workaround ?