I've begun integrating an eInfoChips C6657 EVM with an FPGA EVM connected via SPI. I now can communicate as desired but I needed to change some code in SPI_v0.c which for source code control is not desired.
We are transferring 32-bits in 4 8-bit frames. With the unmodified SPI_v0.c code I see 40 spi clocks instead of the expected 32 clocks. I copied the file SPI_v0.c into my project and I removed the following section of code from SPI_v0_hwiFxn().
if (loop == true)
{
/* Read the interrupt status to check if there are any pending interrupts */
intCode = SPIIntStatusGet(hwAttrs->baseAddr);
/* Check if transmit is completed but data read is pending */
if((object->writeCountIdx == 0U) && !(intCode & SPI_INT_RX_FULL) && (object->readCountIdx))
{
/* Send a dummy transfer to trigger a receive interrupt to handle delayed RX
* interrupt to read the missed data during transmit.
*/
if (intCode & SPI_INT_TX_EMPTY)
{
SPITransmitData(hwAttrs->baseAddr, csHold, 0);
}
}
}
That dummy transfer is causing the extra clocks I am seeing and making the SPI state machine in the FPGA unhappy. Without this code I am able correctly read and write my 32-bit data to/from the FPGA so it would seem these "dummy transfers' are not needed. It is curious that the code says "dummy transfer" but it results in real clocks to the FPGA. This also caused the CS to behave incorrectly, leaving it in the wrong state.
Perhaps I am configuring something wrong to cause this? Here is my basic setup of the SPI driver.
/* Get the default SPI init configurations */
SPI_socGetInitCfg(SPI_INSTANCE, &spi_cfg);
this->baseAddr = spi_cfg.baseAddr;
/* Modify the default SPI configurations if necessary */
spi_cfg.enableIntr = true;
/* Update the SPI functional clock based on CPU clock*/
Board_getSoCInfo(&socInfo);
if(socInfo.sysClock != BOARD_SYS_CLK_DEFAULT)
{
spi_cfg.inputClkFreq = socInfo.sysClock/SPI_MODULE_CLOCK_DIVIDER;
}
spi_cfg.csNum = this->spiCS;
/* Set the default SPI init configurations */
SPI_socSetInitCfg(SPI_INSTANCE, &spi_cfg);
SPI_init();
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA0;
// Make sure are not using semaphores since this is not running in a BIOS Task.
spiParams.transferMode = SPI_MODE_CALLBACK;
spiParams.transferTimeout = SPI_TRANSACTION_TIMEOUT;
spiParams.transferCallbackFxn = SPICallbackFxn;
spiParams.dataSize = 8; // We send 4 8-bit frames
this->handle = SPI_open(SPI_INSTANCE, &spiParams);
/* Enable transfer*/
UInt32 xferEnable = 1;
SPI_control(handle, SPI_V0_CMD_XFER_ACTIVATE, (void *)&xferEnable);
/* Enable chip select pin.*/
SPICSEnable(this->baseAddr, this->spiCS);