SPI on Colibri iMX6

Hello,

I modified the Toradex SPI demo application today to test the SPI1 and SPI2 interface. I saw the SPI Clock signal for SPI1 on pin 88 of the colibri SOM, and observed the clock for SPI2 on pin 140 - I expected to see the SPI clock on pin 153 (see code below). Am I missing a step for configuring the clock pin? I am using the Toradex CE Library v2.1.



    int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow)
    {
    DWORD    loopCount    = 0;
    DWORD    clockSet     = 0;
    DWORD    dataCount    = 0;
    DWORD    spiData[20]  = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};   // Transmit buffer
    DWORD    rxBuffer[20] = {0};   ///< Receive buffer
    HANDLE   hSPI;
	HANDLE	 hSPI2;
    BOOL     fSuccess     = TRUE;
    tVersion ver;

	UNREFERENCED_PARAMETER(instance);
	UNREFERENCED_PARAMETER(prevInstance);
	UNREFERENCED_PARAMETER(cmdLine);
	UNREFERENCED_PARAMETER(cmdShow);

    Imx6Spi_GetVersion(&ver);
    wprintf(L"Demo Application for the SPI Library V%d.%d.%d\r\n", ver.Major, ver.Minor, ver.Build);

    hSPI = Imx6Spi_Init(L"SPI1");
	hSPI2 = Imx6Spi_Init(L"SPI2");

    if (hSPI == NULL)
    {
        wprintf(L"Error initializing the SPI Library\r\n");
        fSuccess = FALSE;
    }
    else
    {
        // Set mode and baud rate
        fSuccess = Imx6Spi_SetConfigInt(hSPI, L"SpiMode", 3, StoreVolatile);
        fSuccess = Imx6Spi_SetConfigInt(hSPI, L"BitRateHz", 10*1000, StoreVolatile);
		fSuccess = Imx6Spi_SetConfigInt(hSPI2, L"SpiMode", 3, StoreVolatile);
		fSuccess = Imx6Spi_SetConfigInt(hSPI2, L"BitRateHz", 10 * 1000, StoreVolatile);
		fSuccess = Imx6Spi_SetConfigInt(hSPI2, L"ioCLK", IOCOLIBRIPIN(153), StoreVolatile);



		
		if (!Imx6Spi_Open(hSPI2))
		{
			wprintf(L"Failed to open SPI2\r\n");
			fSuccess = FALSE;
		}
        if (!Imx6Spi_Open(hSPI))
        {
            wprintf(L"Failed to open SPI\r\n");
            fSuccess = FALSE;
        }
        else
        {
            // If multiple chip selects are used, the following lines of code are required to ensure
            // that all chip selects are properly configured (inac79tive) before the first use.
            // The location of chip select pins for a particular SoM can be looked up in the .chm documentation file
            // shipped with this library package.
            /*
            fSuccess = Imx6Spi_SetConfigInt(hSPI, L"ioCS", IOCOLIBRIPIN(86), StoreVolatile); // Standard CS pin on Colibri
            fSuccess = Imx6Spi_SetConfigInt(hSPI, L"ioCS", IOCOLIBRIPIN(97), StoreVolatile); // 2nd Chip select, on Vybrid
            */

            // write & read using 2 chip selects
            for (loopCount = 0; loopCount < 10; loopCount++)
            {
                // Standard CS pin on Colibri
                fSuccess = Imx6Spi_SetConfigInt(hSPI, L"ioCS", IOCOLIBRIPIN(86), StoreVolatile);
				fSuccess = Imx6Spi_SetConfigInt(hSPI2, L"ioCS", IOCOLIBRIPIN(184), StoreVolatile);
				fSuccess = Imx6Spi_SetConfigInt(hSPI2, L"ioCLK", IOCOLIBRIPIN(153), StoreVolatile);
                dataCount = Imx6Spi_ReadWrite(hSPI, rxBuffer, spiData, 20);
				dataCount = Imx6Spi_ReadWrite(hSPI2, rxBuffer, spiData, 20);
                ASSERTMSG(L"Unexpected amount of received data\r\n" , (dataCount == 20));

                // 2nd CS. Availability depends on the actual SoM used.
                /*
                fSuccess = Imx6Spi_SetConfigInt(hSPI, L"ioCS", IOCOLIBRIPIN(79), StoreVolatile);
                dataCount = Imx6Spi_ReadWrite(hSPI, rxBuffer, spiData, 20);
                ASSERTMSG(L"Unexpected amount of received data\r\n" , (dataCount == 20));
                */
            }

            // print transmitted vs. received data
            wprintf(L"Transmitted data : ");
            for (loopCount = 0; loopCount < dataCount; loopCount++)
                wprintf(L"%02x ", spiData[loopCount]);

            wprintf(L"\r\nReceived data    : ");
            for (loopCount = 0; loopCount < dataCount; loopCount++)
                wprintf(L"%02x ", rxBuffer[loopCount]);

            fSuccess = Imx6Spi_Close(hSPI);
			fSuccess = Imx6Spi_Close(hSPI2);
        }

        fSuccess = Imx6Spi_Deinit(hSPI);
		fSuccess = Imx6Spi_Deinit(hSPI2);
    }

    wprintf(L"\r\n\r\nPress ENTER to exit.");
    getchar();

    return fSuccess;
    }

I tested this code with 2.1 release of the libraries and OS Image 1.3b4 and it works as expected, I see SPI clock on SODIMM pin 153.

By the way (not related to the issue), you should use “generic” SPI_* functions instead of IMX6-specific version, this will make your code more portable on other modules of the same family.

Unfortunately I was looking at the wrong pin on my dev-kit when I posted this issue. The pin did work as it should have. Thanks!