• 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 » Continuous spi transfer using linux spi framework on dm365
Share
Linux
  • Forum
Options
  • Subscribe via RSS
Resources
  • Keystone II MCSDK (A15 Linux) Download
  • Forums

    Continuous spi transfer using linux spi framework on dm365

    This question is answered
    Jan Pohanka
    Posted by Jan Pohanka
    on Mar 09 2012 03:35 AM
    Expert1290 points

    Hello,

    I would like to create following scenario:
    We need to have a never stopping continuous spi transfer between dm365 and an another chip on our board. I can imagine this on bare metal application level - having two data buffers I can link DMA transfers, which will automatically switch these buffers in an interrupt at the end of the transfer so the SPI peripheral will by continuously sending/receiving the data without any CPU interaction. Unfortunately I do not know if something similar is possible in linux. Surprisingly I can use dm365 as a slave even in linux, because davinci spi driver enables using external clock for spi even in master mode.

    Using linux spi framework I can define a struct spi_message which contains several transfers (struct spi_transfer). Then the function spi_async will perform the transfer and it can also trigger a callback (spi_message::complete) when the transfer ends. Is it safe to call spi_async again in this callback? Is it fast enough to prevent a loss of some data when we have external spi_clock?

     with best regards
    Jan 

    dm365 spi dma
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Sudhakar Rajashekhara
      Posted by Sudhakar Rajashekhara
      on Mar 28 2012 06:37 AM
      Expert5130 points

      Hi Jan,

      As I understand, the completion callback is called from a kernel thread that should not sleep. Due to this you cannot call a function from the callback, which can sleep. But as spi_async() function is asynchronous, practically you can call this function.

      Regards, Sudhakar

      Does this help with your question? If not, please send back more information. If it answers your question, please click the  Verify Answer  button below.

      PSP
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jan Pohanka
      Posted by Jan Pohanka
      on Mar 29 2012 08:38 AM
      Expert1290 points

      Hi Sudhakar,

      thank you for the answer. The described setup works for me with spi_async quite well. But now I'm solving another issue.
      On the SPI2 I have working described receiving using external clock and also transmitting using internal clock. Unfortunately the problem arises when I want to switch between these two. There was no mechanism to switch the internal/external clock (it was done only in davinci_spi_probe function) so I add this also to the davinci_spi_setup which can be called from my module. However when I do that (switching the clock source) the transfers stops to work.

      For example I can boot up my desk, invoke a process which receives on SPI2 with external clock and it works. Then I call another process which switches the clock and tries to transmit but this fails and vice versa.

      What is needed to be done to switch the clock on SPI device?

      best regards
      Jan
       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Sudhakar Rajashekhara
      Posted by Sudhakar Rajashekhara
      on Mar 30 2012 03:00 AM
      Expert5130 points

      Hi Jan,

      In your last mail you had mentioned that you can use your dm365 as a slave in Linux but Linux does not have the infrastructure to support SPI slave mode. I am feeling that the issue you are seeing may be related to this.

      Regards, Sudhakar

      Does this help with your question? If not, please send back more information. If it answers your question, please click the  Verify Answer  button below.

      PSP
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jan Pohanka
      Posted by Jan Pohanka
      on Mar 30 2012 03:13 AM
      Expert1290 points

      Dear  Sudhakar,

      I will try to clarify my setup.

      I'm using ordinary linux spi framework. It works well when I want to send a message to some spi slave. I'm using also let's say "pseudo slave"  mode, which uses the ability of the spi hw to use external spi clock (this can be achieved by clearing CLKMOD bit in SPIGCR1 register, SPI_SCLK pin then works as input). Linux spi framework can also be used in this mode, because I the size of the data, which I need to receive - so I can execute spi_read function and the only difference is that the speed of the transfer is controlled by another chip.

      These two setups works for me but problem is the switching between them. When I change CLKMOD bit after my board starup it is ok, but when I change it once more then the next transfers hangs. It occurs even in the case that I reset the peripheral using its reset bit and setup another regs before the CLKMOD change.

      regards
      Jan 

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Sudhakar Rajashekhara
      Posted by Sudhakar Rajashekhara
      on Apr 01 2012 23:36 PM
      Verified Answer
      Verified by Jan Pohanka
      Expert5130 points

      Hi Jan,

      As I understand, you are able to receive the data from external SPI device even when you configured the CLKMOD bit as 0 when board boots up but the same transfer fails if you change the CLKMOD bit one more time. Can you confirm this?

      Also, the SPI driver you are using is pretty old. The new driver available in latest Linux kernel has many bug fixes and I strongly suggest you to check once with this updated driver. You can find the patches to the new driver at http://arago-project.org/git/projects/?p=linux-davinci.git;a=shortlog;h=refs/heads/davinci-spi-rewrite. The kernel tree in this link is based on Linux v2.6.37-rc2. You can have a look at the top 50 odd patches for SPI support.

      Regards, Sudhakar

      Does this help with your question? If not, please send back more information. If it answers your question, please click the  Verify Answer  button below.

      PSP
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jan Pohanka
      Posted by Jan Pohanka
      on Apr 02 2012 00:44 AM
      Expert1290 points

      Hi Sudhakar,

      Yes I confirm, that changing of CLKMOD bit after the successful transfer makes spi driver to hang. I discovered also that this is caused by the fact, that DMA events generation was not stopped correctly in the driver on the end of the transfer.  I checked quickly the proposed patches and it seems that the one there http://arago-project.org/git/projects/?p=linux-davinci.git;a=commit;h=fec209600b91b16f1fc18fffcb5a950c3668cda2 should be related to the described problem.

      As we are using the kernel v2.6.32.17 from the latest available SDK I doubt I will be able to apply proposed patches without problems but I will try it at least. We will surely switch to the newer PSP (kernel 2.6.37) or even the newer one if it is available, but it has to be done later because we need to present some functionality next week...

      best regards
      Jan 

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jan Pohanka
      Posted by Jan Pohanka
      on Apr 17 2012 08:30 AM
      Expert1290 points

      Hi Sudhakar,

      I have applied the patches from davinci-spi-rewrite branch to our kernel and everything is working correctly now. Thank you.

      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