<?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 Clock Polarity not changing</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1339097#M179987</link>
    <description>&lt;P&gt;Hi Aravind&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for clock polarity one can look at "MX51_ECSPI_CONFIG_SCLKPOL" in function mx51_ecspi_prepare_message() spi driver spi-imx.c&lt;/P&gt;
&lt;P&gt;&lt;A href="https://source.codeaurora.org/external/imx/linux-imx/tree/drivers/spi/spi-imx.c?h=lf-5.10.y" target="_blank"&gt;https://source.codeaurora.org/external/imx/linux-imx/tree/drivers/spi/spi-imx.c?h=lf-5.10.y&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards&lt;BR /&gt;igor&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 10:49:46 GMT</pubDate>
    <dc:creator>igorpadykov</dc:creator>
    <dc:date>2021-09-13T10:49:46Z</dc:date>
    <item>
      <title>SPI Clock Polarity not changing</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1339023#M179981</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are using iMX8M Mini based custom board. We have loaded Linux (using uBoot + Yocto) whose Kernel version is 4.14.98-2.2.0.&lt;/P&gt;&lt;P&gt;We are have written SPI driver for ecSPI3. We would like to use SPI in Mode 3 (i.e., CPOL = CPOH = 1).&lt;/P&gt;&lt;P&gt;Following are the parameters we are using&lt;/P&gt;&lt;LI-CODE lang="c"&gt;void init_eeprom_spi(void)
{
	strcpy(eeprom_spiconfig.spi_device, SPI_EEPROM_DEVICE);
	eeprom_spiconfig.spi_bits		=	8;
	eeprom_spiconfig.spi_mode		=	0x03;//SPI_EEPROM_MODE;
	eeprom_spiconfig.spi_speed		=	4000000;//SPI_SPEED_6MHZ; /*5 MHz */
	eeprom_spiconfig.spi_tx_buffer	=	(char *)spi_eeprom_txbuffer;
	eeprom_spiconfig.spi_rx_buffer	=	(char *)spi_eeprom_rxbuffer;
	eeprom_spiconfig.spi_buffsz	    =	SPI_BUFFER_MAX_SIZE;
	eeprom_spiconfig.spi_fd		    =	-1;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is the code were we are writing the data to SPI driver&lt;/P&gt;&lt;LI-CODE lang="c"&gt;int spi_transfer(struct spi_eeprom_conf *conf, char *txBuff, char *rxBuff, int size, int endian)
{

	int ret;
	void *txptr, *rxptr;
	txptr 	= 	(void *)txBuff;
	rxptr	=	(void *)rxBuff;

	/* Check endianess and swap if necessary*/
	if (endian == SPI_BIG_ENDIAN)
		for (int i = 0; i &amp;lt; (size/M_FOUR); i ++)
			SwapEndian((uint32_t *)txptr + i);

	/* Was not getting proper clock polarity, hence adding CPOL, CPOH init here */

	/* Set read mode */
	if ((ret = ioctl(conf-&amp;gt;spi_fd, SPI_IOC_RD_MODE, &amp;amp;conf-&amp;gt;spi_mode)) &amp;lt; M_ZERO) {
		printdbg(("\n spi_open: set read mode failed"));
		close(conf-&amp;gt;spi_fd);
		return M_INVALID;
	}
	printdbg(("\n spi_open: set read mode successfull"));

	/* Set write mode */
	if ((ret = ioctl(conf-&amp;gt;spi_fd, SPI_IOC_WR_MODE, &amp;amp;conf-&amp;gt;spi_mode)) &amp;lt; M_ZERO) {
		printdbg(("\n spi_open: set write mode failed"));
		close(conf-&amp;gt;spi_fd);
		return M_INVALID;
	}
	printdbg(("\n spi_open: set wrie mode successfull"));


	/* Initialize transfer structure for SPI linux API */
	struct spi_ioc_transfer tr = {
				.tx_buf = (unsigned long)(char *)txBuff,
				.rx_buf = (unsigned long)(char *)rxBuff,
				.len = size,
		        .delay_usecs = conf-&amp;gt;spi_delay,
		        .speed_hz = conf-&amp;gt;spi_speed,
		        .bits_per_word = conf-&amp;gt;spi_bits,
		};

	/* Initiate SPI transfer */
	if ((ret = ioctl(conf-&amp;gt;spi_fd, SPI_IOC_MESSAGE(1), &amp;amp;tr)) &amp;lt; M_ZERO) {
		printdbg(("\n spi_transfer: transfer failed"));
		return M_INVALID;
	}

	/* Check endianess and swap bytes if necessary */
	if (endian == SPI_BIG_ENDIAN)
			for (int i = 0; i &amp;lt; (size/M_FOUR); i ++)
				SwapEndian((uint32_t *)rxptr + i);
	printdbg(("\n spi_transfer: transfer success [Size = %d bytes]", ret));

	/* Return no of bytes trasnferred */
	return ret;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In-spite of all the trials, I am not able to change the mode of SPI. It is stuck with "CLOCK being Low in Idle". Interestingly, I can manipulate clock frequency without any problem. I am able to get the data out from MOSI also.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can some one guide me how to change SPI mode? Do you see any problem in code?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Aravind&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 09:02:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1339023#M179981</guid>
      <dc:creator>aravindchakrava</dc:creator>
      <dc:date>2021-09-13T09:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: SPI Clock Polarity not changing</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1339097#M179987</link>
      <description>&lt;P&gt;Hi Aravind&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for clock polarity one can look at "MX51_ECSPI_CONFIG_SCLKPOL" in function mx51_ecspi_prepare_message() spi driver spi-imx.c&lt;/P&gt;
&lt;P&gt;&lt;A href="https://source.codeaurora.org/external/imx/linux-imx/tree/drivers/spi/spi-imx.c?h=lf-5.10.y" target="_blank"&gt;https://source.codeaurora.org/external/imx/linux-imx/tree/drivers/spi/spi-imx.c?h=lf-5.10.y&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards&lt;BR /&gt;igor&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 10:49:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1339097#M179987</guid>
      <dc:creator>igorpadykov</dc:creator>
      <dc:date>2021-09-13T10:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: SPI Clock Polarity not changing</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1342664#M180349</link>
      <description>&lt;P&gt;HI Igor,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply. I did go through the SPI device driver code. However, I felt it is beyond my capability.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am actually looking something which modifiable in user space not at kernel/driver level.&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Aravind&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 09:06:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1342664#M180349</guid>
      <dc:creator>aravindchakrava</dc:creator>
      <dc:date>2021-09-20T09:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: SPI Clock Polarity not changing</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1343073#M180383</link>
      <description>&lt;P&gt;one can try to debug it to find reason why polarity change is not happening,&lt;/P&gt;
&lt;P&gt;read SCLK_PHA field register ECSPIx_CONFIGREG,&amp;nbsp; use&lt;/P&gt;
&lt;P&gt;AN4553 Using Open Source Debugging Tools for Linux on i.MX Processors&lt;BR /&gt;&lt;A href="https://www.nxp.com/docs/en/application-note/AN4553.pdf" target="_blank" rel="noopener"&gt;https://www.nxp.com/docs/en/application-note/AN4553.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;or memtool&lt;/P&gt;
&lt;P&gt;&lt;A href="https://source.codeaurora.org/external/imx/imx-test/tree/test/memtool?h=lf-5.10.y_2.0.0" target="_blank"&gt;https://source.codeaurora.org/external/imx/imx-test/tree/test/memtool?h=lf-5.10.y_2.0.0&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards&lt;BR /&gt;igor&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 06:42:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1343073#M180383</guid>
      <dc:creator>igorpadykov</dc:creator>
      <dc:date>2021-09-21T06:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: SPI Clock Polarity not changing</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1343862#M180460</link>
      <description>&lt;P&gt;Hi Igor,&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is nice way of debugging within Linux. I will check.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Aravind&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 08:57:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SPI-Clock-Polarity-not-changing/m-p/1343862#M180460</guid>
      <dc:creator>aravindchakrava</dc:creator>
      <dc:date>2021-09-22T08:57:12Z</dc:date>
    </item>
  </channel>
</rss>

