SPI Examples

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

Previous topic - Next topic

benowski

Thanks for fast respond! If I deal with mcp251x, I will write about results.
I am doing it with tutorial barebox on olinuxino.md.
I have already compiled kernel. Now I try to compile barebox.
And I got into trouble.

Fadil, do you know what could be a problem?

  CHK     include/generated/utsrelease.h
  SYMLINK include/config.h -> arch/arm/boards/imx233-olinuxino//config.h
  CC      scripts/bareboxenv-target
In file included from /home/andrzej/olinuxino/gcc-arm-none-eabi-4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/include/dirent.h:6:0,
                 from scripts/bareboxenv.c:28:
/home/andrzej/olinuxino/gcc-arm-none-eabi-4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/include/sys/dirent.h:10:2: error: #error "<dirent.h> not supported"
In file included from scripts/bareboxenv.c:34:0:
scripts/compiler.h:27:22: fatal error: sys/mman.h: No such file or directory
compilation terminated.
make[1]: *** [scripts/bareboxenv-target] Błąd 1
make: *** [scripts] Błąd 2

Fadil Berisha

Quote from: benowski on November 05, 2012, 12:41:01 PM

I am doing it with tutorial barebox on olinuxino.md.
I have already compiled kernel. Now I try to compile barebox.


To compile barebox use arm-linux-gnueabi. Now, olinuxino is in barebox mainline and  no need to apply any olinuxino patches on barebox. If still getting problem, please start new topic about compiling barebox and continue here discussion about SPI Examples.

Fadil Berisha
   

benowski

Hi. I have compiled kernel with dts:

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

             can0: mcp2515@0 {
               compatible = "microchip,mcp2515";
               reg = <0>;
               spi-max-frequency = <16000000>;
                                        oscillator-frequency = <12000000>;
                                        irq-flag = <&gpio0 17 0>;//MX23_INT_GPIO0=16
            };

root@debian:~# dmesg | grep spi
[    0.900000] mxs-spi 80034000.ssp: registered master spi32766 (dynamic)
[    0.910000] spi spi32766.0: setup mode 0, 8 bits/w, 16000000 Hz max --> 0
[    0.910000] mxs-spi 80034000.ssp: registered child spi32766.0
[    0.920000] mcp251x spi32766.0: Andrzej tu byl. Probing..1
[    0.920000] mcp251x spi32766.0: setup mode 0, 8 bits/w, 16000000 Hz max --> 0
[    0.930000] mcp251x spi32766.0: spi transfer failed: ret = -22
[    0.940000] mcp251x spi32766.0: spi transfer failed: m = -1014833736
[    0.950000] mcp251x spi32766.0: spi transfer failed: ret = -22
[    0.950000] mcp251x spi32766.0: spi transfer failed: m = -1014833632
[    0.960000] mcp251x spi32766.0: spi transfer failed: ret = -22
[    0.970000] mcp251x spi32766.0: spi transfer failed: m = -1014833632
[    0.970000] mcp251x spi32766.0: CANSTAT 0x8a CANCTRL 0x13
[    0.970000] mcp251x spi32766.0: Probe failed adi mcp251x_hw_probe
[    0.980000] mcp251x spi32766.0: probe failed adi pdata->power_enable
root@debian:~# dmesg | grep can
[    0.910000] vcan: Virtual CAN interface driver
[    1.140000] of_get_named_gpio_flags: can't parse gpios property
[    1.250000] can: controller area network core (rev 20120528 abi 9)
[    1.270000] can: raw protocol (rev 20120528)
[    1.270000] can: broadcast manager protocol (rev 20120528 t)


I think spi is not working, because i watch pins(9,10,11) on CON2 with oscyloscope and nothing appeard.
Fadil, do you know what to do enable or test spi?

Fadil Berisha

#18
Quote from: benowski on November 12, 2012, 01:31:19 PM

I think spi is not working, because i watch pins(9,10,11) on CON2 with oscyloscope and nothing appeard.
Fadil, do you know what to do enable or test spi?

You do not have any activity because your driver in use - fail to probe. See this error:

[    0.970000] mcp251x spi32766.0: Probe failed adi mcp251x_hw_probe

I see you passing variables oscillator-frequency and irq-flag, but question is:
did you adapt driver mcp2515 to accept variables from device tree DT file?

Fadil Berisha

benowski

"did you adapt driver mcp2515 to accept variables from device tree DT file?"

Yes. here is a diff(path) to driver
https://www.dropbox.com/s/kybyp66nkwjblml/mcp251x_path

i try also your port expander(and your path dts to it) and it was working. I saw on osciloscope clk, MOSI etc

or maybe there is a problem with
"
#ifdef CONFIG_OF
static const struct of_device_id mcp251x_dt_ids[] = {
   { .compatible = "microchip,mcp2515", },
   { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, mcp251x_dt_ids);
#else
#define mcp251x_dt_ids NULL
#endif
"

Fadil Berisha

#20
Quote from: benowski on November 12, 2012, 07:58:28 PM
"did you adapt driver mcp2515 to accept variables from device tree DT file?"

Yes. here is a diff(path) to driver
https://www.dropbox.com/s/kybyp66nkwjblml/mcp251x_path

i try also your port expander(and your path dts to it) and it was working. I saw on osciloscope clk, MOSI etc

or maybe there is a problem with
"
#ifdef CONFIG_OF
static const struct of_device_id mcp251x_dt_ids[] = {
   { .compatible = "microchip,mcp2515", },
   { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, mcp251x_dt_ids);
#else
#define mcp251x_dt_ids NULL
#endif
"
Your patch looks good to me, but because of this info:

[    0.980000] mcp251x spi32766.0: probe failed adi pdata->power_enable

I think you need to check definitions about power enable. How power_anable is handled in your board? Is schemtic of your module available?

EDIT Message: Second comment - In DT you have

irq-flag = <&gpio0 17 0>;//MX23_INT_GPIO0=16

With this you passing GPIO pin 17 as interrupt input.
Check documentation of your board. My understanding is that you need to pass irq FLAG not interrupt pin.

If your documentation show that you need to handle interrupts, in that case irq-flag = <&gpio0 17 0> is OK but in driver you need to declare gpio pin 17 as input pin and point to interrupt handler.

Fadil Berisha

benowski

"I think you need to check definitions about power enable. How power_anable is handled in your board? Is schemtic of your module available? "

I didn't plug Can controller to the olinuxino board yet. Firstly I wanted to check if port spi is working. But unfortunately nothing appeared on osciloscope.
You can find example schematic here : http://cor-net.org/2009/09/can-interface-for-the-mini2440-dev-board/

"How power_anable is handled in your board?" I think one pin of gpio  should be connected with CS pin in mcp251x.

I wrote <&gpio0 17 0> in dts, because I do not know what exactly to insert there,it was just to compile dts file with succes
But for sure, in mcp251x datasheet, state that it is Interrupt output pin, so my master device(olinuxino) should have configured this as input. Am i right?

Fadil Berisha

Quote from: benowski on November 12, 2012, 09:36:59 PM

But for sure, in mcp251x datasheet, state that it is Interrupt output pin, so my master device(olinuxino) should have configured this as input. Am i right?
Yes, schematics show that you need to define GPIO pin as input and connect on nINT. In that case. need also section in driver with gpio definition as input and definition for interrupt handler.

You can expect activity on SPI interface only after driver is load with no error. Before connecting on olinuxino check also voltage levels.

Fadil Berisha


jlumme

I'm having some issues adding SPI device to the kernel. I'm trying to add my SPI flash chip.

I have followed Fadil's suggestions as in: https://www.olimex.com/forum/index.php?topic=232.0

My imx23-olinuxino.dts looks like this:

ssp0: ssp@80010000 {
compatible = "fsl,imx23-mmc";
pinctrl-names = "default";
pinctrl-0 = <&mmc0_4bit_pins_a &mmc0_pins_fixup &led_pins_a>;
bus-width = <4>;
status = "okay";
};

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

//Flash chip
flash: sst25vf64c@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "sst,sst25vf64c";
spi-max-frequency = <40000000>;
reg = <0>;
};
};

pinctrl@80018000 {
....


I can see that my dtb is compiled, and if I look at the binary, I can see that "sst25vf64c" looks like it has been added to the blob.

In kernel I have following SPI flags:

CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y


But still during boot, I get nothing:

# dmesg |grep -i spi
[    0.000000] Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2
#


Any ideas what might be the problem here ?
I'm positive that I clean and recreate kernel and also bootlets, but still nothing.. (?)

Fadil Berisha

Quote from: jlumme on December 11, 2012, 01:11:40 PM
I can see that my dtb is compiled, and if I look at the binary, I can see that "sst25vf64c" looks like it has been added to the blob.

In kernel I have following SPI flags:

CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y


But still during boot, I get nothing:
Is driver for sst25vf64c in .config? Also, make sure to append DT blob on kernel.

Fadil Berisha

jlumme

Quote from: Fadil Berisha on December 11, 2012, 07:53:40 PM

Is driver for sst25vf64c in .config? Also, make sure to append DT blob on kernel.

Fadil Berisha
Hi Fadil,

I was trying this one step at the time, and thought I would first see what happens in kernel if I add the device, would it try to load a driver or not.. Yes, I'm sure I was appending also the dtb to kernel.

Now that you mentioned this, I did a bit of searching, and it seems that sst25vf chips are supported by same driver as in your example (m25p80.c), but it's missing support for 64Mbit chip (largest I see is for 32bits). But adding a new one with proper JEDEC ID is not a big thing (if it works ;) ).

I will modify the dts once I get back home, and make sure CONFIG_MTD_M25P80 is also set in config.. Thanks for your help!

jlumme

Still no luck :o

I have pasted my dtsi and dts files here:

imx23.dtsi: http://paste.ubuntu.com/1427335/
imx23-olinuxino.dts: http://paste.ubuntu.com/1427336/

I can clearly see that my modified DTB is added, you can see my change of model name to DTS (model = "i.MX23 Olinuxino Low Cost Board TEST" ) and in kernel boot I can see:
[    0.000000] Booting Linux on physical CPU 0                                                                                                                 
[    0.000000] Linux version 3.6.0_test_alpha1-09647-gddee6b1-dirty (jlumme@simppa) (gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1) ) #8 Wed Dec 12 20:16:042
[    0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177                                                                                   
[    0.000000] CPU: VIVT data cache, VIVT instruction cache                                                                                                     
[    0.000000] Machine: Freescale i.MX23 (Device Tree), model: i.MX23 Olinuxino Low Cost Board TEST               


My kernel config contains now these flags:
CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y
&
CONFIG_MTD_M25P80=y


In the driver I have added the proper JEDEC for my 64bit chip:
kernel/drivers/mtd/devices/m25p80.c:
{ "sst25vf064b", INFO(0xbf254b, 0, 64 * 1024,128, SECT_4K) }, //jlumme


And still dmesg shows zero messages for SPI  :-\
# dmesg | grep spi                                                                                                                                             
[    0.000000] Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2                                         


Any hints ?

Fadil Berisha

Hi jlumme,

Your kernel is Linux version 3.6.0_test_alpha1-09647-gddee6b1-dirty. Check is there SPI support for imx23 SoC. If not, use latest version 3.7 (there is also olinuxino SPI support).

Fadil Berisha


jlumme

Fadil, thanks your for your reply.
Indeed it seems that there is CONFIG_MXS_SPI flag now available in new (3.7) kernels..
I seem to have an issue getting the kernel to boot now, though. I will start another thread, as this might be something others will bump into as well if they try to compile a kernel from kernel.org

jlumme

After successfully compiling latest kernel, and applying the additions I mentioned before, my flash chip is now recognized as expected.

Now, if I only I knew how to use it on Linux side... ;)

Thanks Fadil for your advice on the newer kernel, that was the trick!