spidev problems

Started by jeroends, February 13, 2013, 05:42:32 PM

Previous topic - Next topic

jeroends

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:
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:


[  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):
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

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

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

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

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


orstig

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

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

Quote from: orstig 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


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

@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

change for example in the test spi code:

.rx_buf = (unsigned long)rx,
to
.rx_buf = 0,

this will give you a working spi output.

orstig

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 ?