<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX ProcessorsのトピックRe: SPI Read User Space Issue</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Read-User-Space-Issue/m-p/1276074#M173970</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can refer thsi spi test code&amp;nbsp;&lt;A href="https://source.codeaurora.org/external/imx/imx-test/tree/test/mxc_spi_test/mxc_spi_test1.c?h=imx_5.4.70_2.3.0" target="_blank" rel="noopener"&gt;https://source.codeaurora.org/external/imx/imx-test/tree/test/mxc_spi_test/mxc_spi_test1.c?h=imx_5.4.70_2.3.0&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;static const char   *spiDev0  = "/dev/spidev0.0" ;
static const char   *spiDev1  = "/dev/spidev0.1" ;
static  uint8_t     spiBPW   = 8 ;
static  uint16_t    spiDelay = 0 ;
 
static uint32_t     spiSpeeds [2] ;
static int          spiFds [2] ;
/*
* SPIDataRW:
*    Write and Read a block of data over the SPI bus.
*    Note the data ia being read into the transmit buffer, so will
*    overwrite it!
*    This is also a full-duplex operation.
*********************************************************************************
*********************************************************************************/
int SPIDataRW (int channel, unsigned char *tx_data, unsigned char *rx_data, int len)
{
  int i = 0;
  struct spi_ioc_transfer spi ;
  channel &amp;amp;= 1 ;
  memset (&amp;amp;spi, 0, sizeof (spi)) ;
  spi.tx_buf        = (unsigned long)tx_data ;
  spi.rx_buf        = (unsigned long)rx_data ;
  spi.len           = len ;
  spi.delay_usecs   = spiDelay ;
  spi.speed_hz      = spiSpeeds [channel] ;
  spi.bits_per_word = spiBPW ;
return ioctl (spiFds [channel], SPI_IOC_MESSAGE(1), &amp;amp;spi) ; 
}
/*
* SPISetupMode:
*    Open the SPI device, and set it up, with the mode, etc.
*********************************************************************************
*********************************************************************************/
 
int SPISetupMode (int channel, int speed, int mode)
{
  int fd ;
 
  if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) &amp;lt; 0)
  {
    printf("Unable to open SPI device: %s\n", strerror (errno)) ;
    return -1;
  }
  spiSpeeds [channel] = speed ;
  spiFds    [channel] = fd ;
  
  if (ioctl (fd, SPI_IOC_WR_MODE, &amp;amp;mode) &amp;lt; 0)                     
  {                                                               
    printf("Can't set spi mode: %s\n", strerror (errno)) ;         
    return -1;                                                    
  }                                                               
  if (ioctl (fd, SPI_IOC_RD_MODE, &amp;amp;mode) &amp;lt; 0)                     
  {                                                               
    printf("Can't get spi mode: %s\n", strerror (errno)) ;        
    return -1;                                                 
  }    
  

  if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &amp;amp;spiBPW) &amp;lt; 0)          
  {                                                               
    printf("Can't set bits per word: %s\n", strerror (errno))  ;  
    return -1;                                                    
  }                                                              
  
  if (ioctl (fd, SPI_IOC_RD_BITS_PER_WORD, &amp;amp;spiBPW) &amp;lt; 0)          
  {                                                               
    printf("Can't get bits per word: %s\n", strerror (errno))  ;  
    return -1;                                                   
  }   
  
/*
* Set SPI RW speed*********************************************************************************
*/
  if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &amp;amp;speed) &amp;lt; 0)
  {
    printf("Can't set max speed hz: %s\n", strerror (errno));
    return -1;
  }
  
  if (ioctl (fd, SPI_IOC_RD_MAX_SPEED_HZ, &amp;amp;speed) &amp;lt; 0)
  {
    printf("Can't get max speed hz: %s\n", strerror (errno));
    return -1;
  }
  
  return fd ;
}
/*
* SPISetup:
*    Open the SPI device, and set it up, etc. in the default MODE 0
*********************************************************************************
*********************************************************************************/
int SPISetup (int channel, int speed)
{
  return SPISetupMode (channel, speed, 0) ;
}

&lt;/LI-CODE&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Zhiming&lt;/P&gt;</description>
    <pubDate>Thu, 13 May 2021 02:21:06 GMT</pubDate>
    <dc:creator>Zhiming_Liu</dc:creator>
    <dc:date>2021-05-13T02:21:06Z</dc:date>
    <item>
      <title>SPI Read User Space Issue</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Read-User-Space-Issue/m-p/1274938#M173869</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Board = IMX8MM Custom Board&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In our user space code spi accelerometer reading 14k data per second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI Clock Speed 3.5MHZ.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Our issue is every second we not able to read 14k fixed data it will be varying (13k to 20k)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; We want to get stable 14k data per second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Please suggest to get stable data count in user space code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Note : Microcontroller (imxrt 1064) we can able to read stable count data&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;Vasu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 09:36:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Read-User-Space-Issue/m-p/1274938#M173869</guid>
      <dc:creator>Dhevan</dc:creator>
      <dc:date>2021-05-11T09:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: SPI Read User Space Issue</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Read-User-Space-Issue/m-p/1276074#M173970</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can refer thsi spi test code&amp;nbsp;&lt;A href="https://source.codeaurora.org/external/imx/imx-test/tree/test/mxc_spi_test/mxc_spi_test1.c?h=imx_5.4.70_2.3.0" target="_blank" rel="noopener"&gt;https://source.codeaurora.org/external/imx/imx-test/tree/test/mxc_spi_test/mxc_spi_test1.c?h=imx_5.4.70_2.3.0&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;static const char   *spiDev0  = "/dev/spidev0.0" ;
static const char   *spiDev1  = "/dev/spidev0.1" ;
static  uint8_t     spiBPW   = 8 ;
static  uint16_t    spiDelay = 0 ;
 
static uint32_t     spiSpeeds [2] ;
static int          spiFds [2] ;
/*
* SPIDataRW:
*    Write and Read a block of data over the SPI bus.
*    Note the data ia being read into the transmit buffer, so will
*    overwrite it!
*    This is also a full-duplex operation.
*********************************************************************************
*********************************************************************************/
int SPIDataRW (int channel, unsigned char *tx_data, unsigned char *rx_data, int len)
{
  int i = 0;
  struct spi_ioc_transfer spi ;
  channel &amp;amp;= 1 ;
  memset (&amp;amp;spi, 0, sizeof (spi)) ;
  spi.tx_buf        = (unsigned long)tx_data ;
  spi.rx_buf        = (unsigned long)rx_data ;
  spi.len           = len ;
  spi.delay_usecs   = spiDelay ;
  spi.speed_hz      = spiSpeeds [channel] ;
  spi.bits_per_word = spiBPW ;
return ioctl (spiFds [channel], SPI_IOC_MESSAGE(1), &amp;amp;spi) ; 
}
/*
* SPISetupMode:
*    Open the SPI device, and set it up, with the mode, etc.
*********************************************************************************
*********************************************************************************/
 
int SPISetupMode (int channel, int speed, int mode)
{
  int fd ;
 
  if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) &amp;lt; 0)
  {
    printf("Unable to open SPI device: %s\n", strerror (errno)) ;
    return -1;
  }
  spiSpeeds [channel] = speed ;
  spiFds    [channel] = fd ;
  
  if (ioctl (fd, SPI_IOC_WR_MODE, &amp;amp;mode) &amp;lt; 0)                     
  {                                                               
    printf("Can't set spi mode: %s\n", strerror (errno)) ;         
    return -1;                                                    
  }                                                               
  if (ioctl (fd, SPI_IOC_RD_MODE, &amp;amp;mode) &amp;lt; 0)                     
  {                                                               
    printf("Can't get spi mode: %s\n", strerror (errno)) ;        
    return -1;                                                 
  }    
  

  if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &amp;amp;spiBPW) &amp;lt; 0)          
  {                                                               
    printf("Can't set bits per word: %s\n", strerror (errno))  ;  
    return -1;                                                    
  }                                                              
  
  if (ioctl (fd, SPI_IOC_RD_BITS_PER_WORD, &amp;amp;spiBPW) &amp;lt; 0)          
  {                                                               
    printf("Can't get bits per word: %s\n", strerror (errno))  ;  
    return -1;                                                   
  }   
  
/*
* Set SPI RW speed*********************************************************************************
*/
  if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &amp;amp;speed) &amp;lt; 0)
  {
    printf("Can't set max speed hz: %s\n", strerror (errno));
    return -1;
  }
  
  if (ioctl (fd, SPI_IOC_RD_MAX_SPEED_HZ, &amp;amp;speed) &amp;lt; 0)
  {
    printf("Can't get max speed hz: %s\n", strerror (errno));
    return -1;
  }
  
  return fd ;
}
/*
* SPISetup:
*    Open the SPI device, and set it up, etc. in the default MODE 0
*********************************************************************************
*********************************************************************************/
int SPISetup (int channel, int speed)
{
  return SPISetupMode (channel, speed, 0) ;
}

&lt;/LI-CODE&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Zhiming&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 02:21:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Read-User-Space-Issue/m-p/1276074#M173970</guid>
      <dc:creator>Zhiming_Liu</dc:creator>
      <dc:date>2021-05-13T02:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: SPI Read User Space Issue</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Read-User-Space-Issue/m-p/1277991#M174172</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/151788"&gt;@Zhiming_Liu&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPI user space code working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Our issue reading 14k data per second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In parallel we are reading two spi interface at same time 14k data one spi and one more spi 1k data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If we read two interface parallel data loss is happening and reading data count also different (14k to 20k) but its not stable count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Our industrial processor contains 2 core&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Did you have any solution to avoid data loss ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Possible M4 to read one spi data linux user space read one more spi interface to avoid data loss ?&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 06:26:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Read-User-Space-Issue/m-p/1277991#M174172</guid>
      <dc:creator>Dhevan</dc:creator>
      <dc:date>2021-05-18T06:26:55Z</dc:date>
    </item>
  </channel>
</rss>

