Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A13 => Topic started by: Ilh on July 09, 2014, 09:32:59 AM

Title: Linux SPI API example
Post by: Ilh on July 09, 2014, 09:32:59 AM
Hello,

I am still newbie in linux, so it is a little bit hard for me to figure out what is needed to initialize and use in userspace SPI driver. Could you provide a simple example for A13 SPI initialization/read/write?
Thanks in advance.  :)
Title: Re: Linux SPI API example
Post by: oldpenguin on July 10, 2014, 04:59:32 PM
Hello

Please follow this thread
https://www.olimex.com/forum/index.php?topic=835.msg9746#msg9746

Regards
Title: Re: Linux SPI API example
Post by: Ilh on July 13, 2014, 03:23:06 PM
Hello again,

This topic sure is very useful. However - I encountered a problem - I do everything except:
I use
http://leachy.homeip.net/olinuxino/spi/tst_spi.c
Instead of
https://www.kernel.org/doc/Documentation/spi/spidev_test.c

Because of missing declarations for the modes. Also I don't receive any messages for "cpu tx data time out!"

Everything else is exactly the same as in your post with the difference that there are no real SPI messages outputted on the pins.

Can you help with some ideas what I am doing wrong?
Title: Re: Linux SPI API example
Post by: Ilh on July 14, 2014, 08:42:45 AM
Hello,

This may sound as a newbie request, but can somebody tell me how to update the existing SPI driver module -> I want for example to put some debug messages to see what happens down there. Driver is installed with Kernel compilation by selecting SPI enable and SPI for user mode enable in the menuconfig. Will rmmod and insmod work?  :)
Title: Re: Linux SPI API example
Post by: oldpenguin on July 14, 2014, 07:54:00 PM
Concerning your previous post, do you mean the definitions for DUAL and QUAD modes ?
Add them by hand. I've found that some linux-headers don't have them defined.
#define SPI_TX_DUAL             0x100
#define SPI_TX_QUAD             0x200
#define SPI_RX_DUAL             0x400
#define SPI_RX_QUAD             0x800

Did you make sure the script.bin is modified to allow SPI pin use ?
How are you testing data on you pins ?

Regards

Title: Re: Linux SPI API example
Post by: Ilh on July 15, 2014, 08:06:34 AM
Hello oldpenguin,

Yes - I modified script bin for use of SPI2, removing the cam interface.

I test the pins with oscilloscope.


I will now try to add the definitions.

Best Regards
Title: Re: Linux SPI API example
Post by: vinifr on July 15, 2014, 08:31:46 PM
Quote from: Ilh on July 14, 2014, 08:42:45 AM
Hello,

This may sound as a newbie request, but can somebody tell me how to update the existing SPI driver module -> I want for example to put some debug messages to see what happens down there. Driver is installed with Kernel compilation by selecting SPI enable and SPI for user mode enable in the menuconfig. Will rmmod and insmod work?  :)
You can add:
printk(KERN_WARNING ": some message\n");
Title: Re: Linux SPI API example
Post by: Ilh on July 16, 2014, 08:07:22 AM
Hello vinifr,

Yes - my aim is to use printk, but my problem is in uninstalling the driver and then building and installing the new version, because it is not loaded as a module, but compiled with the kernel.  :)
Title: Re: Linux SPI API example
Post by: vinifr on July 16, 2014, 09:32:01 PM
Quote from: Ilh on July 16, 2014, 08:07:22 AM
Hello vinifr,

Yes - my aim is to use printk, but my problem is in uninstalling the driver and then building and installing the new version, because it is not loaded as a module, but compiled with the kernel.  :)

You have to change the code and recompile the kernel.
http://linux-sunxi.org/Linux_Kernel (http://linux-sunxi.org/Linux_Kernel)
https://www.youtube.com/watch?v=ilDhOzmkORY (https://www.youtube.com/watch?v=ilDhOzmkORY)