Project

General

Profile

We want to know about SPI for CAN Interface with Linux

Added by sin-ka kang about 5 years ago

I sent the following mail to Developers:

We bought MityDSP-L138F with Industrial IO Board.

We want to use CAN interface(mcp2515) with linux system.

But I don't know how to open spi port in /dev folder. (I can open uart port with '/dev/ttys2')

if you have some example program source for SPI with CAN interface, Could you send me some example sources?

in addition, if there is another proceed before making program, I will really appreciate for your additional information about setting.

And I got a following Answer:

The mcp251x driver is already in the kernel and you should be able to access the CAN device via can0. Have you reviewed our wiki page which discusses CAN support? <https://support.criticallink.com/redmine/projects/indio/wiki/CAN_support>
Regarding SPI, you will need to make sure all of the pinmuxes are set for the pins in question, and then update the spi device initialization tables. If you want to use spidev (to control your devices in userspace), then you'll need to add an entry for spidev in the spi device initialization tables for each chip select entry. There should be some examples of spidev in some of the other baseboard-*.c files you should be able to reference.

Thank you for your reply.

At first, I found wiki page which discusses CAN support <https://support.criticallink.com/redmine/projects/indio/wiki/CAN_support> already, but I cannot install 'can-utils' and 'iproute2' packages in MityDSP terminal window. I think the problem is feed server, but i don't know how can I modify feed server. so I can't test can0 in MityDSP-L138F board yet.

And, He told me about 'baseboard-*.c' and i found a 'baseboard-industrilio.c', but i think it is not useful for connect spi(CAN) in MityDSP(Industrial IO), but when i want to use SPI in my custom board.

how can i code my source to connect SPI / mcp2515?

in addition, When i want to connect to UART2, Does it work well "open(/dev/ttys2)" ?

Thank you for reading.


Replies (4)

RE: We want to know about SPI for CAN Interface with Linux - Added by sin-ka kang about 5 years ago

In addition, should i make node with 'mknod' command?

RE: We want to know about SPI for CAN Interface with Linux - Added by Bob Duke about 5 years ago

Are you using the latest MDK available under the files tab?

https://support.criticallink.com/redmine/projects/arm9-platforms/files
Filename: mitydsp-l138-MDK-gui-2018-04-13.sh

This filesystem has the can-utils installed. This is probably the easiest path for you to interact with can0.

You should not need to make any nodes with the mknod command. The nodes should be automatically created for any device defined in the baseboard file.

RE: We want to know about SPI for CAN Interface with Linux - Added by sin-ka kang about 5 years ago

Thank you for reply.

You said that I don't have to make any nodes with 'mknod' command to me,

but when i want to access to SPI1 to control mcp2515 directly, how can I access to SPI1? like open(/dev/spi1.1); in linux.

RE: We want to know about SPI for CAN Interface with Linux - Added by Jonathan Cormier about 5 years ago

sin-ka kang wrote:

Thank you for reply.

You said that I don't have to make any nodes with 'mknod' command to me,

but when i want to access to SPI1 to control mcp2515 directly, how can I access to SPI1? like open(/dev/spi1.1); in linux.

Linux has several mechanisms for creating device node files automatically based on what is configured in the kernel. Its almost always the wrong answer to manually create a device node. udev, mdev, or devtmpfs are different mechanisms linux can use to create device nodes.

If /dev/spi1.1 is missing then there is a good chance the spidev driver in the kernel isn't being correctly configured and manually creating the device node still won't work since there won't be a device driver to connect to.

The following code shows how to configure a spidev device on spi1. https://support.criticallink.com/gitweb/?p=linux-davinci.git;a=blob;f=arch/arm/mach-davinci/baseboard-industrialio.c;h=112cbf0f19942494dd521adaf5e8bf411a6a7f3a;hb=refs/heads/mitydsp-linux-v3.2#l333

I've attached an example c++ class for interacting with the spidev interface.

    (1-4/4)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)