SPI Examples

Started by wwarczak, October 24, 2012, 04:28:58 PM

Previous topic - Next topic

wwarczak

Hello.

I need to use my device with SPI interface in the module connector UEXT OLINUXINO-MAXi.

My device operates in SPI slave mode and SPI requires transmission
256 bytes at a frequency of 25MHz SCK.

I'm looking for examples of the software side of IMX233 using the hardware SPI interface.
Is the software must be implemented at the kernel level, or it can be an application
user. Are there any examples of hardware modules support SPI on which I could learn from?

olimex

to the best of my knowledge iMX233 SPI Linux driver is broken and works only in the ancient LTIB kernel
Fadil who is on this forum is working to push SPI support in 3.x kernel but I'm not sure at what stage it is now

jlumme

I'm also interested in SPI examples for imx.. My hope is to use spi flash, but we're still working on the flashing mechanisms...
The broken driver doesnt sound too good ;/

Fabio Estevam

I added support for spi flash on mx28evk. Take a look at arch/arm/boot/dts/imx28-evk.dts.

The spi driver works fine and the driver is shared between mx23 and mx28. You just need to add support for imx23-olinuxino.dts.

Fadil will post his patches soon.

Regards,

Fabio Estevam

jlumme

Fabio, very interesting - thank you! I will definitely take a look at your example..

wigyori

Hi Fabio / Fadil,

Is there a tree that's publicly available with your updates and if we can take patches from it?

Thanks,
-w-

Fadil Berisha

Quote from: wigyori on October 29, 2012, 03:45:31 PM
Hi Fabio / Fadil,

Is there a tree that's publicly available with your updates and if we can take patches from it?

Thanks,
-w-

I just uploaded patch at following link:
https://www.dropbox.com/s/0v5morn5a4a0mlv/0001-ARM-imx23-olinuxino-Add-spi-support.patch

I will posts also some test results and small guide how to use.

Regards
Fadil Berisha

wigyori

Hi Fadil,

Great stuff, thanks for this. Do you have a repository of the rest of your patches that we can download? I'm referring to the likes of your I2C patch and IIRC there was a USB patchset. Also, it'd be good to know what version or git branch can these apply to.

Thanks a lot,
-w-

wwarczak

#8
I made the first attempt with old LTIB kernel and got the following results:

mxs-spi mxs-spi.0: at 0x80034000 mapped to 0xF0034000, irq=20, bus 1, DMA
at 0x80034000 mapped to 0xF0034000, irq=20, bus 1, DMA

I started to test the example mxc_spi_test1.c (LTIB)

I need to get SPI_CLK at 20Mhz or more, whether it is possible for imx233?
I will try kernel 3.x with Fadil patches.

Fadil Berisha

Hi wigyori

Quote from: wigyori on October 29, 2012, 06:26:46 PM
Hi Fadil,

Great stuff, thanks for this. Do you have a repository of the rest of your patches that we can download? I'm referring to the likes of your I2C patch and IIRC there was a USB patchset. Also, it'd be good to know what version or git branch can these apply to.

Thanks a lot,
-w-

I posted new SPI Example on this forum (GPIO expander mcp23s08). Right now doing final i2c testing. All patches, including i2c support will move on https://github.com/koliqi/imx23-olinuxino/ and rewrite guide for kernel compilation to match 3.7 with spi/i2c support. Patches apply to linux-next 3.7-rc2. You can apply patches also on 3.7-rc2 from kernel.org

Regards
Fadil Berisha

wwarczak

I still have problems with the SPI:

1) On the old LTIB 2.6.31-626-g602af1c_OLinuXino kernel driver is available but does not work properly:

Configuration: noinitrd console=ttyAM0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2

dmesg:

mxs-spi mxs-spi.0: Max possible speed 96000 = 96000000/2 kHz
mxs-spi mxs-spi.0: at 0x80034000 mapped to 0xF0034000, irq=20, bus 1, DMA

device:

0 crw-rw----    1 root     root     153,   0 Jan  1 00:00 /dev/spidev1.0

When sending data to the device function write hang.

echo "test" > /dev/spidev1.0 hangs until CTR-C

SCK and MOSI lines are working properly, but no Slave Select signal is generated


2) On the new linux-3.7-rc3 kernel from kernel.org:

* NOT applied patches 0001-usb_led.patch  (merged in kernel 3.7)
* applied patch: 0001-ARM-imx23-olinuxino-Add-spi-support.patch
* default config witch: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- mxs_defconfig 

in configuration set options:

CONFIG_SPI=y
CONFIG_SPI_BITBANG=m
CONFIG_SPI_GPIO=m
CONFIG_SPI_MXS=y
CONFIG_SPI_SPIDEV=y

kernel compiled and installed without errors

Dmesg: no spi info:

Linux version 3.7.0-rc3 (root@imx233develDebian)
Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2

Sys filesystem:

/sys/bus/spi
/sys/bus/spi/devices
/sys/bus/spi/drivers
/sys/bus/spi/drivers/spidev
/sys/bus/spi/drivers/spidev/bind
/sys/bus/spi/drivers/spidev/uevent
/sys/bus/spi/drivers/spidev/unbind
/sys/bus/spi/drivers/mtd_dataflash
/sys/bus/spi/drivers/mtd_dataflash/bind
/sys/bus/spi/drivers/mtd_dataflash/uevent
/sys/bus/spi/drivers/mtd_dataflash/unbind
/sys/bus/spi/uevent
/sys/bus/spi/drivers_probe
/sys/bus/spi/drivers_autoprobe
/sys/bus/platform/drivers/mxs-spi
/sys/bus/platform/drivers/mxs-spi/bind
/sys/bus/platform/drivers/mxs-spi/uevent
/sys/bus/platform/drivers/mxs-spi/unbind
/sys/class/spi_master
/sys/class/spidev
/sys/module/spidev
/sys/module/spidev/parameters
/sys/module/spidev/parameters/bufsiz
/sys/module/spidev/uevent

My application uses API described in Documentation/spi/spidev. I need some more help witch kernel configuration.

wwarczak

Hello.
After manually applying patches from: https://www.olimex.com/forum/index.php?topic=232.0
there is some progress:

dmesg | grep spi

[    0.000000] Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2
[    0.120000] bus: 'spi': registered
[    0.120000] device class 'spi_master': registering
[    0.920000] bus: 'spi': add driver mtd_dataflash
[    0.930000] device class 'spidev': registering
[    0.930000] bus: 'spi': add driver spidev
[    0.930000] bus: 'platform': add driver mxs-spi
[    0.930000] bus: 'platform': driver_probe_device: matched device 80034000.ssp with driver mxs-spi
[    0.930000] bus: 'platform': really_probe: probing driver mxs-spi with device 80034000.ssp
[    0.930000] device: 'spi32766': device_add
[    0.930000] PM: Adding info for No Bus:spi32766
[    0.930000] mxs-spi 80034000.ssp: registered master spi32766 (dynamic)
[    0.930000] spi spi32766.0: setup mode 0, 8 bits/w, 40000000 Hz max --> 0
[    0.930000] device: 'spi32766.0': device_add
[    0.940000] bus: 'spi': add device spi32766.0
[    0.940000] PM: Adding info for spi:spi32766.0
[    0.940000] mxs-spi 80034000.ssp: registered child spi32766.0
[    0.940000] driver: '80034000.ssp': driver_bound: bound to device 'mxs-spi'
[    0.940000] bus: 'platform': really_probe: bound device 80034000.ssp to driver mxs-spi

[root@imx233 dev]# find /sys/ | grep spi
/sys/bus/spi
/sys/bus/spi/devices
/sys/bus/spi/devices/spi32766.0
/sys/bus/spi/drivers
/sys/bus/spi/drivers/spidev
/sys/bus/spi/drivers/spidev/bind
/sys/bus/spi/drivers/spidev/uevent
/sys/bus/spi/drivers/spidev/unbind
/sys/bus/spi/drivers/mtd_dataflash
/sys/bus/spi/drivers/mtd_dataflash/bind
/sys/bus/spi/drivers/mtd_dataflash/uevent
/sys/bus/spi/drivers/mtd_dataflash/unbind
/sys/bus/spi/uevent
/sys/bus/spi/drivers_probe
/sys/bus/spi/drivers_autoprobe
/sys/bus/platform/drivers/mxs-spi
/sys/bus/platform/drivers/mxs-spi/bind
/sys/bus/platform/drivers/mxs-spi/80034000.ssp
/sys/bus/platform/drivers/mxs-spi/uevent
/sys/bus/platform/drivers/mxs-spi/unbind
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/power
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/device
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/subsystem
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/uevent
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/power
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/modalias
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/subsystem
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/uevent
/sys/class/spi_master
/sys/class/spi_master/spi32766
/sys/class/spidev
/sys/module/spidev
/sys/module/spidev/parameters
/sys/module/spidev/parameters/bufsiz
/sys/module/spidev/uevent

but still no spi device in /dev (udev installed)



Fadil Berisha

#12
Quote from: wwarczak on November 02, 2012, 11:19:40 PM


but still no spi device in /dev (udev installed)

What device you have atached on spi interface?
For each device you need activate driver with kernel menuconfig and  create node on file imx23-olinuxino.dts as shown on https://www.olimex.com/forum/index.php?topic=232.msg912#msg912 and this template:

         ssp1: ssp@80034000 {
            #address-cells = <1>;
            #size-cells = <0>;
            compatible = "fsl,imx23-spi";
            pinctrl-names = "default";
            pinctrl-0 = <&spi2_pins_a>;
            status = "okay";
                                /* Add node here */
                        };

See examples for:

1) spi flash sst25vf016b, and

2) spi GPIO expander mcp23s08

Fadil Berisha

benowski

Did anyone knows what to write in node spi device for mcp2515 CAN Controller?

I think it should be combined somehow with declaration in file ..\linux-mainline/include/linux/can/platform\mcp251x.h

/**
* struct mcp251x_platform_data - MCP251X SPI CAN controller platform data
* @oscillator_frequency:       - oscillator frequency in Hz
* @irq_flags:                  - IRQF configuration flags
* @board_specific_setup:       - called before probing the chip (power,reset)
* @transceiver_enable:         - called to power on/off the transceiver
* @power_enable:               - called to power on/off the mcp *and* the
*                                transceiver
*
* Please note that you should define power_enable or transceiver_enable or
* none of them. Defining both of them is no use.
*
*/

struct mcp251x_platform_data {
   unsigned long oscillator_frequency;
   unsigned long irq_flags;
   int (*board_specific_setup)(struct spi_device *spi);
   int (*transceiver_enable)(int enable);
   int (*power_enable) (int enable);
};

Fadil Berisha

Quote from: benowski on November 04, 2012, 03:42:30 PM
Did anyone knows what to write in node spi device for mcp2515 CAN Controller?


SPI slave device mcp2515 would be presented on imx23-olinuxino.dts DT file with node like this (fill value for oscilator-frequency & irq-flag):

can0: mcp2515@0 {
compatible = "microchip,mcp2515";
reg = <0>;
spi-max-frequency = <16000000>;
                                        oscillator-frequency = <      >;
                                        irq-flag = < >;
};

Since mcp2515 driver is not device tree compatible, you need to modify driver in order to accept platform data from DT file. If needed, you can pass also other board_specific_setup data.
How to modify driver,  example I wrote is here https://www.olimex.com/forum/index.php?topic=232.msg912#msg912

Fadil Berisha