Welcome, Guest

Author Topic: SPI Examples  (Read 44700 times)

wwarczak

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
SPI Examples
« on: October 24, 2012, 04:28:58 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 785
  • Karma: +20/-3
Re: SPI Examples
« Reply #1 on: October 24, 2012, 04:45:11 PM »
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

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +1/-1
Re: SPI Examples
« Reply #2 on: October 25, 2012, 02:11:35 AM »
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

  • Newbie
  • *
  • Posts: 31
  • Karma: +0/-0
Re: SPI Examples
« Reply #3 on: October 25, 2012, 05:33:21 AM »
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

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +1/-1
Re: SPI Examples
« Reply #4 on: October 25, 2012, 06:50:20 AM »
Fabio, very interesting - thank you! I will definitely take a look at your example..

wigyori

  • Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
Re: SPI Examples
« Reply #5 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-

Fadil Berisha

  • Full Member
  • ***
  • Posts: 124
  • Karma: +7/-0
Re: SPI Examples
« Reply #6 on: October 29, 2012, 04:56:41 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

  • Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
Re: SPI Examples
« Reply #7 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-

wwarczak

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: SPI Examples
« Reply #8 on: October 29, 2012, 07:09:27 PM »
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.
« Last Edit: October 29, 2012, 07:24:26 PM by wwarczak »

Fadil Berisha

  • Full Member
  • ***
  • Posts: 124
  • Karma: +7/-0
Re: SPI Examples
« Reply #9 on: October 30, 2012, 04:55:05 AM »
Hi 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-

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

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: SPI Examples
« Reply #10 on: November 02, 2012, 03:58:12 PM »
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

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: SPI Examples
« Reply #11 on: November 02, 2012, 11:19:40 PM »
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

  • Full Member
  • ***
  • Posts: 124
  • Karma: +7/-0
Re: SPI Examples
« Reply #12 on: November 03, 2012, 02:39:48 AM »


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
« Last Edit: November 03, 2012, 02:51:51 AM by Fadil Berisha »

benowski

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: SPI Examples
« Reply #13 on: November 04, 2012, 03:42:30 PM »
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

  • Full Member
  • ***
  • Posts: 124
  • Karma: +7/-0
Re: SPI Examples
« Reply #14 on: November 04, 2012, 07:28:02 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):
Code: [Select]
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