Embedded_linux [SOLVED]: Reading/writing SPI devices

Embedded_linux [SOLVED]: Reading/writing SPI devices

Home Forums Embedded Linux Embedded_linux [SOLVED]: Reading/writing SPI devices

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4342

    Anonymous

    QuestionQuestion

    (I am really unsure of which tags to apply, so apologies in advance if I chose the wrong ones.)

    I hope that this is not a too stupid question, but I’m really lost here.

    A client lent me an Atmel SAMA5D2 Xplained board with Linux4SAM to play around with. I’m trying to interface the SPI interface on it, but I have no clue where to start.

    To be clear, I’ve used similar boards (not this particular one) bare-metal. I’ve also used Linux for many years and wrote a few simple devices drivers some years ago. And still I’m lost.

    dmesg | grep spi gives me the following output:

    [    1.840000] atmel_spi f8000000.spi: version: 0x311
    [    1.840000] atmel_spi f8000000.spi: Using dma0chan0 (tx) and dma0chan1 (rx) for DMA transfers
    [    1.850000] atmel_spi f8000000.spi: Using FIFO (16 data)
    [    1.860000] atmel_spi f8000000.spi: Atmel SPI Controller at 0xf8000000 (irq 32)
    [    1.860000] m25p80 spi32766.0: at25df321a (4096 Kbytes)
    

    From this I infer that a driver is loaded and that it is configured to use DMA. Yet, looking in /dev/ there is nothing that looks like a SPI device (I was expecting to find something like /dev/spidev or /dev/spi32766.0 or similar.)

    Does this mean that there is no actual device driver loaded? Do I have to write one in order to use the SPI?

    If I look at the Makefile in the Linux4SAM source tree, I see around line 1171 that the kernel does not support loading of modules. Does this imply I have to recompile the kernel to include my new driver? This seems to be a silly approach; why providing a Linux distribution if I can’t access the hardware with it?

    What am I missing here?
    (I feel rather stupid…)

    EDIT To be clear: I want to access the external SPI interface that will be connected to some external device. I think the m25p80 is some internal Flash memory; I’m not interested to read/write there.

    #4343

    Anonymous

    Accepted AnswerAnswer

    @0andriy put me on the right track. I had to add a SPI resource to the Device Tree and flash the compile Device Tree Blob to the board. (Since I didn’t know about Device Trees at all, this information is really hard to find…).

    I now have a /dev/spidev32765.0. I added this to the device tree:

            spi1: spi@fc000000 {
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_spi1_default>;
                status = "okay";
    
                spidev@0 {
                    compatible = "linux,spidev";
                    spi-max-frequency = <83000000>;
                    reg = <0>;
                };
            };
    
            pinctrl@fc038000 {
                pinctrl_spi1_default: spi1_default {
                    pinmux = <PIN_PD25__SPI1_SPCK>,
                         <PIN_PD26__SPI1_MOSI>,
                         <PIN_PD27__SPI1_MISO>,
                         <PIN_PD28__SPI1_NPCS0>;
                    bias-disable;
                };
            };
    

    Although I read that adding the spidev@0 is not really the right thing to do (I indeed see in dmesg output “spidev spi32765.0: buggy DT: spidev listed directly in DT”).

    Now, if I run spidev_test it still doesn’t work (it times out), but I guess that’s for another question.

    Source: http://stackoverflow.com/questions/41828308/reading-writing-spi-devices
    Author: Ludo
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.