Tool/software: Code Composer Studio
SPI_init(); or SPI_socGetInitCfg and SPI_socSetInitCfg block
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
SPI_init(); or SPI_socGetInitCfg and SPI_socSetInitCfg block
Anping,
The place to refer to code and collateral are the test and examples included with the driver
Collateral: http://software-dl.ti.com/processor-sdk-rtos/esd/docs/latest/rtos/index_device_drv.html#id45
Example Create: http://software-dl.ti.com/processor-sdk-rtos/esd/docs/latest/rtos/index_overview.html#pdk-example-and-test-project-creation
Source code: pdk_am57xx_1_0_xx\packages\ti\drv\spi\test\src\main_mcspi_test.c
You only need to call SPI_socGetInitCfg/SPI_socSetInitCfg if you want to change SOC default HW Attributes as specified in pdk_am335xx_1_0_xx\packages\ti\drv\spi\soc\am335xSPI_soc.c
Regards,
Rahul
SPI_init();
SPI_socGetInitCfg
.....
SPI_socSetInitCfg block
or
SPI_socGetInitCfg
.....
SPI_socSetInitCfg block
SPI_init();
which is correct order? Thanks
The SPI_socGetInitCfg and SPI_socSetInitCfg needs to be called before SPI_open. The SPI_init call only sets up the SPI driver handle and assume SPI handle is not NULL as you can see from the code here:
static void SPI_init_v1(SPI_Handle handle) { MCSPI_Handle mcHandle; SPI_v1_Object *object; /* Input parameter validation */ if (handle != NULL) { object = (SPI_v1_Object*)handle->object; /* Get multi-channel handle */ mcHandle = MCSPI_get_handle(handle); if (mcHandle != NULL) { MCSPI_init_v1(mcHandle); } /* initialize object varibles */ object->hwi = NULL; object->mutex = NULL; object->transferComplete = NULL; object->transferCallbackFxn = NULL; object->chOpenedCnt = 0; } }
The correct order to setup the SPI driver is provided here:
http://software-dl.ti.com/processor-sdk-rtos/esd/docs/latest/rtos/index_device_drv.html#open-spi
SPI_init is called only when the handle is already created for example if your application doesn`t know if the handle was already created by bootloader or any other part of code, you can call that to re-initialize the handle. If the handle is NULL, it will have no impact.
Regards,
Rahul
Hi Rahul
I talk SPI_init(), not SPI_init_V1(SPI_Handle, handle). Your document don't say clear. I give you two orders. Which is right? Thanks
Anping,
Our drivers use a Function table to interface with different versions of SPI IP on our devices. On this device, if you check the SPI_soc.c for AM335x, you will see that SPI_FxnTable_v1 is mapped to the API layer so SPI_init will route the call to SPI_init_v1 in the driver source.
the best way to understand the correct order is to refer to the SPI test example that we provide along with the driver. In that example sequence 1 is used SPI_init is called first in main (usually the case) but the SPI driver handle is only created when SPI_open is called.
Hope this helps.
Regards,
Rahul
Hi Rahul
I know these functions call before SPI_open. My question is SPI_init call first or not. Thanks
This completely depends on the application use case. Generally speaking this is called first but in some cases could be called afterwards as I explained.for example when you plan to use a handle that is already open.
Regards,
Rahul