This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SPI user space access

Board: DM368, DVSDK4.02, kernel 2.6.32

I have following problem, which is illustrated in the waveform below, I am trying to write 16bits address followed by 16bits value.

The CS goes high before the value is written, the value didn't show up on SDO either.

 

Here's the code in dm365.c

static u64 dm365_spi1_dma_mask = DMA_BIT_MASK(32);

static struct davinci_spi_platform_data dm365_spi1_pdata = {
    .version     = SPI_VERSION_1,
    .num_chipselect = 1,
    .clk_internal    = 1,
    .cs_hold    = 1,
    .intr_level    = 0,
    .poll_mode    = 1,    /* 0 -> interrupt mode 1-> polling mode */
    .use_dma    = 0,    /* when 1, value in poll_mode is ignored */
    .c2tdelay    = 0,
    .t2cdelay    = 0,
};

static struct resource dm365_spi1_resources[] = {
    {
        .start = 0x01c66800,
        .end   = 0x01c66fff,
        .flags = IORESOURCE_MEM,
    },
    {
        .start = IRQ_DM365_SPIINT0_0,
        .flags = IORESOURCE_IRQ,
    },
    {
        .start = EDMA_CHANNEL_ANY,
        .flags = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN,
    },
    {
        .start = EDMA_CHANNEL_ANY,
        .flags = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN,
    },
    {
        .start = EVENTQ_3,
        .flags = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q,
    },
};

static struct platform_device dm365_spi1_device = {
    .name = "spi_davinci",
    .id = 1,
    .dev = {
        .dma_mask = &dm365_spi1_dma_mask,
        .coherent_dma_mask = DMA_BIT_MASK(32),
        .platform_data = &dm365_spi1_pdata,
    },
    .num_resources = ARRAY_SIZE(dm365_spi1_resources),
    .resource = dm365_spi1_resources,
};

void __init dm365_init_spi1(unsigned chipselect_mask,
        struct spi_board_info *info, unsigned len)
{
    davinci_cfg_reg(DM365_SPI1_SCLK);
    davinci_cfg_reg(DM365_SPI1_SDI);
    davinci_cfg_reg(DM365_SPI1_SDO);
    davinci_cfg_reg(DM365_SPI1_SDENA0);

    spi_register_board_info(info, len);

    platform_device_register(&dm365_spi1_device);
}

 

Code in board_dm365_evm.c

static struct spi_board_info dm365_evm_spi_info[]={
{
.modalias="spidev",
.max_speed_hz=25*1000*1000,
.bus_num=1,
.chip_select=0,
.mode=SPI_MODE_0,
.bits_per_word=16,
},
};

dm365_init_spi1(1,dm365_evm_spi_info,ARRAY_SIZE(dm365_evm_spi_info));

 

Please help!

  • user space code:

     

    static int spi_write(int fd,unsigned short addr,unsigned short value)
    {

        uint16_t out_buf[2];
        int      status;
        struct spi_ioc_transfer xfer[1] = {
          {
               .tx_buf = (unsigned long)out_buf,
               .rx_buf = 0,
               .len =  2,
               .delay_usecs = delay,
               .speed_hz = speed,
               .bits_per_word = bits,
             .cs_change = 0
            },
       };

        out_buf[0] = addr;
        out_buf[2] = value;
        printf("Writing register %04x with value %04x \r\n", addr,value);

        status = ioctl(fd, SPI_IOC_MESSAGE(1), xfer);
        if (status < 0) {
            pabort("SPI_IOC_MESSAGE");
           
        }
        return status;
    }

  • Dear Wang !!

    I have an User Space code :

    #include <stdio.h>
    #include <string.h>
    #include <fcntl.h>
    #include <sys/ioctl.h>

    #define SAMSUNG_LED_WRITEREG 0
    #define SAMSUNG_LED_READREG  1

    int main(int argc,char **argv)
    {
        int fd=open("/dev/samsungled",O_RDWR);
        int arg;
        if(argc==1)
            arg=0x00;
        else if(argc==2)    
        {
            arg=atoi(argv[1]);
        }
        if(arg>15)
            arg=0;
        
        printf("%d\n",arg);    
        
        printf("=============TEST BEGIN=============\n");
        if(fd == -1)
        {
            printf("Open File Error\n");
            exit(0);
        }

        if(ioctl(fd,arg,0)==-1)
        {
            printf("Ioctl Error\n");
            exit(0);
        }
        printf("==============TEST END===============\n");

        close(fd);
    }

    through some tutorials i have got this format . i have registered the Led blinking driver to. i have placed it under the Driver directory.

    But how can i test. the User space code is Working or not.

    Can u explain me in short . How can U integrate this Files in the Kernel.

    Thanks and Regard's

    Prag!

  • Hi Parag,

    You have to build this as userspace application and execute from console.

    In you code you have missed 'stdlib.h' file, which throws an error (#include <stdlib.h>)

    Example:

    Build: $ arm-arago-linux-gnueabi-gcc spi.c -o spi

    Exec: ./spi

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

     

  • Dear Anil Sir,

    Thanks For your Immediate response . I would Like to ask you few more Daught's on this .

    Sir,

    1. U said i have to Execute the File from Console. So using the corresponding tool i have to build the file on desktop. And then should i Place this File on the File system of My target system. And Execute there. Probably on ttyS0>.

    Is this Correct ? but this could be temporary. When power goes again i have to execute the File . Suppose i have to do it in while(1).

    2. Dear Sir i have to write an Application code for Receiving and Transmitting Characters through UART. the UART device can be found registered under /dev/ directory.

    My basic Daught is how can i place the Files in the Linux Directory and Do it Permanently.

    Please share your Experience .

  • Sorry I didn't saw your Message. I will close the Other Thread.

  • Parag_Rao said:

    1. U said i have to Execute the File from Console. So using the corresponding tool i have to build the file on desktop. And then should i Place this File on the File system of My target system. And Execute there. Probably on ttyS0>.

    Is this Correct ? but this could be temporary. When power goes again i have to execute the File . Suppose i have to do it in while(1).

    Yes you have to add to your filesystem. You can add this task a background task, after adding to while loop. Remove all the prints in while loop, otherwise you will see lot of messages

    $ ./spi &

    Parag_Rao said:

    2. Dear Sir i have to write an Application code for Receiving and Transmitting Characters through UART. the UART device can be found registered under /dev/ directory.

    My basic Daught is how can i place the Files in the Linux Directory and Do it Permanently.

    Please share your Experience .

    You can use the tftp server for coping the files from host to target. Google will give you the right information on tftp server setup. We can receive files from the host after tftp server setup by using

    $ tftp -g <tftp serverip> -r spi

    If you are not looking for the same info then can you eloborate on what exactly you are looking for?

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

  • Dear Sir,

    I have already configured the TFTP server.

    I have an Linux Ported as i said.

    We are developing a Custom Board in which We have to Port Free Linux and Demo the Customer of Various Peripheral through User Application. As the Customer is only interested in the Hardware and Not the Software.

    For this I am Trying to Write the User code to Access the UART . Once i get an Idea of UART i can Implement the remaining things on My Own.

    Please State your Views.

    Thanks and Regard's
    Hrishikesh.

  • Dear Sir,

    Any Small Document About Linking and Placing the Files in appropriate directory, Would also be helpful.

  • Hi Parag,

    For my unserstanding, You are asking that how files are placed in the filesystem?

    Which filesystem you are using? nfs/sd/jffs2?

    You can boot the system with NFS server and place all your files in the nfs server folder.

    http://processors.wiki.ti.com/index.php/GSG:_OMAP35x_DVEVM_Software_Setup#Exporting_a_Shared_File_System_for_Target_Access

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

     

  • Dear Anil Sir,

    Sir, I am Asking about the .c file which will be in user space. Where should  i Place this file in File system.

    Consider :

    I have a driver written for Led Drivers . Just Providing an API for Making A GPIO high and LOW. ok.

    I have Placed this Files in a directory        linux-2.6.xx / drivers/ LED.

    I have compiled the Kernel and Checked if the Module for the Same is generated . with few changes in the Makefile of the /drivers directory.

    Now till here it is fine I have compiled a Module integrated in the kernel and I can list the Module in the kernel. with lsmod i can see the module in the kernel.

    Now i am writing some small code through UART.

    I will be waiting on UART to receive the Argument either '1' or '0' in while (1). this code will get the Argument which will be passed to the IOCTL function as 3rd argument to make the LED high or LOW.

    This file i have to Link with the Kernel.

    So Now i need to Place this file. where i should Place

    this file. or as this is a User space file . Everytime the OS console comes i have to run this Application code from filesytem . But i want this Process to be automated. whenever my Os starts at the End it should have the Control within this while(1) loop .

    Please Guide !!!!

    Prag!!!!

  • Hi Parag,

    This can be achived by writing sysfs/debugfs in the kernel module itself. Look at "drivers/gpio/gpiolib.c" file for reference on sysfs usage.

    Once the entries are brought out you can control those using shell-scripts

    Regards

    AnilKumar

    Please mark this Forum post as answered via the Verify Answer button below if it helps answer your question.  Thanks!

  • Dear Sir,

    I am a Newbie to Linux . Your Explanation has given me a path to ride . I will Look into this Files and may i need some Help in future to acheive this .

    Prag!!!

  • Hi Anil,

    Can you take some time to see my question in another thread question about DM365 SPI?

    Thank you very much!