Hi, I am using Colibri iMX7D with the Colibri Evaluation board. I am running freeRTOS in M4 core. I need to setup an SPI (ECSPI1) in M4 with two chip selects. In Linux, when we have two chip-selects, we can easily choose between them as spidev0.0 and spidev0.1 will be there. But in M4, I have only one base as ECSPI1. So how to choose to acquire data between them. In M4, how the SPI will be differentiated by the chip-select in M4? Examples will be more useful. Thanks and regards, Nishanth
Dear @nishanth1829
The M4 offering works on a lower level than Linux. The result is a much leaner system which can run on a smaller CPU like the M4 and still reach great performance.
There’s basically two steps you need to do:
- Configure all necessary GPIOs in a way that they can used as a ECSPI1 chip select
- Tell the SPI driver to use one or the other chip select
How can you approach this kind of questions
Look at the i.MX7 reference manual. You will find that the Chip select is controlled by the CHANNEL_SELECT
bits in the ECSPIx_CONREG
register.
Looking at the source code of the M4 examples you will find that these bits are set according to the field .channelSelect
in the ecspi_init_config_t
structure.
Particular solution
In the ECSPI demo application the pin multiplexing is configured in the function configure_ecspi_pins()
in the file pin_mux.c. You need to extend this function in order to properlyinitialize all ECSPI chip select signals.
In the example project \examples\imx7_colibri_m4\driver_examples\ecspi\ecspi_interrupt\master\main.c there is the following code:
ecspi_init_config_t ecspiMasterInitConfig = {
.baudRate = 500000,
.mode = ecspiMasterMode,
.burstLength = ECSPI_MASTER_BURSTLENGTH,
.channelSelect = BOARD_ECSPI_CHANNEL,
.clockPhase = ecspiClockPhaseSecondEdge,
.clockPolarity = ecspiClockPolarityActiveHigh,
.ecspiAutoStart = ECSPI_MASTER_STARTMODE
};
Simply change the BOARD_ECSPI_CHANNEL
to any value between 0 and 3 to select the Chip Select 0…3.
Regards,
Andy
Dear @andy.tx ,
Thanks for the deep explanation.I will try with the above steps and comeback but how can we choose CS while acquiring ie. for example we have connnected an ADC and a counter with ECSPI1 with CS0 and CS1. So I want data from both counter and ADC. If this is done in Linux, we will acquire data by choosing either spidev0.0 and spidev0.1 but in M4 how to do this?
Thanks for your time.
Regards,
Nishanth
Dear @nishanth1829
If my first explanations were not sufficient, I recommend you take a JTAG adapter and step through the example. This helps you to understand where the JTAG driver selects the Chip select, and also helps you to understand how you can change this setting.
Regards, Andy
Dear @andy.tx ,
Thank you for the suggestion. I will try as you mentioned. Also, is it possible to use any GPIO as Chip select other than ECSPI1.SS0…3 for M4?
Regards,
Nishanth
Dear @nishanth1829
This is also documented in the i.MX7 reference manual: There are only a few particular pins which can be used as hardware chip selects.
But if you modify the driver you can of course emulate the chip select with any GPIO.
Regards, Andy