Other Parts Discussed in Thread: SYSBIOS
I am trying to run 3-Wire SPI in callback mode
my driver works fine in blocking mode, but hits a hard-fault in callback mode!
I looked up the SPI.h documentation to implement the callback. I rewrote it multiple times without any progress!
CS is controlled by the app manually through a GPIO pin!
Note:
I am also using a UART2 instance in parallel in callback mode!
example use case:
- Pull CS low
- write 8Bits
- write 8Bits
- write 32 Bits
- Pull CS High
I have to follow this implementation because I am using a chip from ADI that forces me to follow this pattern.
Please help me figure out what might be going wrong!
Function to write:
void AD5940_ReadWriteNBytes(unsigned char *pSendBuffer,unsigned char *pRecvBuff,unsigned long length, bool cs){
LED_BLUE_ON();
memset((void *) masterTxBuffer, 0, SPI_MSG_LENGTH);
memset((void *) masterRxBuffer, 0, SPI_MSG_LENGTH);
memcpy((char *)masterTxBuffer, (char *)pSendBuffer, length);
masterTransaction.count = length;
masterTransaction.txBuf = (void *)masterTxBuffer;
masterTransaction.rxBuf = (void *)masterRxBuffer;
// masterTransaction.arg = &structSem_spi;
Bool transferOK = SPI_transfer(masterSpi, &masterTransaction);
if (transferOK){
Semaphore_pend(spi_comp_sem, BIOS_WAIT_FOREVER);
}
else {
//printf("SPI fail \n");
Log_info0("Unsuccessful master SPI transfer");
while(1);
}
memcpy((char *)pRecvBuff, (char *)masterRxBuffer, length);
LED_BLUE_OFF();
}
Callback:
static void spiTranCompCB(SPI_Handle handle, SPI_Transaction *transaction)
{
//SPI_transferCancel(handle);
if (transaction->status != SPI_TRANSFER_COMPLETED) {
transferStatus = false;
}
else {
transferStatus = true;
}
Semaphore_post(spi_comp_sem);
}
SPI_init():
void spiBus_init(void)
{
SPI_init();
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA0;
spiParams.bitRate = 6000000;
spiParams.mode = SPI_MASTER;
spiParams.dataSize = 8;
//spiParams.transferMode = SPI_MODE_BLOCKING;
spiParams.transferCallbackFxn = spiTranCompCB;
spiParams.transferMode = SPI_MODE_CALLBACK;
}
SPI_acquire():
void spiAcquire(void){
masterSpi = SPI_open(CONFIG_SPI_AFE, &spiParams);
//SPI_control(masterSpi, SPICC26XXDMA_RETURN_PARTIAL_ENABLE, NULL);
if (masterSpi == NULL) {
System_abort("Error initializing master SPI\n");
}
}
void spiRelease(void){
if (masterSpi != NULL) SPI_close(masterSpi);
}
Semaphore_init():
Semaphore_Handle spi_comp_sem;
Semaphore_Params semParams;
Semaphore_Struct structSem_spi;
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
Semaphore_construct(&structSem_spi, 0, &semParams);
spi_comp_sem = Semaphore_handle(&structSem_spi);
if (spi_comp_sem == NULL) System_abort("Semaphore SPI sem create failed");
else Log_info0("Semaphore SPI sem created");
syscfg:


Note:
I am also using a UART2 instance in parallel in callback mode!

FORCED: BUSFAULT