• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Embedded Software » Linux » Linux forum » SPI user space access
Share
Linux
  • Forum
Options
  • Subscribe via RSS

Forums

SPI user space access

This question is not answered
Hongfeng Wang
Posted by Hongfeng Wang
on Jul 21 2011 10:43 AM
Genius3175 points

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!

SPI
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Hongfeng Wang
    Posted by Hongfeng Wang
    on Jul 21 2011 11:17 AM
    Genius3175 points

    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;
    }

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Parag_Rao
    Posted by Parag_Rao
    on Apr 17 2012 05:45 AM
    Prodigy160 points

    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!

    Thanks and Regards, Parag Rao ESD.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on Apr 17 2012 05:58 AM
    Expert6655 points

    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!

     

    PSP DM3517 Test app
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Parag_Rao
    Posted by Parag_Rao
    on Apr 17 2012 06:09 AM
    Prodigy160 points

    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 .

    Thanks and Regards, Parag Rao ESD.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Parag_Rao
    Posted by Parag_Rao
    on Apr 17 2012 06:13 AM
    Prodigy160 points

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

    Thanks and Regards, Parag Rao ESD.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on Apr 17 2012 06:40 AM
    Expert6655 points

    Parag_Rao

    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

    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!

    PSP am3517 APP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Parag_Rao
    Posted by Parag_Rao
    on Apr 17 2012 07:01 AM
    Prodigy160 points

    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.

    Thanks and Regards, Parag Rao ESD.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Parag_Rao
    Posted by Parag_Rao
    on Apr 17 2012 07:15 AM
    Prodigy160 points

    Dear Sir,

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

    Thanks and Regards, Parag Rao ESD.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on Apr 17 2012 07:49 AM
    Expert6655 points

    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!

     

    PSP am3517
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Parag_Rao
    Posted by Parag_Rao
    on Apr 17 2012 23:07 PM
    Prodigy160 points

    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!!!!

    Thanks and Regards, Parag Rao ESD.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Anil
    Posted by Anil
    on Apr 18 2012 01:57 AM
    Expert6655 points

    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!

    SPI DM368 PSP
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Parag_Rao
    Posted by Parag_Rao
    on Apr 18 2012 02:18 AM
    Prodigy160 points

    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!!!

    Thanks and Regards, Parag Rao ESD.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • wish_best
    Posted by wish_best
    on Jul 19 2012 20:26 PM
    Intellectual545 points

    Hi Anil,

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

    Thank you very much!

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use