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.

LAUNCHXL-CC1352P: 3-Wire SPI error in callback mode!

Part Number: LAUNCHXL-CC1352P
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 

Decoded exception
Decoded
Hard Fault: FORCED: BUSFAULT: IMPRECISERR
Exception context
$addr 0x20013ed4
$type ti.sysbios.family.arm.m3.Hwi.ExcContext
threadType
threadHandle 0x20006f44
threadStack 0x20013c00
threadStackSize 1024
r0 0x20000108
r1 0x20006f84
r2 0x31523278
r3 0x20006f84
r4 0x0
r5 0x26fe0
r6 0x2
r7 0x1
r8 0x40020000
r9 0x0
r10 0x1
r11 0x0
r12 0x0
sp 0x20013fa0
lr 0x1002d8b5
pc 0x1002d8b6
psr 0x21000017
ICSR 0x400003
MMFSR 0x0
BFSR 0x4
UFSR 0x0
HFSR 0x40000000
DFSR 0x1
MMAR 0xe000ed34
BFAR 0xe000ed38
AFSR 0x0
Exception call stack
0 ti_sysbios_knl_Swi_post__E at <unknown>:0 :PC=0x1002D8B6
1 ti_sysbios_family_arm_m3_Hwi_excHandlerMin__I at Hwi.c:974 :PC=0x0001AA29