SPI demo not working Apalis imx6

Hello, it’t me again.

Its always a problem for me to getting to know another development environment and devices.
At the moment I am trying to get GPIO, I2C, ADC and SPI working. I managed the first three to work with expect output. Only the SPI is giving me problems.

I use this demo to setup my SPI. Only it doesn’t start at all. When I debug the whole thing I am getting errors on the SPI, there are as follows:

ERROR Spi_Init - Unknown CPU Type
ERROR Spi_SetConfigInt- Unknown CPU Type
ERROR Spi_SetConfigInt- Unknown CPU Type
ERROR Spi_Open - Unknown CPU Type
ERROR Spi_SetConfigInt- Unknown CPU Type

As for as I know, I am using the latest library for it (1.7.2976).

Who did I manage to get an error in even a demo code?

As always I would really appreciate the help.

Kind regards,


I also get another message when using the I2C. I dont know if that is normal. But the message is as follows:
‘ConsoleApplication4.exe’ (Win32): Loaded ‘\Windows\i2csdk.dll’. Cannot find or open the PDB file.

Can you please try with our latest image (1.1 beta 4) and the latest release of our libraries?
SPI should be supported in those releases.

I downloaded the latest image (1.1b4) just like you suggested. After this it still reported the same errors.
Than I also downloaded the latest libraries (release date yesterday…). After this I don’t get the error messages any more.

So this fixed the issue. Many thanks.

But when using the SPI demo I still cant get a connection.
I always get the code “Error in sending data” aka i get a zero return value from Spi_write.
I have something connected on SPI1.

Kind regards,


Can you provide a small code sample that we can use to reproduce the issue?
Actually SPI has no error checking mechanism and so write operations should succeed even when no devices are connected.

These are the include I use (I tried all sort of combinations):
#include “spi.h”
#include “spi_imx6.h”

Initializing of the SPI:
Spi_GetVersion(&ver);///< Get Library Version
wprintf(L"\nSPIlib version %d.%d.%d\r\n", ver.Major, ver.Minor, ver.Build);

hSPI = Spi_Init(L"SPI1");	///< Init SPI interface
if (hSPI == NULL)
	wprintf(L"\tError initializing the SPI Library\r\n");
Spi_SetConfigInt(hSPI, L"SpiMode", 0, StoreVolatile);///< Set SPI MODE of operation
Spi_SetConfigInt(hSPI, L"ioClk", 221, StoreVolatile);///< Set SPI clock speed
Spi_SetConfigInt(hSPI, L"ioMOSI", 225, StoreVolatile);
Spi_SetConfigInt(hSPI, L"ioMISO", 223, StoreVolatile);
Spi_SetConfigInt(hSPI, L"ioCS", 227, StoreVolatile);
Spi_SetConfigInt(hSPI, L"BitRateHz", 100000, StoreVolatile);
Spi_SetConfigInt(hSPI, L"BitsPerWord", 8, StoreVolatile);
if (hSPI == NULL)	///< Open SPI interface
	wprintf(L"\tFailed to open SPI\r\n");

Writing to an SPI device:
DWORD returnValue = 0;
DWORD spiData[3] = { 0 };

spiData[0] = 40;
spiData[1] = 255;
returnValue = Spi_Write(hSPI, spiData, 2);
if (returnValue == 0)
printf("\nError in sending data\n");

This latest routine throws the error with returnValue = 0.
And like you said, I would expect a returnValue of 2 even when there is no device attached.

Sorry how the code is displayed. But I cant get a decent viewing of it here.

I have been playing with it today and get some improvements. But still not a proper SPI communication.

I also change SPI1 to SP2 with the following pin:

When I changed from Spi_SetConfigInt to Spi_SetConfigString I got a clock on the SPI clk, but this clock wasn’t even close to the frequency that I had set. I doesnt what value I enter, it still is around 1MHz clock.

In addition I still get the error Unknow CPU type when debugging.
This error message pops up when I try to use Spi_SetConfigString.

Can you please upload sample application on share.toradex.com and post a link, that would help debugging the issue here.

The link is: https://share.toradex.com/xx4fckcyb9437tr
I have added comments in the ConsoleApplication4.ccp where the errors occur.

I see that you put all libs and headers in the same folder. It seems that not all of them are from the latest version. Can you try to update all library contents you copied in your folder to the latest release?

I thought I already have done that. But for the good measure I will do it again.
I completely removed the “inc” and “libs” folders from my project.
I use the “inc” and “libs” folders in the downloaded “toradexlibraries_v1_8_3509”.
I have added them to my project and linked it in the project properties.
Rebuild the whole project and started the debugging.

I still get the error message: “ERROR Spi_SetConfigString - Unknow CPU Type”.

I removed the unnecessary includes, so the only one that I use are:
Coproc.h (version 1.8.3471)
spi.h (version 1.8.3464)

Is there already an solution found for this problem??

Can you please upload new code to share.toradex.com.
The error should be generated on old releases (previous to 1.8) because on those SPI on i.mx6 was not supported. It seems that in some ways your project is still referencing and old release of one of the libraries (coproclib or spilib).

I have have zipped the whole project, the link for it is: https://share.toradex.com/6j6ay2r3ot8kp1j.

BTW: is seems that i cant commend on your last post valter.tx

I see that your code is using Spi_SetConfigString instead of Spi_SetConfigInt. Spi_SetConfigString is not supported on SPI, and this generates the error. The message is obviously wrong and will be fixed in next release.

After so many posts I think I have to post the problem again, because the answers are contradicting with the real live output. The problem is as follows:

Spi_SetConfigString: “Works” half. Signal on CLK and MOSI pin. Only The frequency is not the same is the set frequency (doesn’t matter what you put in the init, it will always be 1MHz). Get always the debug output: “ERROR Spi_SetConfigString - Unknown CPU Type”.

Spi_SetConfigInt: Doesn’t work at all. No signal on the CLK or MOSI pin. Get always returned 0 in de SPI_write.

I tried it over and over again but still only Spi_SetConfigString shows some results, but still not 100% correct. Spi_SetConfigInt DOESN’T work at all.

And when debugging I get the following:

Using Spi_SetConfigInt:
‘Command’ ‘Before’ - ‘After’
Mode: 0 - 0
ioCLK: 1048631 - 4294967295
ioMOSI: 1048632 - 4294967295
ioMISO: 1048633 - 4294967295
ioCS: 1048634 - 4294967295
BtRateHz: 1000000 - 1000000
BitsPerWord: 32 - 32

Using Spi_SetConfigString:
‘Command’ ‘Before’ - ‘After’
Mode: 0 - 0
ioCLK: 1048631 - 1048631
ioMOSI: 1048632 - 1048632
ioMISO: 1048633 - 1048633
ioCS: 1048634 - 1048634
BtRateHz: 1000000 - 1000000
BitsPerWord: 32 - 32

I did this as follows:

	Spi_GetConfigInt(hSPI, L"SpiMode", &test);
	Spi_GetConfigInt(hSPI, L"ioClk", &test);
	Spi_GetConfigInt(hSPI, L"ioMOSI", &test);
	Spi_GetConfigInt(hSPI, L"ioMISO", &test);
	Spi_GetConfigInt(hSPI, L"ioCS", &test);
	Spi_GetConfigInt(hSPI, L"BitRateHz", &test);				///< Set SPI clock speed
	Spi_GetConfigInt(hSPI, L"BitsPerWord", &test);

	/*success &= Spi_SetConfigString(hSPI, L"SpiMode", L"0", StoreToRegistry);
	success &= Spi_SetConfigString(hSPI, L"ioClk", L"235", StoreToRegistry);
	success &= Spi_SetConfigString(hSPI, L"ioMOSI", L"231", StoreToRegistry);
	success &= Spi_SetConfigString(hSPI, L"ioMISO", L"229", StoreToRegistry);
	success &= Spi_SetConfigString(hSPI, L"ioCS", L"233", StoreToRegistry);
	success &= Spi_SetConfigString(hSPI, L"BitRateHz", L"100000", StoreToRegistry);				///< Set SPI clock speed
	success &= Spi_SetConfigString(hSPI, L"BitsPerWord", L"32", StoreToRegistry);*/

	//Use Spi_SetConfigInt results in no error but there is NO output visible
	/*success &= Spi_SetConfigInt(hSPI, L"SpiMode", 0, StoreToRegistry);
	success &= Spi_SetConfigInt(hSPI, L"ioClk", 235, StoreToRegistry);
	success &= Spi_SetConfigInt(hSPI, L"ioMOSI", 231, StoreToRegistry);
	success &= Spi_SetConfigInt(hSPI, L"ioMISO", 229, StoreToRegistry);
	success &= Spi_SetConfigInt(hSPI, L"ioCS", 233, StoreToRegistry);
	success &= Spi_SetConfigInt(hSPI, L"BitRateHz", 100000, StoreToRegistry);
	success &= Spi_SetConfigInt(hSPI, L"BitsPerWord", 32, StoreToRegistry);*/

	Spi_GetConfigInt(hSPI, L"SpiMode", &test);
	Spi_GetConfigInt(hSPI, L"ioClk", &test);
	Spi_GetConfigInt(hSPI, L"ioMOSI", &test);
	Spi_GetConfigInt(hSPI, L"ioMISO", &test);
	Spi_GetConfigInt(hSPI, L"ioCS", &test);
	Spi_GetConfigInt(hSPI, L"BitRateHz", &test);				///< Set SPI clock speed
	Spi_GetConfigInt(hSPI, L"BitsPerWord", &test);

Atleast Spi_SetConfigString leaves the values intact. I think is the reason why the function works.
Spi_SetConfigInt will mess up the values. I think this causes that I dont see any output.

I had to change some things in your sample code to make it work.
We have an issue preventing us from loading/saving parameter to registry currently, so I removed the StoreToRegistry option, since your code is re-configuring all the parameters anyway. This has ben filled as a bug and will appear in the libraries roadmap soon.
Second issue was that pin numbers must be passed as uIo type (defined in gpio.h) and not just as integer numbers, this will allow the library to understand if you want to reference a module pin (APALIS/COLIBRI) or a direct GPIO number.
With those changes and including gpio.h (required for the IOAPALISPIN macro to work) the code generated the SPI signal I captured in the attached image.

success &= Spi_SetConfigInt(hSPI, L"SpiMode", 0, StoreVolatile); 
success &= Spi_SetConfigInt(hSPI, L"ioClk", IOAPALISPIN(235), StoreVolatile); 
success &= Spi_SetConfigInt(hSPI, L"ioMOSI", IOAPALISPIN(231), StoreVolatile);
success &= Spi_SetConfigInt(hSPI, L"ioMISO", IOAPALISPIN(229), StoreVolatile);
success &= Spi_SetConfigInt(hSPI, L"ioCS", IOAPALISPIN(233), StoreVolatile); 
success &= Spi_SetConfigInt(hSPI, L"BitRateHz", 100000, StoreVolatile); 
success &= Spi_SetConfigInt(hSPI, L"BitsPerWord", 32, StoreVolatile); 

We are going to work on the issues, but I hope that this will allow you to at least test your SPI-related code.

YES, it works also here. :slight_smile:
Thank you very very very much.

I also tried the notation for the IO, but had used the wrong one than I think.
I would never have found the StoreToRegister fault, but had tried both versions at some point.

But Thank you very very much. I know for sure that I can try out the SPI with my hardware.