Help me to setup MCP2515

Started by morind79, September 16, 2014, 01:12:07 PM

Previous topic - Next topic

morind79

Hi All,

I have connected a MCP2515 to A20 board like this :

MCP2515 Pin     A20 Pin
12 (INT)        PI14
13 (SCK)        SPI1-CLK
14 (MOSI)       SPI1-MOSI
15 (MISO)       SPI1-MISO

Then I compiled kernel like this :

--- Networking support
<M> CAN bus subsystem support
   <M> Raw CAN Protocal (raw access with CAN-ID filtering)
   <M> Broadcast Manager CAN Protocal (with content filtering)
   CAN Devices Drivers
    <M> Platform CAN drivers with Netlink support
   
  • CAN bit-timing calculation
        <M> Microchip MCP251x SPI CAN controllers
       
  • CAN devices debugging messages

    Then I just updated uImage and started the board.
    I cannot see anything about MCP2515 when I type :


    cat /proc/interrupts


    Also how I can check SPI is correctly set ?
    Typing :


    dmesg | grep spi


    returns nothing...
    Please help

    Best regards,
    Denis


dave-at-axon

What did you connect the CS (chip select) pin 16 of the MCP2515 to?

morind79

Hi Dave,

Yes I forgot to mention that :

MCP2515 Pin     A20 Pin
16 (CS)         SPI1-CS0

Best regards
Denis

klausbm

Hello Denis,

have you compiled and installed the modules for the new Linux kernel?
The command lsmod will show you all the modules loaded. If the module for MCP251x has not been loaded automatically although you have installed all the new modules you can try the modprobe command.

Klaus

morind79

Hi Klausbm,

Sorry, I am new in Linux and know only basic commands.
I did a modprobe mcp2515x and then ldmod I have :


Module                  Size  Used by
mcp251x                 9450  0
can_dev                 9000  1 mcp251x
disp_ump                 869  0
cpufreq_powersave       1207  0
mali_drm                2616  1
cpufreq_conservative     6042  0
drm                   207598  2 mali_drm
cpufreq_stats           5881  0
cpufreq_userspace       3318  0
mali                  111806  0
sunxi_cedar_mod         9800  0
8192cu                454131  0
ump                    50985  4 mali,disp_ump
hdmi                   31971  0
lcd                     4711  0


So this seems to be good (I hope)
Then I did a cat /proc/interrupts and see :


           CPU0       CPU1
29:      14199       6822       GIC  arch_timer
30:          0          0       GIC  arch_timer
32:          0          0       GIC  axp_mfd
33:        289          0       GIC  serial
39:       2516          0       GIC  sunxi-i2c.0
40:          0          0       GIC  sunxi-i2c.1
41:          0          0       GIC  sunxi-i2c.2
54:          0          0       GIC  timer0
55:         12          0       GIC  aw_clock_event
56:          0          0       GIC  sunxi-rtc alarm
59:          0          0       GIC  dma_irq
60:          0          0       GIC  sunxi-gpio
61:          0          0       GIC  sun4i-ts
64:      11834          0       GIC  sunxi-mmc
67:          0          0       GIC  sunxi-mmc
71:          2          0       GIC  ehci_hcd:usb2
72:          0          0       GIC  ehci_hcd:usb4
76:      21830          0       GIC  sunxi lcd0
77:          0          0       GIC  sunxi lcd1
78:          0          0       GIC  g2d
79:      10907          0       GIC  sunxi scaler0
80:          0          0       GIC  sunxi scaler1
85:          0          0       GIC  cedar_dev
87:        351          0       GIC  eth0
88:          0          0       GIC  sw_ahci
92:          0          0       GIC  ace_dev
96:         93          0       GIC  ohci_hcd:usb3
97:          0          0       GIC  ohci_hcd:usb5
101:          0          0       GIC  mali_gp_irq_handlers
102:          0          0       GIC  mali_mmu_irq_handlers
103:          0          0       GIC  mali_pp_irq_handlers
104:          0          0       GIC  mali_mmu_irq_handlers
106:          0          0       GIC  mali_pp_irq_handlers
107:          0          0       GIC  mali_mmu_irq_handlers
IPI0:          0          0  Timer broadcast interrupts
IPI1:       2408       2832  Rescheduling interrupts
IPI2:          0          0  Function call interrupts
IPI3:         11         16  Single function call interrupts
IPI4:          0          0  CPU stop interrupts
IPI5:          0          0  CPU backtrace
Err:          0


As you can see, there is nothing about mcp251x.
Maybe this is normal, but I read I should see something there...
Any ideas ?

Thank you

Denis

bruceuk


What kernel version are you using?

What does your DTS SPI child node look like?

Have you tried configuring spidev first? I was playing around with spidev and managed to get it working where I can /dev/spidev.0

On my board, I can see SPI as follows:
#
# ps -ef | grep -i spi
   46 root     [spi0]
   47 root     [spi1]
  152 root     grep -i spi
#


I changed spidev to be a kernel module....and it loads without any problems
# lsmod
Module                  Size  Used by    Not tainted
spidev                  5471  0
#



The /sys filesystem is aware of the spi devices:
# find /sys -iname "*spi*"
/sys/bus/spi
/sys/bus/spi/drivers/spidev
/sys/bus/platform/devices/1c06000.spi
/sys/bus/platform/devices/1c17000.spi
/sys/bus/platform/drivers/sun4i-spi
/sys/bus/platform/drivers/sun4i-spi/1c06000.spi
/sys/bus/platform/drivers/sun4i-spi/1c17000.spi
/sys/bus/platform/drivers/sun6i-spi
/sys/devices/soc@01c00000/1c06000.spi
/sys/devices/soc@01c00000/1c06000.spi/spi_master
/sys/devices/soc@01c00000/1c06000.spi/spi_master/spi0
/sys/devices/soc@01c00000/1c17000.spi
/sys/devices/soc@01c00000/1c17000.spi/spi_master
/sys/devices/soc@01c00000/1c17000.spi/spi_master/spi1
/sys/class/spi_master
/sys/class/spi_master/spi0
/sys/class/spi_master/spi1
/sys/class/spidev
/sys/firmware/devicetree/base/soc@01c00000/spi@01c05000
/sys/firmware/devicetree/base/soc@01c00000/spi@01c06000
/sys/firmware/devicetree/base/soc@01c00000/spi@01c17000
/sys/firmware/devicetree/base/soc@01c00000/spi@01c1f000
/sys/firmware/devicetree/base/soc@01c00000/pinctrl@01c20800/spi0@0
/sys/firmware/devicetree/base/soc@01c00000/pinctrl@01c20800/spi1@0
/sys/firmware/devicetree/base/soc@01c00000/pinctrl@01c20800/spi2@0
/sys/firmware/devicetree/base/aliases/spi0
/sys/firmware/devicetree/base/aliases/spi1
/sys/module/spidev
/sys/module/spidev/drivers/spi:spidev
#



I added an spidev child node to my DTS file:
                spi1: spi@01c06000 {
                        pinctrl-names = "default";
                        pinctrl-0 = <&spi1_pins_a>;
                        status = "okay";
                        spidev@0 {
                                compatible = "linux,spidev";
                                reg = <0>;
                                spi-max-frequency = <1000000>;
                        };
                };


and then I could see:
# ls -l /dev/*spi*
crw-------    1 root     root      153,   0 Jan 10 13:51 /dev/spidev0.0
#


I would also like to play with MCP2515 some time so please keep us posted.


Bruce



morind79

Hi Brice,

Well I am afraid you have a to high level for me  :P
I have now set my fex file like this :


[spi0_para]
spi_used = 0
spi_cs_bitmap = 1
spi_cs0 = port:PI10<2><default><default><default>
spi_cs1 = port:PI14<2><default><default><default>
spi_sclk = port:PI11<2><default><default><default>
spi_mosi = port:PI12<2><default><default><default>
spi_miso = port:PI13<2><default><default><default>

[spi1_para]
spi_used = 0
spi_cs_bitmap = 1
spi_cs0 = port:PI16<3><default><default><default>
spi_sclk = port:PI17<3><default><default><default>
spi_mosi = port:PI18<3><default><default><default>
spi_miso = port:PI19<3><default><default><default>

[spi2_para]
spi_used = 1
spi_cs_bitmap = 1
spi_cs0 = port:PC19<3><default><default><default>
spi_sclk = port:PC20<3><default><default><default>
spi_mosi = port:PC21<3><default><default><default>
spi_miso = port:PC22<3><default><default><default>

[spi3_para]
spi_used = 0
spi_cs_bitmap = 1
spi_cs0 = port:PA05<3><default><default><default>
spi_cs1 = port:PA09<3><default><default><default>
spi_sclk = port:PA06<3><default><default><default>
spi_mosi = port:PA07<3><default><default><default>
spi_miso = port:PA08<3><default><default><default>

[spi_devices]
spi_dev_num = 1

[spi_board0]
modalias = "spidev"
max_speed_hz = 16000000
bus_num = 2
chip_select = 0
mode = 3
full_duplex = 0
manual_cs = 0
irq_gpio = 13


And now I have this :


# dmesg | grep spi
[    1.686425] [spi-inf] Found 1 spi devices in config files
[    1.698626] [spi-inf] boards num modalias         max_spd_hz       bus_num  cs   mode
[    1.713436] [spi-inf] 0          spidev           16000000         2        0    0x3
[    1.726219] [spi-inf] sun7i_spi_probe: spi2 dma type: normal
[    1.735468] [spi-inf] bus num = 2, spi used = 1
[    1.744526] [spi-inf] sun7i_spi_probe: spi2 cs bitmap: 0x1
[    1.758577] [spi-inf] sun7i_spi_set_mclk: spi2 source = sdram_pll_p, src_clk = 384000000, mclk 96000000
[    1.773826] sun7i-spi sun7i-spi.2: master is unqueued, this is deprecated
[    1.789398] [spi-inf] sun7i_spi_probe: reuuimlla's SoC SPI Driver loaded for Bus SPI2 with 2 Slaves at most
[    1.808523] [spi-inf] sun7i_spi_probe: spi2 driver probe succeed, base f011c000, irq 44, dma_id_rx 26, dma_id_tx 26


so it seems SPI device is found.
But still communication with MCP2515 is not working. In fact I am not able to find PI14 anymore in the list of GPIO this pin is used as INT. Maybe I should do something here, but I am close to give up...

Denis

bruceuk


Unfortunately I've never used a fex file, I'm also somewhat useless when it comes to board level devices/drivers.

Looking at your fex file, you have defined "spidev"....and you therefore see it in your messages:
[    1.686425] [spi-inf] Found 1 spi devices in config files
[    1.698626] [spi-inf] boards num modalias         max_spd_hz       bus_num  cs   mode
[    1.713436] [spi-inf] 0          spidev           16000000         2        0    0x3

You need to define something like "mcp2515" so that the kernel knows to associate the mcp2525 driver with that particular SPI device.

Have a look at this thread:
https://www.olimex.com/forum/index.php?topic=198.15


Perhaps switch to latest kernel + DTS? There is a patched mcp2525 driver here:
http://www.spinics.net/lists/devicetree/msg11918.html

Should work with DTS variables



bruceuk

#8
I forgot to mention...the A20 processor already has a single built in CAN controller, perhaps you could get away with an fex entry for the A20 processor CAN controller + MCP2561 (CAN Transceiver) ?

morind79

I found some information on this site : http://will-tm.com/spi-on-the-cubieboard2/
I changed modalias to mcp2515 but still I guess I have something no correct.
So it must be something with interuption somewhere...

I do not use the builtin CAN as I use the port for something else.